jamesnetherton commented on a change in pull request #2642:
URL: https://github.com/apache/camel-quarkus/pull/2642#discussion_r636760255



##########
File path: 
integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTestResource.java
##########
@@ -55,12 +76,44 @@
         }
     }
 
+    void setUpDb() {
+        final String mongoUrl = "mongodb://" + 
container.getContainerIpAddress() + ":"
+                + container.getMappedPort(MONGODB_PORT).toString();
+
+        if (mongoUrl != null) {
+            mongoClient = MongoClients.create(mongoUrl);
+        }
+        org.junit.Assume.assumeTrue(mongoClient != null);
+
+        db = mongoClient.getDatabase("test");
+        db.createCollection(MongoDbRoute.COLLECTION_TAILING,
+                new 
CreateCollectionOptions().capped(true).sizeInBytes(1000000000).maxDocuments(MongoDbTest.CAP_NUMBER));
+        db.createCollection(MongoDbRoute.COLLECTION_PERSISTENT_TAILING,
+                new 
CreateCollectionOptions().capped(true).sizeInBytes(1000000000).maxDocuments(MongoDbTest.CAP_NUMBER));
+        db.createCollection(MongoDbRoute.COLLECTION_STREAM_CHANGES);
+    }
+
+    private void execScriptInContainer(String script) throws Exception {
+        String cmd = IOUtils.toString(getClass().getResource("/" + script), 
StandardCharsets.UTF_8);
+        String[] cmds = cmd.split("\\n\\n");
+
+        for (int i = 0; i < cmds.length; i++) {
+            Container.ExecResult er = container.execInContainer(new String[] { 
"mongo", "--eval", cmds[i] });
+            if (er.getExitCode() != 0) {
+                throw new IllegalStateException("Exec exit code " + 
er.getExitCode() + ". " + er.getStderr());
+            }
+        }
+    }
+
     @Override
     public void stop() {
         try {
             if (container != null) {
                 container.stop();
             }
+            if (mongoClient != null) {
+                mongoClient.close();

Review comment:
       Maybe better to do this in `setUpDb`?

##########
File path: 
extensions/mongodb/deployment/src/main/java/org/apache/camel/quarkus/component/mongodb/deployment/MongoDbProcessor.java
##########
@@ -28,4 +30,9 @@
     FeatureBuildItem feature() {
         return new FeatureBuildItem(FEATURE);
     }
+
+    @BuildStep
+    ReflectiveClassBuildItem reflectiveClass() {
+        return new ReflectiveClassBuildItem(true, false, 
ChangeStreamDocument.class);

Review comment:
       If you create an issue on the Quarkus side, please create one in this 
project cross referencing it so that we remember to remove this.

##########
File path: 
integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTest.java
##########
@@ -16,22 +16,66 @@
  */
 package org.apache.camel.quarkus.component.mongodb.it;
 
+import java.sql.SQLException;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
 import io.quarkus.test.common.QuarkusTestResource;
 import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
 import io.restassured.http.ContentType;
 import io.restassured.path.json.JsonPath;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.util.CollectionHelper;
+import org.bson.Document;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
 
+import static 
org.apache.camel.quarkus.component.mongodb.it.MongoDbRoute.COLLECTION_PERSISTENT_TAILING;
+import static 
org.apache.camel.quarkus.component.mongodb.it.MongoDbRoute.COLLECTION_STREAM_CHANGES;
+import static 
org.apache.camel.quarkus.component.mongodb.it.MongoDbRoute.COLLECTION_TAILING;
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.Matchers.is;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 @QuarkusTest
 @QuarkusTestResource(MongoDbTestResource.class)
 class MongoDbTest {
+    public static final String MSG = "Hello Camel Quarkus Mongo DB";
+    public static final int CAP_NUMBER = 1000;
+
+    private static MongoClient mongoClient;
+
+    private static MongoDatabase db;
+
+    @BeforeAll
+    public static void setUp() throws SQLException {
+        final String mongoUrl = "mongodb://" + 
System.getProperty("quarkus.mongodb.hosts");

Review comment:
       Best to avoid looking up values set by `QuarkusTestResource` classes via 
`System.getProperty`. It wont work in Quarkus 2.x. Better to do the lookup via 
`ConfigProvider`.

##########
File path: 
integration-tests/mongodb/src/test/java/org/apache/camel/quarkus/component/mongodb/it/MongoDbTest.java
##########
@@ -16,22 +16,66 @@
  */
 package org.apache.camel.quarkus.component.mongodb.it;
 
+import java.sql.SQLException;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
+import com.mongodb.client.MongoClient;
+import com.mongodb.client.MongoClients;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
 import io.quarkus.test.common.QuarkusTestResource;
 import io.quarkus.test.junit.QuarkusTest;
 import io.restassured.RestAssured;
 import io.restassured.http.ContentType;
 import io.restassured.path.json.JsonPath;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.util.CollectionHelper;
+import org.bson.Document;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
 
+import static 
org.apache.camel.quarkus.component.mongodb.it.MongoDbRoute.COLLECTION_PERSISTENT_TAILING;
+import static 
org.apache.camel.quarkus.component.mongodb.it.MongoDbRoute.COLLECTION_STREAM_CHANGES;
+import static 
org.apache.camel.quarkus.component.mongodb.it.MongoDbRoute.COLLECTION_TAILING;
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.Matchers.is;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 @QuarkusTest
 @QuarkusTestResource(MongoDbTestResource.class)
 class MongoDbTest {
+    public static final String MSG = "Hello Camel Quarkus Mongo DB";
+    public static final int CAP_NUMBER = 1000;
+
+    private static MongoClient mongoClient;
+
+    private static MongoDatabase db;
+
+    @BeforeAll
+    public static void setUp() throws SQLException {
+        final String mongoUrl = "mongodb://" + 
System.getProperty("quarkus.mongodb.hosts");
+
+        if (mongoUrl != null) {
+            mongoClient = MongoClients.create(mongoUrl);
+        }
+        org.junit.Assume.assumeTrue(mongoClient != null);

Review comment:
       Wonder if we want to `assumeTrue`? IMO if the client cannot be created, 
then it's an error condition, so the test should fail.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to