You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/06/20 08:47:13 UTC
[camel] 02/06: CAMEL-19429: added an initial set of integration tests
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
commit 4f07a871cf5e0e621d7c38cf43f2c83e783fe787
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Jun 19 13:25:44 2023 +0200
CAMEL-19429: added an initial set of integration tests
---
components/camel-activemq/pom.xml | 23 +++-
.../component/activemq/ActiveMQITSupport.java | 65 +++++++++++
.../camel/component/activemq/ActiveMQRouteIT.java | 121 +++++++++++++++++++++
.../camel/component/activemq/ActiveMQToDIT.java | 68 ++++++++++++
.../activemq/ActiveMQToDSendDynamicIT.java | 70 ++++++++++++
5 files changed, 345 insertions(+), 2 deletions(-)
diff --git a/components/camel-activemq/pom.xml b/components/camel-activemq/pom.xml
index 43c3654bd57..94d3c1554d3 100644
--- a/components/camel-activemq/pom.xml
+++ b/components/camel-activemq/pom.xml
@@ -50,9 +50,28 @@
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-test-junit5</artifactId>
+ <artifactId>camel-test-infra-core</artifactId>
+ <version>${project.version}</version>
<scope>test</scope>
+ <type>test-jar</type>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-artemis</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test-infra-messaging-common</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
+
</dependencies>
-</project>
\ No newline at end of file
+</project>
diff --git a/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQITSupport.java b/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQITSupport.java
new file mode 100644
index 00000000000..d0e1f8b2254
--- /dev/null
+++ b/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQITSupport.java
@@ -0,0 +1,65 @@
+/*
+ * 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.component.activemq;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.test.infra.artemis.services.ArtemisContainer;
+import org.apache.camel.test.infra.core.CamelContextExtension;
+import org.apache.camel.test.infra.core.DefaultCamelContextExtension;
+import org.apache.camel.test.infra.core.api.ConfigurableContext;
+import org.apache.camel.test.infra.core.api.ConfigurableRoute;
+import org.apache.camel.test.infra.messaging.services.MessagingLocalContainerService;
+import org.apache.camel.test.infra.messaging.services.MessagingService;
+import org.apache.camel.test.infra.messaging.services.MessagingServiceFactory;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+public abstract class ActiveMQITSupport implements ConfigurableContext, ConfigurableRoute {
+ @Order(1)
+ @RegisterExtension
+ protected static MessagingService service = MessagingServiceFactory.builder()
+ .addLocalMapping(ActiveMQITSupport::createLocalService)
+ .build();
+
+ @Order(2)
+ @RegisterExtension
+ protected static CamelContextExtension contextExtension = new DefaultCamelContextExtension();
+
+
+ public static MessagingLocalContainerService<ArtemisContainer> createLocalService() {
+ ArtemisContainer container = new ArtemisContainer();
+
+ return new MessagingLocalContainerService<>(container, c -> container.defaultEndpoint());
+ }
+
+ /* We don't want topic advisories here: they may cause publication issues (i.e.:
+ * jakarta.jms.InvalidDestinationException: Cannot publish to a deleted Destination) with
+ * spring JMS. So, we disable them ...
+ */
+
+ public static ActiveMQComponent activeMQComponent(String uri) {
+ ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(uri);
+
+ connectionFactory.setWatchTopicAdvisories(false);
+
+ ActiveMQConfiguration activeMQConfiguration = new ActiveMQConfiguration();
+ activeMQConfiguration.setConnectionFactory(connectionFactory);
+
+ return new ActiveMQComponent(activeMQConfiguration);
+ }
+}
diff --git a/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQRouteIT.java b/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQRouteIT.java
new file mode 100644
index 00000000000..52e389a38f2
--- /dev/null
+++ b/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQRouteIT.java
@@ -0,0 +1,121 @@
+/*
+ * 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.component.activemq;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.infra.core.annotations.ContextFixture;
+import org.apache.camel.test.infra.core.annotations.RouteFixture;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ActiveMQRouteIT extends ActiveMQITSupport {
+
+ private ProducerTemplate template;
+
+ private MockEndpoint resultEndpoint;
+ private String expectedBody = "Hello there!";
+
+ @BeforeEach
+ void setupTemplate() {
+ template = contextExtension.getProducerTemplate();
+ resultEndpoint = contextExtension.getMockEndpoint("mock:result");
+ }
+
+ @Test
+ public void testJmsQueue() throws Exception {
+ resultEndpoint.expectedMessageCount(1);
+ resultEndpoint.message(0).header("cheese").isEqualTo(123);
+
+ template.sendBodyAndHeader("activemq:queue:ping", expectedBody, "cheese", 123);
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Test
+ public void testRequestReply() {
+ String response = template.requestBody("activemq:queue:inOut", expectedBody, String.class);
+ assertEquals("response", response);
+ }
+
+ @Test
+ public void testJmsTopic() throws Exception {
+ resultEndpoint.expectedMessageCount(2);
+ resultEndpoint.message(0).header("cheese").isEqualTo(123);
+ template.sendBodyAndHeader("activemq:topic:ping", expectedBody, "cheese", 123);
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Test
+ public void testPrefixWildcard() throws Exception {
+ resultEndpoint.expectedMessageCount(1);
+ template.sendBody("activemq:wildcard.foo.bar", expectedBody);
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Test
+ public void testIncludeDestination() throws Exception {
+ resultEndpoint.expectedMessageCount(1);
+ resultEndpoint.message(0).header("JMSDestination").isEqualTo("queue://ping");
+ template.sendBody("activemq:queue:ping", expectedBody);
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @ContextFixture
+ public void configureContext(CamelContext context) {
+
+ context.addComponent("activemq", activeMQComponent(service.defaultEndpoint()));
+ }
+
+ @RouteFixture
+ public void createRouteBuilder(CamelContext context) throws Exception {
+ context.addRoutes(createRouteBuilder());
+ }
+
+ private static RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("activemq:queue:ping")
+ .to("log:routing")
+ .to("mock:result");
+
+ from("activemq:queue:inOut")
+ .setBody()
+ .constant("response");
+
+ from("activemq:topic:ping")
+ .to("log:routing")
+ .to("mock:result");
+
+ from("activemq:topic:ping")
+ .to("log:routing")
+ .to("mock:result");
+
+ from("activemq:queue:wildcard.#")
+ .to("log:routing")
+ .to("mock:result");
+
+ from("activemq:queue:uriEndpoint")
+ .to("log:routing")
+ .to("mock:result");
+ }
+ };
+ }
+}
diff --git a/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQToDIT.java b/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQToDIT.java
new file mode 100644
index 00000000000..59745177391
--- /dev/null
+++ b/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQToDIT.java
@@ -0,0 +1,68 @@
+/*
+ * 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.component.activemq;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.infra.core.annotations.ContextFixture;
+import org.apache.camel.test.infra.core.annotations.RouteFixture;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class ActiveMQToDIT extends ActiveMQITSupport {
+ private ProducerTemplate template;
+
+ @Test
+ public void testToD() throws Exception {
+ contextExtension.getMockEndpoint("mock:bar").expectedBodiesReceived("Hello bar");
+ contextExtension.getMockEndpoint("mock:beer").expectedBodiesReceived("Hello beer");
+
+ template.sendBodyAndHeader("direct:start", "Hello bar", "where", "bar");
+ template.sendBodyAndHeader("direct:start", "Hello beer", "where", "beer");
+
+ MockEndpoint.assertIsSatisfied(contextExtension.getContext());
+ }
+
+ @BeforeEach
+ void setupTemplate() {
+ template = contextExtension.getProducerTemplate();
+ }
+
+ @ContextFixture
+ public void configureContext(CamelContext camelContext) {
+ camelContext.addComponent("activemq", activeMQComponent(service.defaultEndpoint()));
+ }
+
+ @RouteFixture
+ public void createRouteBuilder(CamelContext context) throws Exception {
+ context.addRoutes(createRouteBuilder());
+ }
+
+ private RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // route message dynamic using toD
+ from("direct:start").toD("activemq:queue:${header.where}");
+
+ from("activemq:queue:bar").to("mock:bar");
+ from("activemq:queue:beer").to("mock:beer");
+ }
+ };
+ }
+}
diff --git a/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQToDSendDynamicIT.java b/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQToDSendDynamicIT.java
new file mode 100644
index 00000000000..7509817c474
--- /dev/null
+++ b/components/camel-activemq/src/test/java/org/apache/camel/component/activemq/ActiveMQToDSendDynamicIT.java
@@ -0,0 +1,70 @@
+/*
+ * 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.component.activemq;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.infra.core.annotations.ContextFixture;
+import org.apache.camel.test.infra.core.annotations.RouteFixture;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class ActiveMQToDSendDynamicIT extends ActiveMQITSupport {
+ private ProducerTemplate template;
+ private ConsumerTemplate consumer;
+
+ @Test
+ public void testToD() {
+ template.sendBodyAndHeader("direct:start", "Hello bar", "where", "bar");
+ template.sendBodyAndHeader("direct:start", "Hello beer", "where", "beer");
+
+ // The messages should be in the queues
+ String out = consumer.receiveBody("activemq:queue:bar", 2000, String.class);
+ assertEquals("Hello bar", out);
+ out = consumer.receiveBody("activemq:queue:beer", 2000, String.class);
+ assertEquals("Hello beer", out);
+ }
+
+ @BeforeEach
+ void setupTemplate() {
+ template = contextExtension.getProducerTemplate();
+ consumer = contextExtension.getConsumerTemplate();
+ }
+
+ @ContextFixture
+ public void configureContext(CamelContext camelContext) {
+ camelContext.addComponent("activemq", activeMQComponent(service.defaultEndpoint()));
+ }
+
+ @RouteFixture
+ public void createRouteBuilder(CamelContext context) throws Exception {
+ context.addRoutes(createRouteBuilder());
+ }
+
+ private RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // route message dynamic using toD
+ from("direct:start").toD("activemq:queue:${header.where}");
+ }
+ };
+ }
+}