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 12:12:03 UTC
[camel] branch main updated: CAMEL-18608: camel-box - Fix the regression with shared connection (#8527)
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 526c0a13357 CAMEL-18608: camel-box - Fix the regression with shared connection (#8527)
526c0a13357 is described below
commit 526c0a1335716481281ec150f7524e2d2384d4e4
Author: Nicolas Filotto <es...@users.noreply.github.com>
AuthorDate: Wed Oct 12 14:11:55 2022 +0200
CAMEL-18608: camel-box - Fix the regression with shared connection (#8527)
## Motivation
The test `org.apache.camel.component.box.BoxSharedConnectionTest.testEndpointUsesSharedConnection` fails continuously on Jenkins indicating that there is a regression so it needs to be fixed.
## Modifications:
* Modify the implementation of the `equals` of the class `BoxConfiguration` to support subclasses like `org.apache.camel.component.box.BoxFilesManagerEndpointConfiguration`
* Cleanup the code of the test class (not related to the regression)
---
.../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;
+ }
}