This is an automated email from the ASF dual-hosted git repository. orpiske 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 6daeb3ec94d CAMEL-20838: prevent tests from overriding restricted methods 6daeb3ec94d is described below commit 6daeb3ec94d2e80f7c4d30a2b27840b36b6e8e46 Author: Otavio Rodolfo Piske <angusyo...@gmail.com> AuthorDate: Wed Jun 12 09:18:58 2024 +0200 CAMEL-20838: prevent tests from overriding restricted methods - prevent tests from overriding tearDown - prevent tests from overriding setUp - prevent spring tests from overriding doPreSetup - rework camel-rest-openapi tests to avoid restricted methods - for Spring-based tests, the doPreSetup configures the context, application context and other requirements --- .../cloud/SpringConsulServiceCallRouteTest.java | 4 +- .../cxf/CxfSpringCustomizedExceptionTest.java | 1 - ...ispanRemoteIdempotentRepositoryTestSupport.java | 3 +- .../leveldb/LevelDBSpringAggregateTest.java | 3 +- .../camel/component/rest/openapi/HttpsV3Test.java | 19 ++------ ...tpsV3Test.java => ManagedCamelTestSupport.java} | 37 +++++++++++---- .../rest/openapi/RestOpenApiComponentV3Test.java | 31 ++++--------- .../openapi/RestOpenApiComponentV3YamlTest.java | 30 ++++-------- .../openapi/RestOpenApiDelegateHttpsV3Test.java | 29 ++++++++---- .../openapi/RestOpenApiGlobalHttpsV31Test.java | 10 ++-- .../rest/openapi/RestOpenApiGlobalHttpsV3Test.java | 10 ++-- .../apache/camel/test/junit5/CamelTestSupport.java | 4 +- .../camel/test/junit5/ExchangeTestSupport.java | 3 +- .../camel/test/junit5/CamelTestSupportTest.java | 5 +- .../RouteBuilderConfigureExceptionTest.java | 54 ---------------------- .../main/junit5/legacy/ReplaceRouteFromTest.java | 5 +- .../test/spring/junit5/CamelSpringTestSupport.java | 13 ++---- .../camel/test/patterns/DebugSpringTest.java | 4 +- .../SpringZooKeeperServiceCallRouteIT.java | 4 +- .../ROOT/pages/camel-4x-upgrade-guide-4_8.adoc | 5 ++ 20 files changed, 105 insertions(+), 169 deletions(-) diff --git a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/SpringConsulServiceCallRouteTest.java b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/SpringConsulServiceCallRouteTest.java index 6958d43a1c8..5eeabb14ae1 100644 --- a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/SpringConsulServiceCallRouteTest.java +++ b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cloud/SpringConsulServiceCallRouteTest.java @@ -50,9 +50,7 @@ public abstract class SpringConsulServiceCallRouteTest extends CamelSpringTestSu // ************************************************************************* @Override - public void doPreSetup() throws Exception { - super.doPreSetup(); - + public void setupResources() { this.client = Consul.builder().withUrl(service.getConsulUrl()).build().agentClient(); this.registrations = Arrays.asList( diff --git a/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/CxfSpringCustomizedExceptionTest.java b/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/CxfSpringCustomizedExceptionTest.java index cb2ba0fe3a3..7c87636297b 100644 --- a/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/CxfSpringCustomizedExceptionTest.java +++ b/components/camel-cxf/camel-cxf-spring-soap/src/test/java/org/apache/camel/component/cxf/CxfSpringCustomizedExceptionTest.java @@ -57,7 +57,6 @@ public class CxfSpringCustomizedExceptionTest extends CamelSpringTestSupport { @Override public void setupResources() { CXFTestSupport.getPort1(); - } @Override diff --git a/components/camel-infinispan/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/remote/spring/SpringInfinispanRemoteIdempotentRepositoryTestSupport.java b/components/camel-infinispan/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/remote/spring/SpringInfinispanRemoteIdempotentRepositoryTestSupport.java index 425a49ac6f8..d8dfe88e8c9 100644 --- a/components/camel-infinispan/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/remote/spring/SpringInfinispanRemoteIdempotentRepositoryTestSupport.java +++ b/components/camel-infinispan/camel-infinispan/src/test/java/org/apache/camel/component/infinispan/remote/spring/SpringInfinispanRemoteIdempotentRepositoryTestSupport.java @@ -37,7 +37,7 @@ public abstract class SpringInfinispanRemoteIdempotentRepositoryTestSupport exte public static InfinispanService service = InfinispanServiceFactory.createSingletonInfinispanService(); @Override - public void doPreSetup() throws Exception { + public void setupResources() throws Exception { ConfigurationBuilder clientBuilder = new ConfigurationBuilder(); // for default tests, we force return value for all the @@ -65,7 +65,6 @@ public abstract class SpringInfinispanRemoteIdempotentRepositoryTestSupport exte MarshallerRegistration.init(MarshallerUtil.getSerializationContext(manager)); RemoteCache<Object, Object> cache = manager.administration().getOrCreateCache("idempotent", (String) null); assertNotNull(cache); - super.doPreSetup(); } @Test diff --git a/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSpringAggregateTest.java b/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSpringAggregateTest.java index 4d53797c9f8..c3e6360c489 100644 --- a/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSpringAggregateTest.java +++ b/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSpringAggregateTest.java @@ -34,8 +34,7 @@ import static org.apache.camel.test.junit5.TestSupport.deleteDirectory; public class LevelDBSpringAggregateTest extends CamelSpringTestSupport { @Override - public void doPreSetup() throws Exception { - super.doPreSetup(); + public void setupResources() { deleteDirectory("target/data"); } diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/HttpsV3Test.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/HttpsV3Test.java index e822a25b850..06d5b57c714 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/HttpsV3Test.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/HttpsV3Test.java @@ -41,10 +41,10 @@ import org.apache.camel.RoutesBuilder; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.rest.RestEndpoint; import org.apache.camel.converter.jaxb.JaxbDataFormat; +import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.support.jsse.CipherSuitesParameters; import org.apache.camel.support.jsse.SSLContextParameters; import org.apache.camel.support.jsse.TrustManagersParameters; -import org.apache.camel.test.junit5.CamelTestSupport; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.security.CertificateUtils; import org.junit.jupiter.api.AfterAll; @@ -62,7 +62,7 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMoc import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -public abstract class HttpsV3Test extends CamelTestSupport { +public abstract class HttpsV3Test extends ManagedCamelTestSupport { public static WireMockServer petstore = new WireMockServer( wireMockConfig().httpServerFactory(new WireMockJettyServerFactory()).containerThreads(13).dynamicPort() @@ -83,24 +83,15 @@ public abstract class HttpsV3Test extends CamelTestSupport { petstore.stop(); } - @Override - public void setUp() { - } - @BeforeEach public void resetWireMock() { petstore.resetRequests(); } - public void doSetUp(String componentName) throws Exception { - this.componentName = componentName; - super.setUp(); - } - @ParameterizedTest @MethodSource("knownProducers") public void shouldBeConfiguredForHttps(String componentName) throws Exception { - doSetUp(componentName); + initializeContextForComponent(componentName); final Pet pet = template.requestBodyAndHeader("direct:getPetById", NO_BODY, "petId", 14, Pet.class); @@ -114,8 +105,8 @@ public abstract class HttpsV3Test extends CamelTestSupport { } @Override - protected CamelContext createCamelContext() throws Exception { - final CamelContext camelContext = super.createCamelContext(); + protected CamelContext createCamelContext(String componentName) { + final CamelContext camelContext = new DefaultCamelContext(); final RestOpenApiComponent component = new RestOpenApiComponent(); component.setComponentName(componentName); diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiGlobalHttpsV3Test.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/ManagedCamelTestSupport.java similarity index 50% copy from components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiGlobalHttpsV3Test.java copy to components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/ManagedCamelTestSupport.java index a43a27b58cc..7e896da4543 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiGlobalHttpsV3Test.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/ManagedCamelTestSupport.java @@ -14,20 +14,41 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.camel.component.rest.openapi; import org.apache.camel.CamelContext; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.RoutesBuilder; +import org.junit.jupiter.api.AfterEach; + +abstract class ManagedCamelTestSupport { + protected CamelContext context; + protected ProducerTemplate template; + + protected abstract RoutesBuilder createRouteBuilder(); + + protected abstract CamelContext createCamelContext(String componentName); -public class RestOpenApiGlobalHttpsV3Test extends HttpsV3Test { + protected void initializeContextForComponent(String componentName) throws Exception { + context = createCamelContext(componentName); + + context.addRoutes(createRouteBuilder()); + + context.start(); + template = context.createProducerTemplate(); + template.start(); + } - @Override - protected CamelContext createCamelContext() throws Exception { - CamelContext camelContext = super.createCamelContext(); - camelContext.setSSLContextParameters(createHttpsParameters(camelContext)); + @AfterEach + final void shutdownEverything() { + if (template != null) { + template.stop(); + } - RestOpenApiComponent component = camelContext.getComponent("petStore", RestOpenApiComponent.class); - component.setUseGlobalSslContextParameters(true); + if (context != null) { + context.stop(); + } - return camelContext; } } diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentV3Test.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentV3Test.java index b2632cbbcaf..dcc2dc25d10 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentV3Test.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentV3Test.java @@ -36,7 +36,7 @@ import org.apache.camel.RoutesBuilder; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.rest.RestEndpoint; import org.apache.camel.converter.jaxb.JaxbDataFormat; -import org.apache.camel.test.junit5.CamelTestSupport; +import org.apache.camel.impl.DefaultCamelContext; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -55,14 +55,12 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMoc import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -public class RestOpenApiComponentV3Test extends CamelTestSupport { +public class RestOpenApiComponentV3Test extends ManagedCamelTestSupport { public static WireMockServer petstore = new WireMockServer(wireMockConfig().dynamicPort()); static final Object NO_BODY = null; - public String componentName; - @BeforeAll public static void startWireMockServer() { petstore.start(); @@ -73,24 +71,15 @@ public class RestOpenApiComponentV3Test extends CamelTestSupport { petstore.stop(); } - @Override - public void setUp() { - } - @BeforeEach public void resetWireMock() { petstore.resetRequests(); } - public void doSetUp(String componentName) throws Exception { - this.componentName = componentName; - super.setUp(); - } - @ParameterizedTest @MethodSource("knownProducers") public void shouldBeAddingPets(String componentName) throws Exception { - doSetUp(componentName); + initializeContextForComponent(componentName); final Pet pet = new Pet(); pet.setName("Jean-Luc Picard"); @@ -109,7 +98,7 @@ public class RestOpenApiComponentV3Test extends CamelTestSupport { @ParameterizedTest @MethodSource("knownProducers") public void shouldBeGettingPetsById(String componentName) throws Exception { - doSetUp(componentName); + initializeContextForComponent(componentName); final Pet pet = template.requestBodyAndHeader("direct:getPetById", NO_BODY, "petId", 14, Pet.class); @@ -125,7 +114,7 @@ public class RestOpenApiComponentV3Test extends CamelTestSupport { @ParameterizedTest @MethodSource("knownProducers") public void shouldBeGettingPetsByIdSpecifiedInEndpointParameters(String componentName) throws Exception { - doSetUp(componentName); + initializeContextForComponent(componentName); final Pet pet = template.requestBody("direct:getPetByIdWithEndpointParams", NO_BODY, Pet.class); @@ -141,7 +130,7 @@ public class RestOpenApiComponentV3Test extends CamelTestSupport { @ParameterizedTest @MethodSource("knownProducers") public void shouldBeGettingPetsByIdWithApiKeysInHeader(String componentName) throws Exception { - doSetUp(componentName); + initializeContextForComponent(componentName); final Map<String, Object> headers = new HashMap<>(); headers.put("petId", 14); @@ -161,7 +150,7 @@ public class RestOpenApiComponentV3Test extends CamelTestSupport { @ParameterizedTest @MethodSource("knownProducers") public void shouldBeGettingPetsByIdWithApiKeysInQueryParameter(String componentName) throws Exception { - doSetUp(componentName); + initializeContextForComponent(componentName); final Map<String, Object> headers = new HashMap<>(); headers.put("petId", 14); @@ -180,7 +169,7 @@ public class RestOpenApiComponentV3Test extends CamelTestSupport { @ParameterizedTest @MethodSource("knownProducers") public void shouldBeGettingPetsByStatus(String componentName) throws Exception { - doSetUp(componentName); + initializeContextForComponent(componentName); final Pets pets = template.requestBodyAndHeader("direct:findPetsByStatus", NO_BODY, "status", "available", Pets.class); @@ -195,8 +184,8 @@ public class RestOpenApiComponentV3Test extends CamelTestSupport { } @Override - protected CamelContext createCamelContext() throws Exception { - final CamelContext camelContext = super.createCamelContext(); + protected CamelContext createCamelContext(String componentName) { + final CamelContext camelContext = new DefaultCamelContext(); final RestOpenApiComponent component = new RestOpenApiComponent(); component.setComponentName(componentName); diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentV3YamlTest.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentV3YamlTest.java index 38e9537907d..f81710dde5e 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentV3YamlTest.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentV3YamlTest.java @@ -35,7 +35,7 @@ import org.apache.camel.RoutesBuilder; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.rest.RestEndpoint; import org.apache.camel.converter.jaxb.JaxbDataFormat; -import org.apache.camel.test.junit5.CamelTestSupport; +import org.apache.camel.impl.DefaultCamelContext; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -54,14 +54,12 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMoc import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -public class RestOpenApiComponentV3YamlTest extends CamelTestSupport { +public class RestOpenApiComponentV3YamlTest extends ManagedCamelTestSupport { public static WireMockServer petstore = new WireMockServer(wireMockConfig().dynamicPort()); static final Object NO_BODY = null; - public String componentName; - @BeforeAll public static void startWireMockServer() { petstore.start(); @@ -72,24 +70,16 @@ public class RestOpenApiComponentV3YamlTest extends CamelTestSupport { petstore.stop(); } - @Override - public void setUp() { - } - @BeforeEach public void resetWireMock() { petstore.resetRequests(); - } - public void doSetUp(String componentName) throws Exception { - this.componentName = componentName; - super.setUp(); } @ParameterizedTest @MethodSource("knownProducers") public void shouldBeAddingPets(String componentName) throws Exception { - doSetUp(componentName); + initializeContextForComponent(componentName); final Pet pet = new Pet(); pet.setName("Jean-Luc Picard"); @@ -108,7 +98,7 @@ public class RestOpenApiComponentV3YamlTest extends CamelTestSupport { @ParameterizedTest @MethodSource("knownProducers") public void shouldBeGettingPetsById(String componentName) throws Exception { - doSetUp(componentName); + initializeContextForComponent(componentName); final Pet pet = template.requestBodyAndHeader("direct:getPetById", NO_BODY, "petId", 14, Pet.class); @@ -124,7 +114,7 @@ public class RestOpenApiComponentV3YamlTest extends CamelTestSupport { @ParameterizedTest @MethodSource("knownProducers") public void shouldBeGettingPetsByIdSpecifiedInEndpointParameters(String componentName) throws Exception { - doSetUp(componentName); + initializeContextForComponent(componentName); final Pet pet = template.requestBody("direct:getPetByIdWithEndpointParams", NO_BODY, Pet.class); @@ -140,7 +130,7 @@ public class RestOpenApiComponentV3YamlTest extends CamelTestSupport { @ParameterizedTest @MethodSource("knownProducers") public void shouldBeGettingPetsByIdWithApiKeysInHeader(String componentName) throws Exception { - doSetUp(componentName); + initializeContextForComponent(componentName); final Map<String, Object> headers = new HashMap<>(); headers.put("petId", 14); @@ -160,7 +150,7 @@ public class RestOpenApiComponentV3YamlTest extends CamelTestSupport { @ParameterizedTest @MethodSource("knownProducers") public void shouldBeGettingPetsByIdWithApiKeysInQueryParameter(String componentName) throws Exception { - doSetUp(componentName); + initializeContextForComponent(componentName); final Map<String, Object> headers = new HashMap<>(); headers.put("petId", 14); @@ -179,7 +169,7 @@ public class RestOpenApiComponentV3YamlTest extends CamelTestSupport { @ParameterizedTest @MethodSource("knownProducers") public void shouldBeGettingPetsByStatus(String componentName) throws Exception { - doSetUp(componentName); + initializeContextForComponent(componentName); final Pets pets = template.requestBodyAndHeader("direct:findPetsByStatus", NO_BODY, "status", "available", Pets.class); @@ -194,8 +184,8 @@ public class RestOpenApiComponentV3YamlTest extends CamelTestSupport { } @Override - protected CamelContext createCamelContext() throws Exception { - final CamelContext camelContext = super.createCamelContext(); + protected CamelContext createCamelContext(String componentName) { + final CamelContext camelContext = new DefaultCamelContext(); final RestOpenApiComponent component = new RestOpenApiComponent(); component.setComponentName(componentName); diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiDelegateHttpsV3Test.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiDelegateHttpsV3Test.java index 8ae8329e620..6395721e6be 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiDelegateHttpsV3Test.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiDelegateHttpsV3Test.java @@ -24,22 +24,31 @@ import org.apache.camel.support.PropertyBindingSupport; public class RestOpenApiDelegateHttpsV3Test extends HttpsV3Test { @Override - protected CamelContext createCamelContext() throws Exception { - final CamelContext camelContext = super.createCamelContext(); + protected CamelContext createCamelContext(String componentName) { + final CamelContext camelContext = super.createCamelContext(componentName); // since camel context is not started, then we need to manually initialize the delegate - final Component delegate = PluginHelper.getComponentResolver(camelContext) - .resolveComponent(componentName, camelContext); + final Component delegate; + try { + delegate = PluginHelper.getComponentResolver(camelContext) + .resolveComponent(componentName, camelContext); + } catch (Exception e) { + throw new RuntimeException(e); + } delegate.setCamelContext(camelContext); delegate.init(); // and configure the ssl context parameters via binding - new PropertyBindingSupport.Builder() - .withCamelContext(camelContext) - .withProperty("sslContextParameters", createHttpsParameters(camelContext)) - .withTarget(delegate) - .withConfigurer(delegate.getComponentPropertyConfigurer()) - .bind(); + try { + new PropertyBindingSupport.Builder() + .withCamelContext(camelContext) + .withProperty("sslContextParameters", createHttpsParameters(camelContext)) + .withTarget(delegate) + .withConfigurer(delegate.getComponentPropertyConfigurer()) + .bind(); + } catch (Exception e) { + throw new RuntimeException(e); + } camelContext.addComponent(componentName, delegate); return camelContext; diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiGlobalHttpsV31Test.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiGlobalHttpsV31Test.java index 50acc2d2213..40cb76bcf5c 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiGlobalHttpsV31Test.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiGlobalHttpsV31Test.java @@ -43,9 +43,13 @@ public class RestOpenApiGlobalHttpsV31Test extends HttpsV3Test { } @Override - protected CamelContext createCamelContext() throws Exception { - CamelContext camelContext = super.createCamelContext(); - camelContext.setSSLContextParameters(createHttpsParameters(camelContext)); + protected CamelContext createCamelContext(String componentName) { + CamelContext camelContext = super.createCamelContext(componentName); + try { + camelContext.setSSLContextParameters(createHttpsParameters(camelContext)); + } catch (Exception e) { + throw new RuntimeException(e); + } RestOpenApiComponent component = camelContext.getComponent("petStore", RestOpenApiComponent.class); component.setUseGlobalSslContextParameters(true); diff --git a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiGlobalHttpsV3Test.java b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiGlobalHttpsV3Test.java index a43a27b58cc..c8b60e1c77f 100644 --- a/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiGlobalHttpsV3Test.java +++ b/components/camel-rest-openapi/src/test/java/org/apache/camel/component/rest/openapi/RestOpenApiGlobalHttpsV3Test.java @@ -21,9 +21,13 @@ import org.apache.camel.CamelContext; public class RestOpenApiGlobalHttpsV3Test extends HttpsV3Test { @Override - protected CamelContext createCamelContext() throws Exception { - CamelContext camelContext = super.createCamelContext(); - camelContext.setSSLContextParameters(createHttpsParameters(camelContext)); + protected CamelContext createCamelContext(String componentName) { + CamelContext camelContext = super.createCamelContext(componentName); + try { + camelContext.setSSLContextParameters(createHttpsParameters(camelContext)); + } catch (Exception e) { + throw new RuntimeException(e); + } RestOpenApiComponent component = camelContext.getComponent("petStore", RestOpenApiComponent.class); component.setUseGlobalSslContextParameters(true); diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java index 74cfdabfe62..ee15babf0b2 100644 --- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java +++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java @@ -174,7 +174,7 @@ public abstract class CamelTestSupport extends AbstractTestSupport */ @Deprecated(since = "4.7.0") @BeforeEach - public void setUp() throws Exception { + public final void setUp() throws Exception { unsupportedCheck(); setupResources(); @@ -258,7 +258,7 @@ public abstract class CamelTestSupport extends AbstractTestSupport */ @Deprecated(since = "4.7.0") @AfterEach - public void tearDown() throws Exception { + public final void tearDown() throws Exception { long time = watch.taken(); contextManager.dumpRouteCoverage(getClass(), currentTestName, time); diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ExchangeTestSupport.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ExchangeTestSupport.java index 14727c190cc..ecf85e5d42d 100644 --- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ExchangeTestSupport.java +++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/ExchangeTestSupport.java @@ -48,8 +48,7 @@ public abstract class ExchangeTestSupport extends CamelTestSupport { @Override @BeforeEach - public void setUp() throws Exception { - super.setUp(); + public void doPostSetup() throws Exception { exchange = createExchange(); assertNotNull(exchange, "No exchange created!"); populateExchange(exchange); diff --git a/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupportTest.java b/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupportTest.java index 2d11070c6d2..d1e935306b8 100644 --- a/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupportTest.java +++ b/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/CamelTestSupportTest.java @@ -19,7 +19,6 @@ package org.apache.camel.test.junit5; import org.apache.camel.NoSuchEndpointException; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -28,10 +27,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows; public class CamelTestSupportTest extends CamelTestSupport { @Override - @BeforeEach - public void setUp() throws Exception { + public void doPreSetup() throws Exception { replaceRouteFromWith("routeId", "direct:start"); - super.setUp(); } @Test diff --git a/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/RouteBuilderConfigureExceptionTest.java b/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/RouteBuilderConfigureExceptionTest.java deleted file mode 100644 index d1ab53b287d..00000000000 --- a/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/RouteBuilderConfigureExceptionTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.test.junit5.patterns; - -import org.apache.camel.Predicate; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.fail; - -public class RouteBuilderConfigureExceptionTest extends CamelTestSupport { - - private Predicate iAmNull; - - @Override - @BeforeEach - public void setUp() { - try { - super.setUp(); - fail("Should have thrown exception"); - } catch (Exception e) { - // expected - } - } - - @Test - public void testFoo() { - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() { - from("direct:start").choice().when(iAmNull).to("mock:dead"); - } - }; - } -} diff --git a/components/camel-test/camel-test-main-junit5/src/test/java/org/apache/camel/test/main/junit5/legacy/ReplaceRouteFromTest.java b/components/camel-test/camel-test-main-junit5/src/test/java/org/apache/camel/test/main/junit5/legacy/ReplaceRouteFromTest.java index 14ec3651903..9ac6baba8c0 100644 --- a/components/camel-test/camel-test-main-junit5/src/test/java/org/apache/camel/test/main/junit5/legacy/ReplaceRouteFromTest.java +++ b/components/camel-test/camel-test-main-junit5/src/test/java/org/apache/camel/test/main/junit5/legacy/ReplaceRouteFromTest.java @@ -21,7 +21,6 @@ import org.apache.camel.main.MainConfigurationProperties; import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.camel.test.main.junit5.CamelMainTestSupport; import org.apache.camel.test.main.junit5.common.MyConfiguration; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -33,10 +32,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; class ReplaceRouteFromTest extends CamelMainTestSupport { @Override - @BeforeEach - public void setUp() throws Exception { + public void doPreSetup() { replaceRouteFromWith("foo", "direct:foo"); - super.setUp(); } @Override diff --git a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringTestSupport.java b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringTestSupport.java index 4efa07ce4e9..50e2bffcf6a 100644 --- a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringTestSupport.java +++ b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringTestSupport.java @@ -41,7 +41,6 @@ import org.apache.camel.test.junit5.CamelTestSupport; import org.apache.camel.test.junit5.util.CamelContextTestHelper; import org.apache.camel.util.IOHelper; import org.apache.camel.util.ObjectHelper; -import org.junit.jupiter.api.AfterEach; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; @@ -77,7 +76,7 @@ public abstract class CamelSpringTestSupport extends CamelTestSupport { protected abstract AbstractApplicationContext createApplicationContext(); @Override - public void postProcessTest() throws Exception { + protected final void postProcessTest() throws Exception { if (testConfiguration().isCreateCamelContextPerClass()) { applicationContext = THREAD_APP_CONTEXT.get(); } @@ -85,7 +84,7 @@ public abstract class CamelSpringTestSupport extends CamelTestSupport { } @Override - public void doPreSetup() throws Exception { + protected final void doPreSetup() throws Exception { boolean skip = CamelContextTestHelper.isSkipAutoStartContext(testConfiguration()); if (!skip) { // tell camel-spring it should not trigger starting CamelContext, since we do that later @@ -134,18 +133,12 @@ public abstract class CamelSpringTestSupport extends CamelTestSupport { } @Override - @AfterEach - public void tearDown() throws Exception { - super.tearDown(); - + public void doPostTearDown() throws Exception { if (!testConfiguration().isCreateCamelContextPerClass()) { IOHelper.close(applicationContext); applicationContext = null; } - } - @Override - public void doPostTearDown() throws Exception { if (THREAD_APP_CONTEXT.get() != null) { IOHelper.close(THREAD_APP_CONTEXT.get()); THREAD_APP_CONTEXT.remove(); diff --git a/components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/patterns/DebugSpringTest.java b/components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/patterns/DebugSpringTest.java index ebaa82a7eb6..1d90190f9c2 100644 --- a/components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/patterns/DebugSpringTest.java +++ b/components/camel-test/camel-test-spring-junit5/src/test/java/org/apache/camel/test/patterns/DebugSpringTest.java @@ -37,9 +37,7 @@ public class DebugSpringTest extends CamelSpringTestSupport { private boolean debugged; @Override - public void doPreSetup() throws Exception { - super.doPreSetup(); - + public void setupResources() throws Exception { camelContextConfiguration() .withBreakpoint(createBreakpoint()); } diff --git a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/integration/SpringZooKeeperServiceCallRouteIT.java b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/integration/SpringZooKeeperServiceCallRouteIT.java index 3469709cc72..a3178513385 100644 --- a/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/integration/SpringZooKeeperServiceCallRouteIT.java +++ b/components/camel-zookeeper/src/test/java/org/apache/camel/component/zookeeper/cloud/integration/SpringZooKeeperServiceCallRouteIT.java @@ -63,9 +63,7 @@ public class SpringZooKeeperServiceCallRouteIT extends CamelSpringTestSupport { } @Override - public void doPreSetup() throws Exception { - super.doPreSetup(); - + public void setupResources() throws Exception { function = new AvailablePortFinderPropertiesFunction(); curator = CuratorFrameworkFactory.builder() diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_8.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_8.adoc index 367e1bb595a..9c2b10d44a2 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_8.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_8.adoc @@ -11,3 +11,8 @@ from both 4.0 to 4.1 and 4.1 to 4.2. The `KafkaIdempotentRepository` will now continue to sync cache updates after Camel has been started. You can configure `startupOnly=true` to only sync the cache once on startup (however then the cache is not synced with other Camel nodes in a cluster). + +=== camel-tests + +Continuing the multi-release tests cleanups, on this one, restricted methods from the `CamelTestSupport` class +have been marked as final and cannot be extended.