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/19 14:02:35 UTC

[camel] branch master updated: CAMEL-16400: split unit and integration tests for camel-facebook (#5428)

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 c7752be  CAMEL-16400: split unit and integration tests for camel-facebook (#5428)
c7752be is described below

commit c7752bef5b30b04430b5c5ade2809b6f39e20e1a
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Mon Apr 19 16:02:12 2021 +0200

    CAMEL-16400: split unit and integration tests for camel-facebook (#5428)
---
 components/camel-facebook/pom.xml                  | 35 +++-------------------
 .../facebook/CamelFacebookTestSupport.java         | 31 +++++++++++++++----
 ...rTest.java => FacebookComponentConsumerIT.java} |  7 +++--
 ...java => FacebookComponentPageIdProducerIT.java} |  5 +++-
 ...rTest.java => FacebookComponentProducerIT.java} |  7 +++--
 ...okEndpointTest.java => FacebookEndpointIT.java} |  7 +++--
 ...UserMethodsTest.java => TestUserMethodsIT.java} |  7 +++--
 .../src/test/resources/test-options.properties     |  6 ++--
 8 files changed, 56 insertions(+), 49 deletions(-)

diff --git a/components/camel-facebook/pom.xml b/components/camel-facebook/pom.xml
index c7b2a52..0c80031 100644
--- a/components/camel-facebook/pom.xml
+++ b/components/camel-facebook/pom.xml
@@ -73,41 +73,14 @@
                     <forkCount>1</forkCount>
                     <reuseForks>true</reuseForks>
                     <forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds>
-                    <includes>
-                        <!-- Here we only run test of  -->
-                        <include>**/ReadingBuilderTest.java</include>
-                        <include>**/FacebookMethodsType*Test.java</include>
-                        <include>**/FacebookEndpointConfigurationTest.java</include>
-                    </includes>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-failsafe-plugin</artifactId>
+            </plugin>
         </plugins>
     </build>
 
-    <profiles>
-        <profile>
-            <id>facebook-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>
-                            <excludes>
-                                <exclude>**/*XXXTest.java</exclude>
-                            </excludes>
-                            <includes>
-                                <include>**/*Test.java</include>
-                            </includes>
-                        </configuration>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
-    </profiles>
 
 </project>
diff --git a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/CamelFacebookTestSupport.java b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/CamelFacebookTestSupport.java
index ac8d51a..cf09f3a 100644
--- a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/CamelFacebookTestSupport.java
+++ b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/CamelFacebookTestSupport.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.facebook;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.HashMap;
@@ -33,12 +34,7 @@ public abstract class CamelFacebookTestSupport extends CamelTestSupport {
     protected FacebookConfiguration configuration;
 
     protected void loadProperties(CamelContext context) throws Exception {
-        URL url = getClass().getResource("/test-options.properties");
-
-        InputStream inStream = url.openStream();
-
-        properties = new Properties();
-        properties.load(inStream);
+        loadProperties();
 
         Map<String, Object> options = new HashMap<>();
         for (Map.Entry<Object, Object> entry : properties.entrySet()) {
@@ -49,6 +45,29 @@ public abstract class CamelFacebookTestSupport extends CamelTestSupport {
         PropertyBindingSupport.bindProperties(context, configuration, options);
     }
 
+    private static Properties loadProperties() {
+        URL url = CamelFacebookTestSupport.class.getResource("/test-options.properties");
+
+        InputStream inStream = null;
+        try {
+            inStream = url.openStream();
+
+            Properties properties = new Properties();
+            properties.load(inStream);
+            return properties;
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    // Used by JUnit to determine whether to run the integration tests
+    @SuppressWarnings("unused")
+    private static boolean hasCredentials() {
+        Properties properties = loadProperties();
+
+        return !properties.getProperty("oAuthAccessToken", "").isEmpty();
+    }
+
     @Override
     protected CamelContext createCamelContext() throws Exception {
         CamelContext context = super.createCamelContext();
diff --git a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentConsumerTest.java b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentConsumerIT.java
similarity index 95%
rename from components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentConsumerTest.java
rename to components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentConsumerIT.java
index 544605a..6471f98 100644
--- a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentConsumerTest.java
+++ b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentConsumerIT.java
@@ -35,17 +35,20 @@ import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.support.DefaultPollingConsumerPollStrategy;
 import org.apache.camel.support.ScheduledPollConsumer;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
-public class FacebookComponentConsumerTest extends CamelFacebookTestSupport {
+@EnabledIf(value = "org.apache.camel.component.facebook.CamelFacebookTestSupport#hasCredentials",
+           disabledReason = "Facebook credentials were not provided")
+public class FacebookComponentConsumerIT extends CamelFacebookTestSupport {
     public static final String APACHE_FOUNDATION_PAGE_ID = "6538157161";
 
     private final Set<String> searchNames = new HashSet<>();
     private List<String> excludedNames;
 
-    public FacebookComponentConsumerTest() throws Exception {
+    public FacebookComponentConsumerIT() throws Exception {
         // find search methods for consumer tests
         for (Method method : SearchMethods.class.getDeclaredMethods()) {
             String name = getShortName(method.getName());
diff --git a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentPageIdProducerTest.java b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentPageIdProducerIT.java
similarity index 89%
rename from components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentPageIdProducerTest.java
rename to components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentPageIdProducerIT.java
index dd113cf..2b8267c 100644
--- a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentPageIdProducerTest.java
+++ b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentPageIdProducerIT.java
@@ -21,8 +21,11 @@ import facebook4j.ResponseList;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
 
-public class FacebookComponentPageIdProducerTest extends CamelFacebookTestSupport {
+@EnabledIf(value = "org.apache.camel.component.facebook.CamelFacebookTestSupport#hasCredentials",
+           disabledReason = "Facebook credentials were not provided")
+public class FacebookComponentPageIdProducerIT extends CamelFacebookTestSupport {
     public static final String APACHE_FOUNDATION_PAGE_ID = "6538157161";
 
     long lastTimestamp = -1;
diff --git a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentProducerTest.java b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentProducerIT.java
similarity index 96%
rename from components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentProducerTest.java
rename to components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentProducerIT.java
index 09341d7..2f93c32 100644
--- a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentProducerTest.java
+++ b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookComponentProducerIT.java
@@ -32,18 +32,21 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.facebook.data.FacebookMethodsType;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
-public class FacebookComponentProducerTest extends CamelFacebookTestSupport {
+@EnabledIf(value = "org.apache.camel.component.facebook.CamelFacebookTestSupport#hasCredentials",
+           disabledReason = "Facebook credentials were not provided")
+public class FacebookComponentProducerIT extends CamelFacebookTestSupport {
 
     private final Set<String> noArgNames = new HashSet<>();
 
     private final List<String> idExcludes;
     private final List<String> readingExcludes;
 
-    public FacebookComponentProducerTest() throws Exception {
+    public FacebookComponentProducerIT() throws Exception {
         for (Class<?> clazz : Facebook.class.getInterfaces()) {
             final String clazzName = clazz.getSimpleName();
             if (clazzName.endsWith("Methods") && !clazzName.equals("GameMethods")) {
diff --git a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookEndpointTest.java b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookEndpointIT.java
similarity index 86%
rename from components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookEndpointTest.java
rename to components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookEndpointIT.java
index 8b231db..0c06e62 100644
--- a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookEndpointTest.java
+++ b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/FacebookEndpointIT.java
@@ -20,13 +20,16 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
 
 /**
  * Test preconfigured Facebook component.
  */
-public class FacebookEndpointTest extends CamelFacebookTestSupport {
+@EnabledIf(value = "org.apache.camel.component.facebook.CamelFacebookTestSupport#hasCredentials",
+           disabledReason = "Facebook credentials were not provided")
+public class FacebookEndpointIT extends CamelFacebookTestSupport {
 
-    public FacebookEndpointTest() throws Exception {
+    public FacebookEndpointIT() throws Exception {
     }
 
     @Test
diff --git a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/TestUserMethodsTest.java b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/TestUserMethodsIT.java
similarity index 95%
rename from components/camel-facebook/src/test/java/org/apache/camel/component/facebook/TestUserMethodsTest.java
rename to components/camel-facebook/src/test/java/org/apache/camel/component/facebook/TestUserMethodsIT.java
index 03eb20c..aa23211 100644
--- a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/TestUserMethodsTest.java
+++ b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/TestUserMethodsIT.java
@@ -24,6 +24,7 @@ import java.util.Map;
 import facebook4j.TestUser;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIf;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -32,12 +33,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 /**
  * Test methods in {@link facebook4j.api.TestUserMethods}
  */
-public class TestUserMethodsTest extends CamelFacebookTestSupport {
+@EnabledIf(value = "org.apache.camel.component.facebook.CamelFacebookTestSupport#hasCredentials",
+           disabledReason = "Facebook credentials were not provided")
+public class TestUserMethodsIT extends CamelFacebookTestSupport {
 
     private static final String TEST_USER1 = "test one";
     private static final String TEST_USER2 = "test two";
 
-    public TestUserMethodsTest() throws Exception {
+    public TestUserMethodsIT() throws Exception {
     }
 
     @Test
diff --git a/components/camel-facebook/src/test/resources/test-options.properties b/components/camel-facebook/src/test/resources/test-options.properties
index 83dd824..99c3466 100644
--- a/components/camel-facebook/src/test/resources/test-options.properties
+++ b/components/camel-facebook/src/test/resources/test-options.properties
@@ -15,6 +15,6 @@
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
 
-oAuthAppId=<app-id>
-oAuthAppSecret=<app-secret>
-oAuthAccessToken=<access-token>
+oAuthAppId=
+oAuthAppSecret=
+oAuthAccessToken=