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 6e8d9e6edae CAMEL-20113: camel/tests consolidating (#12612) 6e8d9e6edae is described below commit 6e8d9e6edae3f4a97771e0e5636b123f47a96f31 Author: Ivan Kulaga <kulagaivanandreev...@gmail.com> AuthorDate: Wed Jan 3 22:35:23 2024 +0600 CAMEL-20113: camel/tests consolidating (#12612) org.apache.camel.itest.jms: -AdviceWithTransactionIssueTest - moved to camel-jms; -DynamicRouteTest - moved to camel-jms; -FileToJmsTest - moved to camel-jms; -JmsConsumerShutdownTest - moved to camel-jms; -JmsIntegrationTest - jms sending to queue and processing with custom bean is checked in others tests, so it is deleted; -JmsMediumQueuePerformanceTest - tests to play with the performance tuning are org.apache.camel.component.jms.tuning.PerformanceRouteTest and PerformanceRoutePojoTest, so this test is deleted; -JmsPerformanceTest - tests to play with the performance tuning are org.apache.camel.component.jms.tuning.PerformanceRouteTest and PerformanceRoutePojoTest, so this test is deleted; -JmsPollingConsumerTest - moved to camel-jms; -JmsPollEnrichTest - moved to camel-jms; -JMSNestedTransactionRollbackTest - moved to camel-jms; -JmsResequencerTest - resequence is checked in other camel-jms tests, so this test is deleted; -JmsValidatorTest - moved to camel-jms; -SpringJmsValidatorTest - moved to camel-jms; --- .../camel/component}/jms/DynamicRouteTest.java | 44 ++++-- .../component}/jms/JmsConsumerShutdownTest.java | 29 ++-- .../jms/JmsEndpointConfigurationTest.java | 2 +- .../camel/component}/jms/JmsPollEnrichTest.java | 38 +++-- .../component}/jms/JmsPollingConsumerTest.java | 42 ++--- .../component/jms/JmsSpringValidatorTest.java | 12 +- .../camel/component}/jms/JmsValidatorTest.java | 49 +++--- .../issues}/AdviceWithTransactionIssueTest.java | 11 +- .../component/jms/issues/FileToJmsIssueTest.java | 27 ++-- .../jms/tx}/JMSNestedTransactionRollbackTest.java | 14 +- .../component/jms/JmsConsumerShutdownTest.xml | 6 +- .../camel/component/jms/JmsPollingConsumerTest.xml | 6 +- .../camel/component/jms/JmsSpringValidatorTest.xml | 6 +- .../camel/component/jms/JmsValidatorTestSchema.xsd | 0 .../jms/issues}/AdviceWithTransactionIssueTest.xml | 8 +- .../component/jms/issues/FileToJmsIssueTest.xml | 4 +- .../jms/tx/JMSNestedTransactionRollbackTest.xml | 6 +- .../apache/camel/itest/jms/JmsIntegrationTest.java | 79 ---------- .../itest/jms/JmsMediumQueuePerformanceTest.java | 25 --- .../apache/camel/itest/jms/JmsPerformanceTest.java | 126 --------------- .../apache/camel/itest/jms/JmsResequencerTest.java | 175 --------------------- 21 files changed, 163 insertions(+), 546 deletions(-) diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/DynamicRouteTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/DynamicRouteTest.java similarity index 75% rename from tests/camel-itest/src/test/java/org/apache/camel/itest/jms/DynamicRouteTest.java rename to components/camel-jms/src/test/java/org/apache/camel/component/jms/DynamicRouteTest.java index 161c6d6500e..f80e7d29297 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/DynamicRouteTest.java +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/DynamicRouteTest.java @@ -14,24 +14,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.itest.jms; +package org.apache.camel.component.jms; +import org.apache.camel.BindToRegistry; import org.apache.camel.Exchange; import org.apache.camel.Header; +import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jms.JmsComponent; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.spi.Registry; -import org.apache.camel.test.junit5.CamelTestSupport; +import org.apache.camel.test.infra.core.CamelContextExtension; +import org.apache.camel.test.infra.core.DefaultCamelContextExtension; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import static org.junit.jupiter.api.Assertions.assertEquals; -public class DynamicRouteTest extends CamelTestSupport { +public class DynamicRouteTest extends AbstractJMSTest { @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); + public static CamelContextExtension camelContextExtension = new DefaultCamelContextExtension(); + @BindToRegistry + private final MyBean myBean = new MyBean(); + private final String componentName = "jms"; + protected ProducerTemplate template; @Test void testDynamicRouteWithJms() { @@ -64,16 +69,6 @@ public class DynamicRouteTest extends CamelTestSupport { }; } - @Override - protected void bindToRegistry(Registry registry) { - // add ActiveMQ with embedded broker - JmsComponent amq = jmsServiceExtension.getComponent(); - - amq.setCamelContext(context); - registry.bind("jms", amq); - registry.bind("myBean", new MyBean()); - } - public static class MyBean { public String foo() { @@ -97,4 +92,19 @@ public class DynamicRouteTest extends CamelTestSupport { } } + @Override + protected String getComponentName() { + return componentName; + } + + @Override + public CamelContextExtension getCamelContextExtension() { + return camelContextExtension; + } + + @BeforeEach + void setUpRequirements() { + template = camelContextExtension.getProducerTemplate(); + } + } diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsConsumerShutdownTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsConsumerShutdownTest.java similarity index 79% rename from tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsConsumerShutdownTest.java rename to components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsConsumerShutdownTest.java index aa2e8599497..0ef443a3454 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsConsumerShutdownTest.java +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsConsumerShutdownTest.java @@ -14,30 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.itest.jms; +package org.apache.camel.component.jms; -import org.apache.camel.CamelContext; import org.apache.camel.EndpointInject; import org.apache.camel.Produce; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jms.issues.CamelBrokerClientTestSupport; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.test.spring.junit5.CamelSpringTest; +import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.support.AbstractApplicationContext; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -@CamelSpringTest -@ContextConfiguration -public class JmsConsumerShutdownTest { - @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); - - @Autowired - CamelContext camelContext; +public class JmsConsumerShutdownTest extends CamelBrokerClientTestSupport { @Produce("jms:start") protected ProducerTemplate activemq; @@ -51,10 +41,15 @@ public class JmsConsumerShutdownTest { @EndpointInject("mock:exception") protected MockEndpoint exception; + @Override + protected AbstractApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/jms/JmsConsumerShutdownTest.xml"); + } + @Test @DirtiesContext void testJmsConsumerShutdownWithMessageInFlight() throws InterruptedException { - camelContext.getShutdownStrategy().setTimeout(3); + context().getShutdownStrategy().setTimeout(3); end.expectedMessageCount(0); end.setResultWaitTime(1000); @@ -73,7 +68,7 @@ public class JmsConsumerShutdownTest { @Test @DirtiesContext void testSedaConsumerShutdownWithMessageInFlight() throws InterruptedException { - camelContext.getShutdownStrategy().setTimeout(3); + context().getShutdownStrategy().setTimeout(3); end.expectedMessageCount(0); end.setResultWaitTime(1000); diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java index 632ed369714..ae63cbe4072 100644 --- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsEndpointConfigurationTest.java @@ -62,7 +62,7 @@ public class JmsEndpointConfigurationTest extends AbstractJMSTest { @Order(2) @RegisterExtension public static CamelContextExtension camelContextExtension = new DefaultCamelContextExtension(); - private static final Logger LOG = LoggerFactory.getLogger(ConsumeJmsMapMessageTest.class); + private static final Logger LOG = LoggerFactory.getLogger(JmsEndpointConfigurationTest.class); @RegisterExtension public ArtemisService service = ArtemisServiceFactory.createVMService(); diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPollEnrichTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollEnrichTest.java similarity index 65% rename from tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPollEnrichTest.java rename to components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollEnrichTest.java index c8bc4ed0f11..329f2e9cf42 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPollEnrichTest.java +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollEnrichTest.java @@ -14,22 +14,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.itest.jms; +package org.apache.camel.component.jms; +import org.apache.camel.CamelContext; +import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jms.JmsComponent; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.spi.Registry; -import org.apache.camel.test.junit5.CamelTestSupport; +import org.apache.camel.test.infra.core.CamelContextExtension; +import org.apache.camel.test.infra.core.DefaultCamelContextExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import static org.apache.camel.test.junit5.TestSupport.deleteDirectory; +public class JmsPollEnrichTest extends AbstractJMSTest { -public class JmsPollEnrichTest extends CamelTestSupport { + @Order(2) @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); + public static CamelContextExtension camelContextExtension = new DefaultCamelContextExtension(); + protected CamelContext context; + protected ProducerTemplate template; @Test void testPollEnrichJms() throws Exception { @@ -55,15 +59,19 @@ public class JmsPollEnrichTest extends CamelTestSupport { } @Override - protected void bindToRegistry(Registry registry) { - deleteDirectory("activemq-data"); - - // add ActiveMQ with embedded broker which must be persistent - JmsComponent amq = jmsServiceExtension.getComponent(); + public CamelContextExtension getCamelContextExtension() { + return camelContextExtension; + } - amq.setCamelContext(context); + @Override + protected String getComponentName() { + return "jms"; + } - registry.bind("jms", amq); + @BeforeEach + void setUpRequirements() { + context = camelContextExtension.getContext(); + template = camelContextExtension.getProducerTemplate(); } } diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPollingConsumerTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java similarity index 69% rename from tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPollingConsumerTest.java rename to components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java index 120c7dfff83..c1ca2cca17b 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPollingConsumerTest.java +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.itest.jms; +package org.apache.camel.component.jms; import org.apache.camel.ConsumerTemplate; import org.apache.camel.EndpointInject; @@ -22,21 +22,15 @@ import org.apache.camel.Exchange; import org.apache.camel.Handler; import org.apache.camel.Produce; import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.jms.issues.CamelBrokerClientTestSupport; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.test.spring.junit5.CamelSpringTest; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.support.ClassPathXmlApplicationContext; -@CamelSpringTest -@ContextConfiguration -public class JmsPollingConsumerTest { - @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); +public class JmsPollingConsumerTest extends CamelBrokerClientTestSupport { @Produce("jms:JmsPollingConsumerTestStartConsumer") protected ProducerTemplate startConsumer; @@ -50,13 +44,17 @@ public class JmsPollingConsumerTest { @EndpointInject("mock:JmsPollingConsumerTestResult") protected MockEndpoint result; + @Override + protected ClassPathXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext( + "/org/apache/camel/component/jms/JmsPollingConsumerTest.xml"); + } + /** - * Fails: Consumer is expected to read two messages from activemq:queue and concatenate their bodies. In this test, + * Consumer is expected to read two messages from activemq:queue and concatenate their bodies. In this test, * consumer bean is invoked from an activemq: route. */ @Test - @DirtiesContext - @Disabled("CAMEL-2305") void testConsumerFromJMSRoute() throws Exception { result.expectedBodiesReceived("foobar"); @@ -73,7 +71,6 @@ public class JmsPollingConsumerTest { * test, consumer bean is invoked from a direct: route. */ @Test - @DirtiesContext void testConsumerFromDirectRoute() throws Exception { result.expectedBodiesReceived("foobar"); @@ -85,13 +82,13 @@ public class JmsPollingConsumerTest { result.assertIsSatisfied(); } - public static class Consumer { + public static class Consumer implements ApplicationContextAware { - @Autowired - protected ConsumerTemplate consumer; + private ApplicationContext applicationContext; @Handler public String consume() { + ConsumerTemplate consumer = applicationContext.getBean(ConsumerTemplate.class); StringBuilder result = new StringBuilder(); Exchange exchange; @@ -102,5 +99,10 @@ public class JmsPollingConsumerTest { return result.toString(); } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } } } diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/SpringJmsValidatorTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSpringValidatorTest.java similarity index 81% rename from tests/camel-itest/src/test/java/org/apache/camel/itest/jms/SpringJmsValidatorTest.java rename to components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSpringValidatorTest.java index 836a297a6eb..07a3c438414 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/SpringJmsValidatorTest.java +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSpringValidatorTest.java @@ -14,23 +14,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.itest.jms; +package org.apache.camel.component.jms; +import org.apache.camel.component.jms.issues.CamelBrokerClientTestSupport; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.test.spring.junit5.CamelSpringTestSupport; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.context.support.AbstractXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; -public class SpringJmsValidatorTest extends CamelSpringTestSupport { - @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); +public class JmsSpringValidatorTest extends CamelBrokerClientTestSupport { @Override protected AbstractXmlApplicationContext createApplicationContext() { - return new ClassPathXmlApplicationContext("org/apache/camel/itest/jms/SpringJmsValidatorTest.xml"); + return new ClassPathXmlApplicationContext("org/apache/camel/component/jms/JmsSpringValidatorTest.xml"); } @Test diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsValidatorTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsValidatorTest.java similarity index 72% rename from tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsValidatorTest.java rename to components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsValidatorTest.java index 8eb59d20a6d..72c2a2d5c94 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsValidatorTest.java +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsValidatorTest.java @@ -14,21 +14,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.itest.jms; +package org.apache.camel.component.jms; +import org.apache.camel.CamelContext; +import org.apache.camel.ProducerTemplate; import org.apache.camel.ValidationException; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jms.JmsComponent; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.spi.Registry; -import org.apache.camel.test.junit5.CamelTestSupport; +import org.apache.camel.test.infra.core.CamelContextExtension; +import org.apache.camel.test.infra.core.DefaultCamelContextExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -public class JmsValidatorTest extends CamelTestSupport { +public class JmsValidatorTest extends AbstractJMSTest { + + @Order(2) @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); + public static CamelContextExtension camelContextExtension = new DefaultCamelContextExtension(); + protected CamelContext context; + protected ProducerTemplate template; @Test void testJmsValidator() throws Exception { @@ -54,16 +60,6 @@ public class JmsValidatorTest extends CamelTestSupport { MockEndpoint.assertIsSatisfied(context); } - @Override - protected void bindToRegistry(Registry registry) { - // add ActiveMQ with embedded broker - JmsComponent amq = jmsServiceExtension.getComponent(); - - amq.setCamelContext(context); - - registry.bind("jms", amq); - } - @Override protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @@ -72,7 +68,7 @@ public class JmsValidatorTest extends CamelTestSupport { from("jms:queue:inbox") .convertBodyTo(String.class) .doTry() - .to("validator:file:src/test/resources/myschema.xsd") + .to("validator:file:src/test/resources/org/apache/camel/component/jms/JmsValidatorTestSchema.xsd") .to("jms:queue:valid") .doCatch(ValidationException.class) .to("jms:queue:invalid") @@ -86,4 +82,21 @@ public class JmsValidatorTest extends CamelTestSupport { } }; } + + @Override + protected String getComponentName() { + return "jms"; + } + + @Override + public CamelContextExtension getCamelContextExtension() { + return camelContextExtension; + } + + @BeforeEach + void setUpRequirements() { + context = camelContextExtension.getContext(); + template = camelContextExtension.getProducerTemplate(); + } + } diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/AdviceWithTransactionIssueTest.java similarity index 84% rename from tests/camel-itest/src/test/java/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.java rename to components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/AdviceWithTransactionIssueTest.java index 82dfb2dc4ef..a2063e79848 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.java +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/AdviceWithTransactionIssueTest.java @@ -14,25 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.itest.jms; +package org.apache.camel.component.jms.issues; import org.apache.camel.builder.AdviceWith; import org.apache.camel.builder.AdviceWithRouteBuilder; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.test.spring.junit5.CamelSpringTestSupport; import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.context.support.AbstractApplicationContext; -public class AdviceWithTransactionIssueTest extends CamelSpringTestSupport { - @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); +public class AdviceWithTransactionIssueTest extends CamelBrokerClientTestSupport { @Override protected AbstractApplicationContext createApplicationContext() { - return new ClassPathXmlApplicationContext("org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.xml"); + return new ClassPathXmlApplicationContext("org/apache/camel/component/jms/issues/AdviceWithTransactionIssueTest.xml"); } @Override diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/FileToJmsTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/FileToJmsIssueTest.java similarity index 67% rename from tests/camel-itest/src/test/java/org/apache/camel/itest/jms/FileToJmsTest.java rename to components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/FileToJmsIssueTest.java index e07e5267687..a720534247c 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/FileToJmsTest.java +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/FileToJmsIssueTest.java @@ -14,30 +14,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.itest.jms; +package org.apache.camel.component.jms.issues; import org.apache.camel.EndpointInject; import org.apache.camel.Exchange; -import org.apache.camel.ProducerTemplate; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.test.spring.junit5.CamelSpringTest; +import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; - -@CamelSpringTest -@ContextConfiguration -public class FileToJmsTest { - @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); - - @Autowired - protected ProducerTemplate template; +import org.springframework.context.support.AbstractApplicationContext; + +public class FileToJmsIssueTest extends CamelBrokerClientTestSupport { + @EndpointInject("mock:result") protected MockEndpoint result; + @Override + protected AbstractApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/jms/issues/FileToJmsIssueTest.xml"); + } + @Test void testFileToJms() throws Exception { result.expectedBodiesReceived("Hello World"); diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JMSNestedTransactionRollbackTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSNestedTransactionRollbackTest.java similarity index 77% rename from tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JMSNestedTransactionRollbackTest.java rename to components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSNestedTransactionRollbackTest.java index 352727a4fb4..ad970d6c335 100644 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JMSNestedTransactionRollbackTest.java +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/JMSNestedTransactionRollbackTest.java @@ -14,29 +14,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.itest.jms; +package org.apache.camel.component.jms.tx; import org.apache.camel.Exchange; import org.apache.camel.Processor; +import org.apache.camel.component.jms.issues.CamelBrokerClientTestSupport; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.test.spring.junit5.CamelSpringTestSupport; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; import org.springframework.context.support.ClassPathXmlApplicationContext; -public class JMSNestedTransactionRollbackTest extends CamelSpringTestSupport { - @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); +public class JMSNestedTransactionRollbackTest extends CamelBrokerClientTestSupport { @Override protected ClassPathXmlApplicationContext createApplicationContext() { return new ClassPathXmlApplicationContext( - "/org/apache/camel/itest/jms/JMSNestedTransactionTest-context.xml"); + "/org/apache/camel/component/jms/tx/JMSNestedTransactionRollbackTest.xml"); } @Test - void testNestedTransactionRolledbackSuccessfully() throws Exception { + void testNestedTransactionRolledackSuccessfully() throws Exception { context.start(); // error handler should catch 1 exception and rollback producer transaction diff --git a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JmsConsumerShutdownTest-context.xml b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/JmsConsumerShutdownTest.xml similarity index 89% rename from tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JmsConsumerShutdownTest-context.xml rename to components/camel-jms/src/test/resources/org/apache/camel/component/jms/JmsConsumerShutdownTest.xml index 9678e053497..dda51809a06 100644 --- a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JmsConsumerShutdownTest-context.xml +++ b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/JmsConsumerShutdownTest.xml @@ -25,7 +25,9 @@ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <bean id="jmsConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory"> - <property name="brokerURL" value="vm://itest-jms?broker.persistent=false&create=false"/> + <property name="brokerURL"> + <bean class="org.apache.camel.component.jms.issues.CamelBrokerClientTestSupport" factory-method="getServiceAddress"/> + </property> </bean> <bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration"> @@ -38,7 +40,7 @@ <property name="configuration" ref="jmsConfig"/> </bean> - <bean id="myRouteBuilder" class="org.apache.camel.itest.jms.JmsConsumerShutdownTest$MyRouteBuilder"/> + <bean id="myRouteBuilder" class="org.apache.camel.component.jms.JmsConsumerShutdownTest$MyRouteBuilder"/> <!-- Set short timeout --> <bean id="shutdownStrategy" class="org.apache.camel.impl.engine.DefaultShutdownStrategy"> diff --git a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JmsPollingConsumerTest-context.xml b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/JmsPollingConsumerTest.xml similarity index 92% rename from tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JmsPollingConsumerTest-context.xml rename to components/camel-jms/src/test/resources/org/apache/camel/component/jms/JmsPollingConsumerTest.xml index b0772d6ae89..322419869ff 100644 --- a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JmsPollingConsumerTest-context.xml +++ b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/JmsPollingConsumerTest.xml @@ -29,7 +29,9 @@ </bean> <bean id="jmsConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory"> - <property name="brokerURL" value="vm://itest-jms?broker.persistent=false&create=false"/> + <property name="brokerURL"> + <bean class="org.apache.camel.component.jms.issues.CamelBrokerClientTestSupport" factory-method="getServiceAddress"/> + </property> </bean> <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager"> @@ -53,7 +55,7 @@ </bean> --> - <bean id="consumer" class="org.apache.camel.itest.jms.JmsPollingConsumerTest$Consumer"/> + <bean id="consumer" class="org.apache.camel.component.jms.JmsPollingConsumerTest$Consumer"/> <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> diff --git a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/SpringJmsValidatorTest.xml b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/JmsSpringValidatorTest.xml similarity index 88% rename from tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/SpringJmsValidatorTest.xml rename to components/camel-jms/src/test/resources/org/apache/camel/component/jms/JmsSpringValidatorTest.xml index ea4baa34f58..5bb8dc6befa 100644 --- a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/SpringJmsValidatorTest.xml +++ b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/JmsSpringValidatorTest.xml @@ -24,7 +24,9 @@ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <bean id="jmsConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory"> - <property name="brokerURL" value="vm://itest-jms?broker.persistent=false&create=false"/> + <property name="brokerURL"> + <bean class="org.apache.camel.component.jms.issues.CamelBrokerClientTestSupport" factory-method="getServiceAddress"/> + </property> </bean> <bean id="jms" class="org.apache.camel.component.jms.JmsComponent"> @@ -37,7 +39,7 @@ <!-- enforce the body as a String to let it be easier to work with --> <convertBodyTo type="String"/> <doTry> - <to uri="validator:file:src/test/resources/myschema.xsd"/> + <to uri="validator:file:src/test/resources/org/apache/camel/component/jms/JmsValidatorTestSchema.xsd"/> <to uri="jms:queue:valid"/> <doCatch> <exception>org.apache.camel.ValidationException</exception> diff --git a/tests/camel-itest/src/test/resources/myschema.xsd b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/JmsValidatorTestSchema.xsd similarity index 100% rename from tests/camel-itest/src/test/resources/myschema.xsd rename to components/camel-jms/src/test/resources/org/apache/camel/component/jms/JmsValidatorTestSchema.xsd diff --git a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.xml b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/AdviceWithTransactionIssueTest.xml similarity index 85% rename from tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.xml rename to components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/AdviceWithTransactionIssueTest.xml index 155851a9800..48512fce6ce 100644 --- a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.xml +++ b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/AdviceWithTransactionIssueTest.xml @@ -20,8 +20,8 @@ <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> +http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd +http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <bean id="poolConnectionFactory" class="org.messaginghub.pooled.jms.JmsPoolConnectionFactory" init-method="start" destroy-method="stop"> <property name="maxConnections" value="8"/> @@ -29,7 +29,9 @@ </bean> <bean id="jmsConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory"> - <property name="brokerURL" value="vm://itest-jms?broker.persistent=false&create=false"/> + <property name="brokerURL"> + <bean class="org.apache.camel.component.jms.issues.CamelBrokerClientTestSupport" factory-method="getServiceAddress"/> + </property> </bean> <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager"> diff --git a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/FileToJmsTest-context.xml b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/FileToJmsIssueTest.xml similarity index 93% rename from tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/FileToJmsTest-context.xml rename to components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/FileToJmsIssueTest.xml index 55da05f873f..0384140e939 100644 --- a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/FileToJmsTest-context.xml +++ b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/FileToJmsIssueTest.xml @@ -29,7 +29,9 @@ </bean> <bean id="jmsConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory"> - <property name="brokerURL" value="vm://itest-jms?broker.persistent=false&create=false"/> + <property name="brokerURL"> + <bean class="org.apache.camel.component.jms.issues.CamelBrokerClientTestSupport" factory-method="getServiceAddress"/> + </property> </bean> <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager"> diff --git a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JMSNestedTransactionTest-context.xml b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSNestedTransactionRollbackTest.xml similarity index 91% rename from tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JMSNestedTransactionTest-context.xml rename to components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSNestedTransactionRollbackTest.xml index df612d22157..66dd865fb8a 100644 --- a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/JMSNestedTransactionTest-context.xml +++ b/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSNestedTransactionRollbackTest.xml @@ -31,7 +31,9 @@ </bean> <bean id="jmsConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory"> - <property name="brokerURL" value="vm://itest-jms?broker.persistent=false&create=false"/> + <property name="brokerURL"> + <bean class="org.apache.camel.component.jms.issues.CamelBrokerClientTestSupport" factory-method="getServiceAddress"/> + </property> </bean> <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager"> @@ -77,6 +79,6 @@ </camelContext> - <bean id="errorProducer" class="org.apache.camel.itest.jms.JMSNestedTransactionRollbackTest.ErrorThrowProcessor"/> + <bean id="errorProducer" class="org.apache.camel.component.jms.tx.JMSNestedTransactionRollbackTest.ErrorThrowProcessor"/> </beans> diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsIntegrationTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsIntegrationTest.java deleted file mode 100644 index fecb85865f5..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsIntegrationTest.java +++ /dev/null @@ -1,79 +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.itest.jms; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jms.JmsComponent; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.spi.Registry; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class JmsIntegrationTest extends CamelTestSupport { - @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); - - private static final Logger LOG = LoggerFactory.getLogger(JmsIntegrationTest.class); - - protected CountDownLatch receivedCountDown = new CountDownLatch(1); - protected MyBean myBean = new MyBean(); - - @Test - void testOneWayInJmsOutPojo() throws Exception { - // Send a message to the JMS endpoint - template.sendBodyAndHeader("jms:test", "Hello", "cheese", 123); - - // The Activated endpoint should send it to the pojo due to the configured route. - assertTrue(receivedCountDown.await(5, TimeUnit.SECONDS), "The message ware received by the Pojo"); - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() { - from("jms:test").to("bean:myBean"); - } - }; - } - - @Override - protected void bindToRegistry(Registry registry) { - // add ActiveMQ with embedded broker - JmsComponent amq = jmsServiceExtension.getComponent(); - - amq.setCamelContext(context); - - registry.bind("myBean", myBean); - registry.bind("jms", amq); - } - - protected class MyBean { - public void onMessage(String body) { - LOG.info("Received: " + body); - receivedCountDown.countDown(); - } - } - -} diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java deleted file mode 100644 index 7d8fcd90752..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsMediumQueuePerformanceTest.java +++ /dev/null @@ -1,25 +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.itest.jms; - -public class JmsMediumQueuePerformanceTest extends JmsPerformanceTest { - - @Override - protected int getMessageCount() { - return 1000; - } -} diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPerformanceTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPerformanceTest.java deleted file mode 100644 index 050a28a161e..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsPerformanceTest.java +++ /dev/null @@ -1,126 +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.itest.jms; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.camel.Header; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jms.JmsComponent; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.spi.Registry; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class JmsPerformanceTest extends CamelTestSupport { - @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); - - private static final Logger LOG = LoggerFactory.getLogger(JmsPerformanceTest.class); - - private List<Integer> receivedHeaders = new ArrayList<>(getMessageCount()); - private List<Object> receivedMessages = new ArrayList<>(getMessageCount()); - - @Test - void testSendingAndReceivingMessages() throws Exception { - LOG.info("Sending {} messages", getMessageCount()); - - sendLoop(getMessageCount()); - - LOG.info("Sending {} messages completed, now will assert on their content as well as the order of their receipt", - getMessageCount()); - - // should wait a bit to make sure all messages have been received by the MyBean#onMessage() method - // as this happens asynchronously, that's not inside the 'main' thread - Thread.sleep(3000); - - assertExpectedMessagesReceived(); - } - - protected int getMessageCount() { - return 100; - } - - protected void sendLoop(int messageCount) { - for (int i = 1; i <= messageCount; i++) { - sendMessage(i); - } - } - - protected void sendMessage(int messageCount) { - template.sendBodyAndHeader("activemq:" + getQueueName(), "Hello:" + messageCount, "counter", messageCount); - } - - protected String getQueueName() { - return "testSendingAndReceivingMessages"; - } - - protected void assertExpectedMessagesReceived() throws InterruptedException { - // assert on the expected message count - assertEquals(getMessageCount(), receivedMessages.size(), "The expected message count does not match!"); - - // assert on the expected message order - List<Integer> expectedHeaders = new ArrayList<>(getMessageCount()); - for (int i = 1; i <= getMessageCount(); i++) { - expectedHeaders.add(i); - } - - List<Object> expectedMessages = new ArrayList<>(getMessageCount()); - for (int i = 1; i <= getMessageCount(); i++) { - expectedMessages.add("Hello:" + i); - } - - assertEquals(expectedHeaders, receivedHeaders, "The expected header order does not match!"); - assertEquals(expectedMessages, receivedMessages, "The expected message order does not match!"); - } - - @Override - protected void bindToRegistry(Registry registry) { - // add AMQ client and make use of connection pooling we depend on because of the (large) number - // of the JMS messages we do produce - // add ActiveMQ with embedded broker - JmsComponent amq = jmsServiceExtension.getComponent(); - - amq.setCamelContext(context); - - registry.bind("myBean", new MyBean()); - registry.bind("activemq", amq); - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() { - from("activemq:" + getQueueName()).to("bean:myBean"); - } - }; - } - - protected class MyBean { - public void onMessage(@Header("counter") int counter, Object body) { - // the invocation of this method happens inside the same thread so no need for a thread-safe list here - receivedHeaders.add(counter); - receivedMessages.add(body); - } - } -} diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsResequencerTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsResequencerTest.java deleted file mode 100644 index 2898d80d001..00000000000 --- a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/JmsResequencerTest.java +++ /dev/null @@ -1,175 +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.itest.jms; - -import java.util.List; - -import org.apache.camel.Body; -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jms.JmsComponent; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.itest.utils.extensions.JmsServiceExtension; -import org.apache.camel.model.config.BatchResequencerConfig; -import org.apache.camel.spi.Registry; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.junit.jupiter.api.Assertions.assertSame; - -public class JmsResequencerTest extends CamelTestSupport { - @RegisterExtension - public static JmsServiceExtension jmsServiceExtension = JmsServiceExtension.createExtension(); - - private static final Logger LOG = LoggerFactory.getLogger(JmsResequencerTest.class); - private ReusableBean b1 = new ReusableBean("myBean1"); - private ReusableBean b2 = new ReusableBean("myBean2"); - private ReusableBean b3 = new ReusableBean("myBean3"); - - private MockEndpoint resultEndpoint; - - public void sendBodyAndHeader( - String endpointUri, final Object body, final String headerName, - final Object headerValue) { - template.send(endpointUri, exchange -> { - Message in = exchange.getIn(); - in.setBody(body); - in.setHeader(headerName, headerValue); - //in.setHeader("testCase", getName()); - in.setHeader(Exchange.BEAN_METHOD_NAME, "execute"); - }); - } - - @Test - void testSendMessagesInWrongOrderButReceiveThemInCorrectOrder() throws Exception { - sendAndVerifyMessages("activemq:queue:batch"); - } - - @Test - void testSendMessageToStream() throws Exception { - sendAndVerifyMessages("activemq:queue:stream"); - } - - private void sendAndVerifyMessages(String endpointUri) throws Exception { - resultEndpoint.expectedBodiesReceived("msg1", "msg2", "msg3", "msg4", "msg5", "msg6"); - sendBodyAndHeader(endpointUri, "msg4", "seqnum", 4L); - sendBodyAndHeader(endpointUri, "msg1", "seqnum", 1L); - sendBodyAndHeader(endpointUri, "msg3", "seqnum", 3L); - sendBodyAndHeader(endpointUri, "msg2", "seqnum", 2L); - sendBodyAndHeader(endpointUri, "msg6", "seqnum", 6L); - sendBodyAndHeader(endpointUri, "msg5", "seqnum", 5L); - resultEndpoint.assertIsSatisfied(); - List<Exchange> list = resultEndpoint.getReceivedExchanges(); - for (Exchange exchange : list) { - LOG.debug("Received: " + exchange); - } - } - - @Override - @BeforeEach - public void setUp() throws Exception { - super.setUp(); - - resultEndpoint = getMockEndpoint("mock:result"); - - Object lookedUpBean = context.getRegistry().lookupByName("myBean1"); - assertSame(b1, lookedUpBean, "Lookup of 'myBean' should return same object!"); - lookedUpBean = context.getRegistry().lookupByName("myBean2"); - assertSame(b2, lookedUpBean, "Lookup of 'myBean' should return same object!"); - lookedUpBean = context.getRegistry().lookupByName("myBean3"); - assertSame(b3, lookedUpBean, "Lookup of 'myBean' should return same object!"); - - } - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - public void configure() { - - from("activemq:queue:batch") - .to(callExecuteOnBean("myBean1")) - .resequence(header("seqnum")) - .batch(new BatchResequencerConfig(100, 2000L)) - .to(callExecuteOnBean("myBean2")) - .to("activemq:queue:stop"); - - from("activemq:queue:stream") - .to(callExecuteOnBean("myBean1")) - .resequence(header("seqnum")) - .stream() - .to(callExecuteOnBean("myBean2")) - .to("activemq:queue:stop"); - - from("activemq:queue:stop") - .to(callExecuteOnBean("myBean3")) - .to("mock:result"); - - } - }; - } - - private static String callExecuteOnBean(String beanName) { - return "bean:" + beanName + "?method=execute"; - } - - public static class ReusableBean { - public String body; - private String name; - - public ReusableBean(String name) { - this.name = name; - } - - public void setName(String name) { - this.name = name; - } - - @Override - public String toString() { - return "MyBean:" + name; - } - - public void read(@Body String body) { - this.body = body; - LOG.info(name + " read() method on " + this + " with body: " + body); - } - - public void execute() { - LOG.info(name + " started"); - LOG.info(name + " finished"); - } - } - - @Override - protected void bindToRegistry(Registry registry) { - // add ActiveMQ with embedded broker - JmsComponent amq = jmsServiceExtension.getComponent(); - - amq.setCamelContext(context); - registry.bind("activemq", amq); - - registry.bind("myBean1", b1); - registry.bind("myBean2", b2); - registry.bind("myBean3", b3); - } - -}