ACS-1252 : Add tests for the JMS/ActiveMQ/Camel configuration in *alfresco-community-repo* (#356)

- fix messaging context for tests by adding missing mocked beans and properties
   - add tests for amqp, jms, activemq protocols
   - add travis job to run messaging tests
This commit is contained in:
Denis Ungureanu
2021-03-24 14:13:37 +02:00
committed by GitHub
parent 8c91145b39
commit d91a552925
5 changed files with 149 additions and 27 deletions

View File

@@ -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'

View File

@@ -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 <http://www.gnu.org/licenses/>.
* #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 <activemq>";
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 <amqp>";
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 <jms>";
jmsTemplate.sendBody(msg);
final Object reply = camelContext
.createConsumerTemplate()
.receiveBody("jms:queue:alfresco.test", 2000);
assertEquals(msg, reply);
}
}

View File

@@ -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 = "<matched.>";
resultEndpoint1.expectedBodiesReceived(expectedBody);
template1.sendBody(expectedBody);
resultEndpoint1.assertIsSatisfied();
}
@Test
public void testMessageRoutePackageDefined() throws Exception {
String expectedBody = "<matched.>";
resultEndpoint2.expectedBodiesReceived(expectedBody);
template2.sendBody(expectedBody);
resultEndpoint2.assertIsSatisfied();
}
@Test
public void testMessageRouteXmlOverride() throws Exception {
String expectedBody = "<matched.>";
dlqEndpoint.expectedBodiesReceived(expectedBody);
template3.sendBody(expectedBody);
dlqEndpoint.assertIsSatisfied();
}
@Test
public void testTransactedRoute() throws Exception {
String expectedBody = "<matched.>";
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());
}

View File

@@ -9,13 +9,13 @@
</bean>
<import resource="classpath:/alfresco/subsystems/Messaging/default/messaging-context.xml" />
<bean id="messagingExceptionProcessor"
class="org.alfresco.messaging.camel.MockExceptionProcessor" />
<bean id="mockConsumer"
class="org.alfresco.messaging.camel.MockConsumer" />
<bean id="mockExceptionThrowingConsumer"
class="org.alfresco.messaging.camel.MockExceptionThrowingConsumer" />
@@ -25,4 +25,19 @@
<property name="routeContextId" value="customRoutes" />
</bean>
<bean id="transactionAwareEventProducer" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.alfresco.repo.rawevents.TransactionAwareEventProducer" />
</bean>
<bean id="policyComponent" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.alfresco.repo.policy.PolicyComponentImpl"/>
</bean>
<bean id="renditionEventProcessor" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.alfresco.repo.rendition2.RenditionEventProcessor"/>
</bean>
<bean id="transformRequestProcessor" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.alfresco.repo.rendition2.TransformRequestProcessor" />
</bean>
</beans>

View File

@@ -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=
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