You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/10/12 11:01:50 UTC

[camel] branch CAMEL-18608/fix-testEndpointUsesSharedConnection created (now 37e58bde016)

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

nfilotto pushed a change to branch CAMEL-18608/fix-testEndpointUsesSharedConnection
in repository https://gitbox.apache.org/repos/asf/camel.git


      at 37e58bde016 CAMEL-18608: camel-box - Fix the regression with shared connection

This branch includes the following new commits:

     new 37e58bde016 CAMEL-18608: camel-box - Fix the regression with shared connection

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[camel] 01/01: CAMEL-18608: camel-box - Fix the regression with shared connection

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch CAMEL-18608/fix-testEndpointUsesSharedConnection
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 37e58bde016d4d76ceed83eaf45b8abe8f58c5f6
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Wed Oct 12 13:01:24 2022 +0200

    CAMEL-18608: camel-box - Fix the regression with shared connection
---
 .../camel/component/box/BoxConfiguration.java      |  7 +-
 .../component/box/BoxSharedConnectionTest.java     | 89 ++++++++++------------
 2 files changed, 41 insertions(+), 55 deletions(-)

diff --git a/components/camel-box/camel-box-component/src/main/java/org/apache/camel/component/box/BoxConfiguration.java b/components/camel-box/camel-box-component/src/main/java/org/apache/camel/component/box/BoxConfiguration.java
index 7f20e2f9265..4601c84f91f 100644
--- a/components/camel-box/camel-box-component/src/main/java/org/apache/camel/component/box/BoxConfiguration.java
+++ b/components/camel-box/camel-box-component/src/main/java/org/apache/camel/component/box/BoxConfiguration.java
@@ -467,11 +467,8 @@ public class BoxConfiguration {
             return true;
         }
 
-        if (o == null) {
-            return false;
-        }
-
-        if (this.getClass() != o.getClass()) {
+        // Don't check that the classes are equal intentionally to support subclasses
+        if (!(o instanceof BoxConfiguration)) {
             return false;
         }
 
diff --git a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxSharedConnectionTest.java b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxSharedConnectionTest.java
index a6b036c0502..c8b859d2115 100644
--- a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxSharedConnectionTest.java
+++ b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxSharedConnectionTest.java
@@ -28,93 +28,82 @@ import org.junit.jupiter.api.Test;
 import org.mockito.MockedStatic;
 import org.mockito.Mockito;
 
-public class BoxSharedConnectionTest {
+class BoxSharedConnectionTest {
 
     private static final String PATH_PREFIX
             = BoxApiCollection.getCollection().getApiName(BoxFilesManagerApiMethod.class).getName();
 
     @Test
-    public void testEndpointUsesSharedConnection() throws Exception {
+    void testEndpointUsesSharedConnection() throws Exception {
         final String boxUri = "box:" + PATH_PREFIX + "/getFileInfo";
 
-        BoxConfiguration configuration = new BoxConfiguration();
-        configuration.setUserName("camel@apache.org");
-        configuration.setUserPassword("p4ssw0rd");
-        configuration.setClientId("camel-client-id");
-        configuration.setClientSecret("camel-client-secret");
-        configuration.setAuthenticationType("STANDARD_AUTHENTICATION");
+        BoxConfiguration configuration = createBoxConfiguration();
 
         BoxComponent component = new BoxComponent();
         component.setConfiguration(configuration);
 
-        CamelContext camelContext = new DefaultCamelContext();
-        camelContext.addComponent("box", component);
-        camelContext.addRoutes(new RouteBuilder() {
-            @Override
-            public void configure() {
-                from("direct:start").to(boxUri);
-            }
-        });
+        try (CamelContext camelContext = createCamelContext(boxUri, component)) {
 
-        BoxAPIConnection connection = Mockito.mock(BoxAPIConnection.class);
+            BoxAPIConnection connection = Mockito.mock(BoxAPIConnection.class);
 
-        try (MockedStatic<BoxConnectionHelper> helper = Mockito.mockStatic(BoxConnectionHelper.class)) {
-            helper.when(() -> BoxConnectionHelper.createConnection(configuration)).thenReturn(connection);
+            try (MockedStatic<BoxConnectionHelper> helper = Mockito.mockStatic(BoxConnectionHelper.class)) {
+                helper.when(() -> BoxConnectionHelper.createConnection(configuration)).thenReturn(connection);
 
-            camelContext.start();
-            try {
+                camelContext.start();
                 BoxEndpoint endpoint = camelContext.getEndpoint(boxUri, BoxEndpoint.class);
 
                 helper.verify(() -> BoxConnectionHelper.createConnection(configuration), Mockito.times(1));
 
                 Assertions.assertSame(component.getBoxConnection(), endpoint.getBoxConnection());
-            } finally {
-                camelContext.stop();
             }
         }
     }
 
     @Test
-    public void testEndpointOverridesSharedConnection() throws Exception {
+    void testEndpointOverridesSharedConnection() throws Exception {
         String boxUri = "box:" + PATH_PREFIX + "/getFileInfo?userPassword=0th3rP4ssw0rd";
 
-        BoxConfiguration configuration = new BoxConfiguration();
-        configuration.setUserName("camel@apache.org");
-        configuration.setUserPassword("p4ssw0rd");
-        configuration.setClientId("camel-client-id");
-        configuration.setClientSecret("camel-client-secret");
-        configuration.setAuthenticationType("STANDARD_AUTHENTICATION");
-
         BoxComponent component = new BoxComponent();
-        component.setConfiguration(configuration);
+        component.setConfiguration(createBoxConfiguration());
 
-        CamelContext camelContext = new DefaultCamelContext();
-        camelContext.addComponent("box", component);
-        camelContext.addRoutes(new RouteBuilder() {
-            @Override
-            public void configure() {
-                from("direct:start").to(boxUri);
-            }
-        });
-
-        BoxAPIConnection componentConnection = Mockito.mock(BoxAPIConnection.class);
-        BoxAPIConnection endpointConnection = Mockito.mock(BoxAPIConnection.class);
+        try (CamelContext camelContext = createCamelContext(boxUri, component)) {
+            BoxAPIConnection componentConnection = Mockito.mock(BoxAPIConnection.class);
+            BoxAPIConnection endpointConnection = Mockito.mock(BoxAPIConnection.class);
 
-        try (MockedStatic<BoxConnectionHelper> helper = Mockito.mockStatic(BoxConnectionHelper.class)) {
-            helper.when(() -> BoxConnectionHelper.createConnection(Mockito.isA(BoxConfiguration.class)))
-                    .thenReturn(componentConnection, endpointConnection);
+            try (MockedStatic<BoxConnectionHelper> helper = Mockito.mockStatic(BoxConnectionHelper.class)) {
+                helper.when(() -> BoxConnectionHelper.createConnection(Mockito.isA(BoxConfiguration.class)))
+                        .thenReturn(componentConnection, endpointConnection);
 
-            camelContext.start();
-            try {
+                camelContext.start();
                 BoxEndpoint endpoint = camelContext.getEndpoint(boxUri, BoxEndpoint.class);
 
                 helper.verify(() -> BoxConnectionHelper.createConnection(Mockito.any()), Mockito.times(2));
 
                 Assertions.assertSame(componentConnection, component.getBoxConnection());
                 Assertions.assertSame(endpointConnection, endpoint.getBoxConnection());
-            } finally {
-                camelContext.stop();
             }
         }
     }
+
+    private static CamelContext createCamelContext(String boxUri, BoxComponent component) throws Exception {
+        CamelContext camelContext = new DefaultCamelContext();
+        camelContext.addComponent("box", component);
+        camelContext.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:start").to(boxUri);
+            }
+        });
+        return camelContext;
+    }
+
+    private static BoxConfiguration createBoxConfiguration() {
+        BoxConfiguration configuration = new BoxConfiguration();
+        configuration.setUserName("camel@apache.org");
+        configuration.setUserPassword("p4ssw0rd");
+        configuration.setClientId("camel-client-id");
+        configuration.setClientSecret("camel-client-secret");
+        configuration.setAuthenticationType("STANDARD_AUTHENTICATION");
+        return configuration;
+    }
 }