You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2021/04/16 09:25:14 UTC

[camel] branch master updated: CAMEL-16400: split unit and integration tests for camel-google-bigquery (#5385)

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 253541f  CAMEL-16400: split unit and integration tests for camel-google-bigquery (#5385)
253541f is described below

commit 253541f7ef5a698753b17938fbaa4457a4108edb
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Fri Apr 16 11:24:18 2021 +0200

    CAMEL-16400: split unit and integration tests for camel-google-bigquery (#5385)
---
 .../camel-google/camel-google-bigquery/ReadMe.md   |  6 ++---
 .../camel-google/camel-google-bigquery/pom.xml     | 30 ++--------------------
 .../integration/{AsyncTest.java => AsyncIT.java}   |  5 +++-
 ...ueryTestSupport.java => BigQueryITSupport.java} | 12 ++++++---
 ...namicTableIdTest.java => DynamicTableIdIT.java} |  5 +++-
 .../{InsertIdTest.java => InsertIdIT.java}         |  5 +++-
 .../{SingleRowTest.java => SingleRowIT.java}       |  5 +++-
 ...sourceTest.java => SqlQueryFromResourceIT.java} |  7 +++--
 .../sql/{SqlQueryTest.java => SqlQueryIT.java}     |  7 +++--
 .../GoogleBigQuerySQLProducerWithParamersTest.java |  2 +-
 10 files changed, 40 insertions(+), 44 deletions(-)

diff --git a/components/camel-google/camel-google-bigquery/ReadMe.md b/components/camel-google/camel-google-bigquery/ReadMe.md
index d29580b..aff4f01 100644
--- a/components/camel-google/camel-google-bigquery/ReadMe.md
+++ b/components/camel-google/camel-google-bigquery/ReadMe.md
@@ -30,14 +30,12 @@ https://developers.google.com/identity/protocols/application-default-credentials
 
 Service Account Email and Service Account Key can be found in the GCP JSON credentials file as client_email and private_key respectively.
 
-For the tests the `project.id` and `bigquery.datasetId` needs to be configured. By default
+For the tests the `project.id` and `bigquery.datasetId` needs to be configured. By default,
 the current google user will be used to connect but credentials can be provided either by
 account/key (via `service.account` and `service.key`) or a credentials file (`service.credentialsFileLocation`)
 
 Running tests against BigQuery instance:
 
 ```
-mvn -Pgoogle-bigquery-test verify
+mvn verify
 ```
-
-
diff --git a/components/camel-google/camel-google-bigquery/pom.xml b/components/camel-google/camel-google-bigquery/pom.xml
index 045ddef..33ded46 100644
--- a/components/camel-google/camel-google-bigquery/pom.xml
+++ b/components/camel-google/camel-google-bigquery/pom.xml
@@ -87,42 +87,16 @@
     <build>
         <plugins>
             <plugin>
-                <artifactId>maven-surefire-plugin</artifactId>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-failsafe-plugin</artifactId>
                 <configuration>
                     <childDelegation>false</childDelegation>
                     <useFile>true</useFile>
                     <forkCount>1</forkCount>
                     <reuseForks>true</reuseForks>
                     <forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds>
-                    <includes>
-                        <!-- Here we only run test of  -->
-                        <include>**/unit/**/*.java</include>
-                    </includes>
                 </configuration>
             </plugin>
         </plugins>
     </build>
-
-    <profiles>
-        <profile>
-            <id>google-bigquery-test</id>
-            <build>
-                <plugins>
-                    <plugin>
-                        <artifactId>maven-surefire-plugin</artifactId>
-                        <configuration>
-                            <childDelegation>false</childDelegation>
-                            <useFile>true</useFile>
-                            <forkCount>1</forkCount>
-                            <reuseForks>true</reuseForks>
-                            <forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds>
-                            <includes>
-                                <include>**/*Test.java</include>
-                            </includes>
-                        </configuration>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
-    </profiles>
 </project>
diff --git a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/AsyncTest.java b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/AsyncIT.java
similarity index 92%
rename from components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/AsyncTest.java
rename to components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/AsyncIT.java
index 297de66..ae6cd73 100644
--- a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/AsyncTest.java
+++ b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/AsyncIT.java
@@ -34,8 +34,11 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.support.DefaultExchange;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
 
-public class AsyncTest extends BigQueryTestSupport {
+@EnabledIf(value = "org.apache.camel.component.google.bigquery.integration.BigQueryITSupport#hasCredentials",
+           disabledReason = "Credentials were not provided")
+public class AsyncIT extends BigQueryITSupport {
     private static final String TABLE_ID = "asynctest";
 
     @EndpointInject("direct:in")
diff --git a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/BigQueryTestSupport.java b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/BigQueryITSupport.java
similarity index 93%
rename from components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/BigQueryTestSupport.java
rename to components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/BigQueryITSupport.java
index 0436148..bb44779 100644
--- a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/BigQueryTestSupport.java
+++ b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/BigQueryITSupport.java
@@ -45,14 +45,14 @@ import org.slf4j.LoggerFactory;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
-public class BigQueryTestSupport extends CamelTestSupport {
+public class BigQueryITSupport extends CamelTestSupport {
     public static final String SERVICE_KEY;
     public static final String SERVICE_ACCOUNT;
     public static final String PROJECT_ID;
     public static final String DATASET_ID;
     public static final String CREDENTIALS_FILE_LOCATION;
 
-    private static final Logger LOGGER = LoggerFactory.getLogger(BigQueryTestSupport.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(BigQueryITSupport.class);
 
     private GoogleBigQueryConnectionFactory connectionFactory;
 
@@ -67,7 +67,7 @@ public class BigQueryTestSupport extends CamelTestSupport {
 
     private static Properties loadProperties() {
         Properties testProperties = new Properties();
-        InputStream fileIn = BigQueryTestSupport.class.getClassLoader().getResourceAsStream("simple.properties");
+        InputStream fileIn = BigQueryITSupport.class.getClassLoader().getResourceAsStream("simple.properties");
         try {
             testProperties.load(fileIn);
 
@@ -78,6 +78,12 @@ public class BigQueryTestSupport extends CamelTestSupport {
         return testProperties;
     }
 
+    // This is used by JUnit to to dynamically enable / disable the integration tests
+    @SuppressWarnings("unused")
+    private static boolean hasCredentials() {
+        return (SERVICE_KEY != null && SERVICE_ACCOUNT != null) || CREDENTIALS_FILE_LOCATION != null;
+    }
+
     protected void addBigqueryComponent(CamelContext context) {
 
         connectionFactory = new GoogleBigQueryConnectionFactory()
diff --git a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/DynamicTableIdTest.java b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/DynamicTableIdIT.java
similarity index 92%
rename from components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/DynamicTableIdTest.java
rename to components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/DynamicTableIdIT.java
index f567ada..e23dbfd 100644
--- a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/DynamicTableIdTest.java
+++ b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/DynamicTableIdIT.java
@@ -31,8 +31,11 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.support.DefaultExchange;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
 
-public class DynamicTableIdTest extends BigQueryTestSupport {
+@EnabledIf(value = "org.apache.camel.component.google.bigquery.integration.BigQueryITSupport#hasCredentials",
+           disabledReason = "Credentials were not provided")
+public class DynamicTableIdIT extends BigQueryITSupport {
     private static final String TABLE_ID_1 = "dynamic_table_1";
     private static final String TABLE_ID_2 = "dynamic_table_2";
 
diff --git a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/InsertIdTest.java b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/InsertIdIT.java
similarity index 94%
rename from components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/InsertIdTest.java
rename to components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/InsertIdIT.java
index bca8e3e..00aab62 100644
--- a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/InsertIdTest.java
+++ b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/InsertIdIT.java
@@ -31,8 +31,11 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.support.DefaultExchange;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
 
-public class InsertIdTest extends BigQueryTestSupport {
+@EnabledIf(value = "org.apache.camel.component.google.bigquery.integration.BigQueryITSupport#hasCredentials",
+           disabledReason = "Credentials were not provided")
+public class InsertIdIT extends BigQueryITSupport {
     private static final String TABLE_ID = "insertId";
 
     @EndpointInject("direct:withInsertId")
diff --git a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/SingleRowTest.java b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/SingleRowIT.java
similarity index 90%
rename from components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/SingleRowTest.java
rename to components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/SingleRowIT.java
index 4786cb4..979d927 100644
--- a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/SingleRowTest.java
+++ b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/SingleRowIT.java
@@ -30,8 +30,11 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.support.DefaultExchange;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
 
-public class SingleRowTest extends BigQueryTestSupport {
+@EnabledIf(value = "org.apache.camel.component.google.bigquery.integration.BigQueryITSupport#hasCredentials",
+           disabledReason = "Credentials were not provided")
+public class SingleRowIT extends BigQueryITSupport {
     private static final String TABLE_ID = "singlerow";
 
     @EndpointInject("direct:in")
diff --git a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/sql/SqlQueryFromResourceTest.java b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/sql/SqlQueryFromResourceIT.java
similarity index 90%
rename from components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/sql/SqlQueryFromResourceTest.java
rename to components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/sql/SqlQueryFromResourceIT.java
index f0af94a..b789b8d 100644
--- a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/sql/SqlQueryFromResourceTest.java
+++ b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/sql/SqlQueryFromResourceIT.java
@@ -26,13 +26,16 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.google.bigquery.integration.BigQueryTestSupport;
+import org.apache.camel.component.google.bigquery.integration.BigQueryITSupport;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.support.DefaultExchange;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
 
-public class SqlQueryFromResourceTest extends BigQueryTestSupport {
+@EnabledIf(value = "org.apache.camel.component.google.bigquery.integration.BigQueryITSupport#hasCredentials",
+           disabledReason = "Credentials were not provided")
+public class SqlQueryFromResourceIT extends BigQueryITSupport {
     private static final String TABLE_ID = "test_sql_table";
 
     @EndpointInject("direct:in")
diff --git a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/sql/SqlQueryTest.java b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/sql/SqlQueryIT.java
similarity index 91%
rename from components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/sql/SqlQueryTest.java
rename to components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/sql/SqlQueryIT.java
index 564cd8f..91f0a18 100644
--- a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/sql/SqlQueryTest.java
+++ b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/integration/sql/SqlQueryIT.java
@@ -26,13 +26,16 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.google.bigquery.integration.BigQueryTestSupport;
+import org.apache.camel.component.google.bigquery.integration.BigQueryITSupport;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.support.DefaultExchange;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
 
-public class SqlQueryTest extends BigQueryTestSupport {
+@EnabledIf(value = "org.apache.camel.component.google.bigquery.integration.BigQueryITSupport#hasCredentials",
+           disabledReason = "Credentials were not provided")
+public class SqlQueryIT extends BigQueryITSupport {
     private static final String TABLE_ID = "test_sql_table";
 
     @EndpointInject("direct:in")
diff --git a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerWithParamersTest.java b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerWithParamersTest.java
index 3d1dc87..61c29d9 100644
--- a/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerWithParamersTest.java
+++ b/components/camel-google/camel-google-bigquery/src/test/java/org/apache/camel/component/google/bigquery/unit/sql/GoogleBigQuerySQLProducerWithParamersTest.java
@@ -30,7 +30,7 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.mockito.ArgumentCaptor;
 
-import static org.apache.camel.component.google.bigquery.integration.BigQueryTestSupport.PROJECT_ID;
+import static org.apache.camel.component.google.bigquery.integration.BigQueryITSupport.PROJECT_ID;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;