This is an automated email from the ASF dual-hosted git repository. davsclaus 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 070ab951725 Stub (#17192) 070ab951725 is described below commit 070ab951725a7a0980c590b51031b80d127d28bc Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Feb 19 10:08:41 2025 +0000 Stub (#17192) * Polished * CAMEL-21759: camel-test - Add @StubEndpoints to make it easy to test and replace out components like kafka --- .../camel/test/junit5/AbstractTestSupport.java | 13 ++++ .../test/junit5/CamelContextConfiguration.java | 17 +++++ .../apache/camel/test/junit5/CamelTestSupport.java | 3 +- .../test/junit5/LegacyCamelContextManager.java | 3 + .../test/junit5/StubComponentAutowireStrategy.java | 89 ++++++++++++++++++++++ .../camel/test/junit5/StubComponentResolver.java | 39 ++++++++++ .../test/junit5/TransientCamelContextManager.java | 3 + .../test/junit5/util/CamelContextTestHelper.java | 25 ++++++ .../test/junit5/patterns/IsStubEndpointsTest.java | 52 +++++++++++++ .../src/main/docs/test-spring-junit5.adoc | 1 + .../spring/junit5/CamelAnnotationsHandler.java | 33 ++++++++ .../junit5/CamelSpringBootExecutionListener.java | 1 + .../junit5/CamelSpringTestContextLoader.java | 1 + .../camel/test/spring/junit5/ExcludeRoutes.java | 2 +- .../{ExcludeRoutes.java => StubEndpoints.java} | 13 +--- 15 files changed, 284 insertions(+), 11 deletions(-) diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/AbstractTestSupport.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/AbstractTestSupport.java index bc7dc2a391d..8e5a9bea8d9 100644 --- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/AbstractTestSupport.java +++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/AbstractTestSupport.java @@ -176,6 +176,19 @@ public abstract class AbstractTestSupport implements CommonTestSupport { return camelContextConfiguration().mockEndpointsAndSkip(); } + /** + * Override to enable auto stub endpoints based on the pattern. + * <p/> + * Return <tt>*</tt> to mock all endpoints. + * + * @see EndpointHelper#matchEndpoint(CamelContext, String, String) + * @deprecated Use the accessors from {@link #camelContextConfiguration()} method + */ + @Deprecated(since = "4.11.0") + public String isStubEndpoints() { + return camelContextConfiguration().stubEndpoints(); + } + /** * To replace from routes * diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelContextConfiguration.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelContextConfiguration.java index d80da3554b8..eeab6e99b3e 100644 --- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelContextConfiguration.java +++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelContextConfiguration.java @@ -59,6 +59,7 @@ public class CamelContextConfiguration { private Breakpoint breakpoint; private String mockEndpoints; private String mockEndpointsAndSkip; + private String stubEndpoints; private Properties useOverridePropertiesWithPropertiesComponent; private Boolean ignoreMissingLocationWithPropertiesComponent; @@ -185,6 +186,22 @@ public class CamelContextConfiguration { return this; } + public String stubEndpoints() { + return stubEndpoints; + } + + /** + * Enables auto stub endpoints based on the pattern. + * <p/> + * Use <tt>*</tt> to stub all endpoints. + * + * @see EndpointHelper#matchEndpoint(CamelContext, String, String) + */ + public CamelContextConfiguration withStubEndpoints(String pattern) { + this.stubEndpoints = pattern; + return this; + } + public Properties useOverridePropertiesWithPropertiesComponent() { return useOverridePropertiesWithPropertiesComponent; } 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 6b93ab1a550..147feb3691b 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 @@ -88,7 +88,8 @@ public abstract class CamelTestSupport extends AbstractTestSupport .withRouteFilterExcludePattern(getRouteFilterExcludePattern()) .withRouteFilterIncludePattern(getRouteFilterIncludePattern()) .withMockEndpoints(isMockEndpoints()) - .withMockEndpointsAndSkip(isMockEndpointsAndSkip()); + .withMockEndpointsAndSkip(isMockEndpointsAndSkip()) + .withStubEndpoints(isStubEndpoints()); } @Override diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/LegacyCamelContextManager.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/LegacyCamelContextManager.java index c1d06cfa661..ee3d8b382a4 100644 --- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/LegacyCamelContextManager.java +++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/LegacyCamelContextManager.java @@ -140,6 +140,9 @@ public class LegacyCamelContextManager implements CamelContextManager { final String mockPattern = camelContextConfiguration.mockEndpoints(); final String mockAndSkipPattern = camelContextConfiguration.mockEndpointsAndSkip(); CamelContextTestHelper.enableAutoMocking(context, mockPattern, mockAndSkipPattern); + // enable auto stub if enabled + final String stubPattern = camelContextConfiguration.stubEndpoints(); + CamelContextTestHelper.enableAutoStub(context, stubPattern); // configure properties component (mandatory for testing) configurePropertiesComponent(); diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/StubComponentAutowireStrategy.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/StubComponentAutowireStrategy.java new file mode 100644 index 00000000000..58bc94904f6 --- /dev/null +++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/StubComponentAutowireStrategy.java @@ -0,0 +1,89 @@ +/* + * 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; + +import org.apache.camel.CamelContext; +import org.apache.camel.Component; +import org.apache.camel.Ordered; +import org.apache.camel.spi.AutowiredLifecycleStrategy; +import org.apache.camel.spi.DataFormat; +import org.apache.camel.spi.Language; +import org.apache.camel.support.LifecycleStrategySupport; + +public class StubComponentAutowireStrategy extends LifecycleStrategySupport implements AutowiredLifecycleStrategy, Ordered { + private final CamelContext camelContext; + private final String pattern; + + public StubComponentAutowireStrategy(CamelContext camelContext, String pattern) { + this.camelContext = camelContext; + this.pattern = pattern; + } + + @Override + public int getOrder() { + // we should be last + return Ordered.LOWEST; + } + + @Override + public void onComponentAdd(String name, Component component) { + autowireComponent(name, component); + } + + @Override + public void onDataFormatCreated(String name, DataFormat dataFormat) { + autowireDataFormat(name, dataFormat); + } + + @Override + public void onLanguageCreated(String name, Language language) { + autowireLanguage(name, language); + } + + private void autowireComponent(String name, Component component) { + // autowiring can be turned off on context level and per component + boolean enabled = camelContext.isAutowiredEnabled() && component.isAutowiredEnabled(); + if (enabled) { + autowire(name, "component", component); + } + } + + private void autowireDataFormat(String name, DataFormat dataFormat) { + // autowiring can be turned off on context level + boolean enabled = camelContext.isAutowiredEnabled(); + if (enabled) { + autowire(name, "dataformat", dataFormat); + } + } + + private void autowireLanguage(String name, Language language) { + // autowiring can be turned off on context level + boolean enabled = camelContext.isAutowiredEnabled(); + if (enabled) { + autowire(name, "language", language); + } + } + + private void autowire(String name, String kind, Object target) { + if (pattern.contains(name)) { + // do not autowire + } else { + doAutoWire(name, kind, target, camelContext); + } + } + +} diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/StubComponentResolver.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/StubComponentResolver.java new file mode 100644 index 00000000000..09436224662 --- /dev/null +++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/StubComponentResolver.java @@ -0,0 +1,39 @@ +/* + * 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; + +import org.apache.camel.CamelContext; +import org.apache.camel.Component; +import org.apache.camel.impl.engine.DefaultComponentResolver; + +public class StubComponentResolver extends DefaultComponentResolver { + + private final String pattern; + + public StubComponentResolver(String pattern) { + this.pattern = pattern; + } + + @Override + public Component resolveComponent(String name, CamelContext context) { + if (pattern.contains(name)) { + return super.resolveComponent("stub", context); + } else { + return super.resolveComponent(name, context); + } + } +} diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TransientCamelContextManager.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TransientCamelContextManager.java index c63cbd241b5..7ded6c393db 100644 --- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TransientCamelContextManager.java +++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/TransientCamelContextManager.java @@ -108,6 +108,9 @@ public class TransientCamelContextManager implements CamelContextManager { final String mockPattern = camelContextConfiguration.mockEndpoints(); final String mockAndSkipPattern = camelContextConfiguration.mockEndpointsAndSkip(); CamelContextTestHelper.enableAutoMocking(context, mockPattern, mockAndSkipPattern); + // enable auto stub if enabled + final String stubPattern = camelContextConfiguration.stubEndpoints(); + CamelContextTestHelper.enableAutoStub(context, stubPattern); // configure properties component (mandatory for testing) configurePropertiesComponent(); diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelContextTestHelper.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelContextTestHelper.java index db387bb98a4..7606f36eab1 100644 --- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelContextTestHelper.java +++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/util/CamelContextTestHelper.java @@ -29,14 +29,18 @@ import org.apache.camel.builder.AdviceWith; import org.apache.camel.builder.AdviceWithRouteBuilder; import org.apache.camel.component.mock.InterceptSendToMockEndpointStrategy; import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.component.stub.StubComponent; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.impl.debugger.DefaultDebugger; import org.apache.camel.model.Model; import org.apache.camel.model.ModelCamelContext; import org.apache.camel.spi.Breakpoint; +import org.apache.camel.spi.ComponentResolver; import org.apache.camel.spi.PropertiesComponent; import org.apache.camel.spi.PropertiesSource; import org.apache.camel.spi.Registry; +import org.apache.camel.test.junit5.StubComponentAutowireStrategy; +import org.apache.camel.test.junit5.StubComponentResolver; import org.apache.camel.test.junit5.TestExecutionConfiguration; import org.apache.camel.test.junit5.TestSupport; import org.slf4j.Logger; @@ -162,6 +166,27 @@ public final class CamelContextTestHelper { } } + /** + * Enables auto stub + */ + public static void enableAutoStub(CamelContext context, String pattern) { + if (pattern != null) { + StubComponent stub = context.getComponent("stub", StubComponent.class); + // enable shadow mode on stub component + stub.setShadow(true); + stub.setShadowPattern(pattern); + // should not autowire + stub.setAutowiredEnabled(false); + // and use a specialized component resolver + context.getCamelContextExtension().addContextPlugin(ComponentResolver.class, + new StubComponentResolver(pattern)); + // need to replace autowire strategy with stub capable + context.getLifecycleStrategies() + .removeIf(s -> s.getClass().getSimpleName().equals("DefaultAutowiredLifecycleStrategy")); + context.getLifecycleStrategies().add(new StubComponentAutowireStrategy(context, pattern)); + } + } + /** * Configure the PropertiesComponent from the given context * diff --git a/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/IsStubEndpointsTest.java b/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/IsStubEndpointsTest.java new file mode 100644 index 00000000000..74fd0bd3195 --- /dev/null +++ b/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/IsStubEndpointsTest.java @@ -0,0 +1,52 @@ +/* + * 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.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +public class IsStubEndpointsTest extends CamelTestSupport { + + @Override + public String isStubEndpoints() { + return "kafka,amqp"; + } + + @Test + public void testStubEndpoints() throws Exception { + getMockEndpoint("mock:middle").expectedBodiesReceived("World"); + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + + template.sendBody("direct:start", "World"); + + MockEndpoint.assertIsSatisfied(context); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + @Override + public void configure() { + from("direct:start").to("amqp:cheese"); + from("amqp:cheese").to("mock:middle").transform(simple("Bye ${body}")).to("kafka:beer"); + from("kafka:beer").to("mock:result"); + } + }; + } +} diff --git a/components/camel-test/camel-test-spring-junit5/src/main/docs/test-spring-junit5.adoc b/components/camel-test/camel-test-spring-junit5/src/main/docs/test-spring-junit5.adoc index 67e7c1a8ce0..0d30b4720d5 100644 --- a/components/camel-test/camel-test-spring-junit5/src/main/docs/test-spring-junit5.adoc +++ b/components/camel-test/camel-test-spring-junit5/src/main/docs/test-spring-junit5.adoc @@ -212,6 +212,7 @@ The following annotations can be used with `camel-spring-junit5` unit testing. | `@ShutdownTimeout` | Timeout to use for xref:manual::graceful-shutdown.adoc[shutdown]. The default is 10 seconds. | `@UseAdviceWith` | To enable testing with xref:manual::advice-with.adoc[Advice With]. | `@UseOverridePropertiesWithPropertiesComponent` | To use custom `Properties` with the xref:ROOT:properties-component.adoc[Properties] component. The annotated method must be `public` and return `Properties`. +| `@StubEndpoints` | To auto-stub of endpoints whose URIs match the provided filter. |======================================================================= diff --git a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelAnnotationsHandler.java b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelAnnotationsHandler.java index 255055a2d72..5527e6b6cd9 100644 --- a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelAnnotationsHandler.java +++ b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelAnnotationsHandler.java @@ -29,14 +29,18 @@ import java.util.function.Function; import org.apache.camel.api.management.ManagedCamelContext; import org.apache.camel.api.management.mbean.ManagedCamelContextMBean; import org.apache.camel.component.mock.InterceptSendToMockEndpointStrategy; +import org.apache.camel.component.stub.StubComponent; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.impl.debugger.DefaultDebugger; import org.apache.camel.spi.Breakpoint; +import org.apache.camel.spi.ComponentResolver; import org.apache.camel.spi.Debugger; import org.apache.camel.spi.DumpRoutesStrategy; import org.apache.camel.spi.EventNotifier; import org.apache.camel.spi.PropertiesComponent; import org.apache.camel.spring.SpringCamelContext; +import org.apache.camel.test.junit5.StubComponentAutowireStrategy; +import org.apache.camel.test.junit5.StubComponentResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.BeanPostProcessor; @@ -347,6 +351,35 @@ public final class CamelAnnotationsHandler { } } + /** + * Handles auto-stub of endpoints with mocks based on {@link StubEndpoints}. + * + * @param context the initialized Spring context + * @param testClass the test class being executed + */ + public static void handleStubEndpoints(ConfigurableApplicationContext context, Class<?> testClass) throws Exception { + if (testClass.isAnnotationPresent(StubEndpoints.class)) { + final String stubEndpoints = testClass.getAnnotation(StubEndpoints.class).value(); + CamelSpringTestHelper.doToSpringCamelContexts(context, (contextName, camelContext) -> { + LOGGER.info("Enabling auto stub of endpoints matching pattern [{}] on CamelContext with name [{}].", + stubEndpoints, contextName); + StubComponent stub = camelContext.getComponent("stub", StubComponent.class); + // enable shadow mode on stub component + stub.setShadow(true); + stub.setShadowPattern(stubEndpoints); + // should not autowire + stub.setAutowiredEnabled(false); + // and use a specialized component resolver + camelContext.getCamelContextExtension().addContextPlugin(ComponentResolver.class, + new StubComponentResolver(stubEndpoints)); + // need to replace autowire strategy with stub capable + camelContext.getLifecycleStrategies() + .removeIf(s -> s.getClass().getSimpleName().equals("DefaultAutowiredLifecycleStrategy")); + camelContext.getLifecycleStrategies().add(new StubComponentAutowireStrategy(camelContext, stubEndpoints)); + }); + } + } + /** * Handles auto-intercepting of endpoints with mocks based on {@link MockEndpointsAndSkip} and skipping the original * endpoint. diff --git a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootExecutionListener.java b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootExecutionListener.java index 45f22420d41..321475f432c 100644 --- a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootExecutionListener.java +++ b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringBootExecutionListener.java @@ -67,6 +67,7 @@ public class CamelSpringBootExecutionListener extends AbstractTestExecutionListe CamelAnnotationsHandler.handleShutdownTimeout(context, testClass); CamelAnnotationsHandler.handleMockEndpoints(context, testClass); CamelAnnotationsHandler.handleMockEndpointsAndSkip(context, testClass); + CamelAnnotationsHandler.handleStubEndpoints(context, testClass); System.clearProperty(PROPERTY_SKIP_STARTING_CAMEL_CONTEXT); SpringCamelContext.setNoStart(false); diff --git a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringTestContextLoader.java b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringTestContextLoader.java index 52a386212d3..93de5058e19 100644 --- a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringTestContextLoader.java +++ b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/CamelSpringTestContextLoader.java @@ -151,6 +151,7 @@ public class CamelSpringTestContextLoader extends AbstractContextLoader { CamelAnnotationsHandler.handleShutdownTimeout(context, testClass); CamelAnnotationsHandler.handleMockEndpoints(context, testClass); CamelAnnotationsHandler.handleMockEndpointsAndSkip(context, testClass); + CamelAnnotationsHandler.handleStubEndpoints(context, testClass); // CamelContext(s) startup CamelAnnotationsHandler.handleCamelContextStartup(context, testClass); diff --git a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/ExcludeRoutes.java b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/ExcludeRoutes.java index 69916e47e94..eb6ccc4d8f9 100644 --- a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/ExcludeRoutes.java +++ b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/ExcludeRoutes.java @@ -28,7 +28,7 @@ import org.apache.camel.RoutesBuilder; /** * Indicates if certain route builder classes should be excluded from discovery. Initializes a * {@link org.apache.camel.spi.PackageScanClassResolver} to exclude a set of given classes from being resolved. - * Typically this is used at test time to exclude certain routes, which might otherwise be noisy, from being discovered + * Typically, this is used at test time to exclude certain routes, which might otherwise be noisy, from being discovered * and initialized. */ @Documented diff --git a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/ExcludeRoutes.java b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/StubEndpoints.java similarity index 68% copy from components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/ExcludeRoutes.java copy to components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/StubEndpoints.java index 69916e47e94..c7d93ff2bd2 100644 --- a/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/ExcludeRoutes.java +++ b/components/camel-test/camel-test-spring-junit5/src/main/java/org/apache/camel/test/spring/junit5/StubEndpoints.java @@ -23,22 +23,17 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.apache.camel.RoutesBuilder; - /** - * Indicates if certain route builder classes should be excluded from discovery. Initializes a - * {@link org.apache.camel.spi.PackageScanClassResolver} to exclude a set of given classes from being resolved. - * Typically this is used at test time to exclude certain routes, which might otherwise be noisy, from being discovered - * and initialized. + * Triggers the auto-stub of endpoints whose URIs match the provided filter. */ @Documented @Inherited @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.TYPE }) -public @interface ExcludeRoutes { +public @interface StubEndpoints { /** - * The classes to exclude from resolution when using package scanning. + * The pattern to use for matching endpoints to enable stub on. */ - Class<? extends RoutesBuilder>[] value() default {}; + String value(); }