diff --git a/.travis.yml b/.travis.yml index 9453cf3452..ef48e6baec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -177,6 +177,11 @@ jobs: - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.16.1 script: travis_wait 20 mvn -B test -pl repository -Dtest=AllDBTestsTestSuite -Ddb.driver=org.postgresql.Driver -Ddb.name=alfresco -Ddb.url=jdbc:postgresql://localhost:5433/alfresco -Ddb.username=alfresco -Ddb.password=alfresco + - name: "Repository - Messaging tests" + before_script: + - docker run -d -p 61616:61616 -p 5672:5672 alfresco/alfresco-activemq:5.16.1 + script: travis_wait 20 mvn -B test -pl repository -Dtest=CamelRoutesTest,CamelComponentsTest + - name: "Remote-api - AppContext01TestSuite" before_script: - docker run -d -p 5433:5432 -e POSTGRES_PASSWORD=alfresco -e POSTGRES_USER=alfresco -e POSTGRES_DB=alfresco postgres:13.1 postgres -c 'max_connections=300' diff --git a/repository/src/test/java/org/alfresco/messaging/camel/CamelComponentsTest.java b/repository/src/test/java/org/alfresco/messaging/camel/CamelComponentsTest.java new file mode 100644 index 0000000000..5cbc6358d3 --- /dev/null +++ b/repository/src/test/java/org/alfresco/messaging/camel/CamelComponentsTest.java @@ -0,0 +1,99 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2018 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.messaging.camel; + +import org.apache.camel.CamelContext; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import static org.junit.Assert.assertEquals; + +/** + * Tests Camel components defined in the application's Spring context + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = "/test-messaging-context.xml") +public class CamelComponentsTest { + @Autowired + protected CamelContext camelContext; + + @Produce("activemq:queue:alfresco.test") + protected ProducerTemplate activemqTemplate; + + @Produce("amqp:queue:alfresco.test") + protected ProducerTemplate amqpTemplate; + + @Produce("jms:queue:alfresco.test") + protected ProducerTemplate jmsTemplate; + + + @Test + public void testActivemqComponent() + { + final String msg = "ping "; + + activemqTemplate.sendBody(msg); + + final Object reply = camelContext + .createConsumerTemplate() + .receiveBody("activemq:queue:alfresco.test", 2000); + + assertEquals(msg, reply); + } + + @Test + public void testAmqpComponent() + { + final String msg = "ping "; + + amqpTemplate.sendBody(msg); + + final Object reply = camelContext + .createConsumerTemplate() + .receiveBody("amqp:queue:alfresco.test", 2000); + + assertEquals(msg, reply); + } + + @Test + public void testJmsComponent() + { + final String msg = "ping "; + + jmsTemplate.sendBody(msg); + + final Object reply = camelContext + .createConsumerTemplate() + .receiveBody("jms:queue:alfresco.test", 2000); + + assertEquals(msg, reply); + } +} diff --git a/repository/src/test/java/org/alfresco/messaging/camel/CamelRoutesTest.java b/repository/src/test/java/org/alfresco/messaging/camel/CamelRoutesTest.java index 119374125f..57cdd43eaf 100644 --- a/repository/src/test/java/org/alfresco/messaging/camel/CamelRoutesTest.java +++ b/repository/src/test/java/org/alfresco/messaging/camel/CamelRoutesTest.java @@ -61,76 +61,76 @@ public class CamelRoutesTest @Produce("direct-vm:alfresco.test.1") protected ProducerTemplate template1; - + @Produce("direct-vm:alfresco.test.2") protected ProducerTemplate template2; - + @Produce("direct-vm:alfresco.default") protected ProducerTemplate template3; - + @Produce("direct-vm:alfresco.test.transacted") protected ProducerTemplate template4; - + @Autowired protected MockExceptionProcessor messagingExceptionProcessor; - + @Autowired protected MockConsumer mockConsumer; - + @Autowired protected MockExceptionThrowingConsumer mockExceptionThrowingConsumer; @Test public void testMessageRouteXmlDefined() throws Exception { String expectedBody = ""; - + resultEndpoint1.expectedBodiesReceived(expectedBody); - + template1.sendBody(expectedBody); - + resultEndpoint1.assertIsSatisfied(); } - + @Test public void testMessageRoutePackageDefined() throws Exception { String expectedBody = ""; - + resultEndpoint2.expectedBodiesReceived(expectedBody); - + template2.sendBody(expectedBody); - + resultEndpoint2.assertIsSatisfied(); } - + @Test public void testMessageRouteXmlOverride() throws Exception { String expectedBody = ""; - + dlqEndpoint.expectedBodiesReceived(expectedBody); - + template3.sendBody(expectedBody); - + dlqEndpoint.assertIsSatisfied(); } - + @Test public void testTransactedRoute() throws Exception { String expectedBody = ""; - + template4.sendBody(expectedBody); - + // Wait for Camel and ActiveMQ to process Thread.sleep(2000); - + // Test that our exception processor received the error assertNotNull(messagingExceptionProcessor.getLastError()); assertTrue(messagingExceptionProcessor.getLastError().getClass().equals( IllegalArgumentException.class)); - + // Check that an error was thrown the first time assertTrue(mockExceptionThrowingConsumer.isErrorThrown()); assertNull(mockExceptionThrowingConsumer.getLastMessage()); - + // Check that the message was re-delivered to a second consumer assertEquals(expectedBody, mockConsumer.getLastMessage()); } diff --git a/repository/src/test/resources/test-messaging-context.xml b/repository/src/test/resources/test-messaging-context.xml index ff17e10e96..fda5961a26 100644 --- a/repository/src/test/resources/test-messaging-context.xml +++ b/repository/src/test/resources/test-messaging-context.xml @@ -9,13 +9,13 @@ - + - + @@ -25,4 +25,19 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/repository/src/test/resources/test-messaging.properties b/repository/src/test/resources/test-messaging.properties index c28423a695..fee0fe7fcf 100644 --- a/repository/src/test/resources/test-messaging.properties +++ b/repository/src/test/resources/test-messaging.properties @@ -1,6 +1,9 @@ -messaging.broker.url=vm://localhost?broker.persistent=false +messaging.broker.url=nio://localhost:61616 messaging.broker.ssl=false messaging.broker.connections.max=8 messaging.transacted=true messaging.broker.username= -messaging.broker.password= \ No newline at end of file +messaging.broker.password= + +acs.repo.rendition.events.endpoint=jms:acs-repo-rendition-events-test?jmsMessageType=Text +acs.repo.transform.request.endpoint=jms:acs-repo-transform-request-test?jmsMessageType=Text \ No newline at end of file