Merge pull request #1 from myrle-krantz/develop
Making it possible to listen for events in integration tests.
diff --git a/build.gradle b/build.gradle
index 1d72f8d..b77a0d4 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,7 +19,9 @@
frameworkapi : '0.1.0-BUILD-SNAPSHOT',
frameworktest : '0.1.0-BUILD-SNAPSHOT',
frameworkanubis : '0.1.0-BUILD-SNAPSHOT',
- validator : '5.3.0.Final'
+ validator : '5.3.0.Final',
+ springcontext : '4.3.3.RELEASE',
+ activeMQ : '5.13.2',
]
apply plugin: 'java'
@@ -59,6 +61,9 @@
[group: 'org.eclipse.aether', name: 'aether-transport-http', version: '1.1.0'],
[group: 'org.apache.maven', name: 'maven-aether-provider', version: '3.1.0'],
[group: 'org.springframework.cloud', name: 'spring-cloud-starter-eureka-server'],
+ [group: 'org.springframework', name: 'spring-jms', version: versions.springcontext],
+ [group: 'org.apache.activemq', name: 'activemq-broker', version: versions.activeMQ],
+ [group: 'org.apache.activemq', name: 'activemq-spring', version: versions.activeMQ],
)
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index f1b1899..0e42381 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Mar 15 18:38:13 CET 2017
+#Thu Mar 23 14:10:08 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-all.zip
diff --git a/src/main/java/io/mifos/core/test/servicestarter/ActiveMQForTest.java b/src/main/java/io/mifos/core/test/servicestarter/ActiveMQForTest.java
new file mode 100644
index 0000000..6fb4214
--- /dev/null
+++ b/src/main/java/io/mifos/core/test/servicestarter/ActiveMQForTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.test.servicestarter;
+
+import io.mifos.core.test.listener.EnableEventRecording;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.jms.pool.PooledConnectionFactory;
+import org.apache.activemq.spring.ActiveMQConnectionFactory;
+import org.junit.rules.ExternalResource;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
+import org.springframework.jms.config.JmsListenerContainerFactory;
+
+import java.lang.annotation.*;
+
+/**
+ * @author Myrle Krantz
+ */
+@SuppressWarnings("WeakerAccess")
+public class ActiveMQForTest extends ExternalResource {
+ static final int PORT = 61616;
+ static final String BIND_ADDRESS = "tcp://localhost:" + PORT;
+
+ @Configuration
+ @EnableAutoConfiguration(exclude= {HibernateJpaAutoConfiguration.class, DataSourceAutoConfiguration.class})
+ @EnableEventRecording(maxWait = 45000L)
+ public static class ActiveMQListenConfiguration {
+ @Bean
+ public PooledConnectionFactory jmsFactory() {
+ final PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory();
+ final ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
+ activeMQConnectionFactory.setBrokerURL(BIND_ADDRESS);
+ pooledConnectionFactory.setConnectionFactory(activeMQConnectionFactory);
+
+ return pooledConnectionFactory;
+ }
+
+ @Bean
+ public JmsListenerContainerFactory jmsListenerContainerFactory(final PooledConnectionFactory jmsFactory) {
+ final DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
+ factory.setPubSubDomain(true);
+ factory.setConnectionFactory(jmsFactory);
+ factory.setConcurrency(CONCURRENCY);
+
+ return factory;
+ }
+ }
+
+
+ @SuppressWarnings("unused")
+ @Target(ElementType.TYPE)
+ @Retention(RetentionPolicy.RUNTIME)
+ @Documented
+ @Inherited
+ @Import({ActiveMQListenConfiguration.class})
+ public @interface EnableActiveMQListen {
+
+ }
+
+ private static final String CONCURRENCY = "3-10";
+
+ private BrokerService broker;
+
+ @Override
+ protected void before() throws Throwable {
+ broker = new BrokerService();
+ broker.addConnector(BIND_ADDRESS);
+ broker.setPersistent(false);
+ broker.start();
+ }
+
+ @Override
+ protected void after() {
+ try {
+ broker.stop();
+ } catch (final Exception e) {
+ System.out.println("ActiveMQ threw an exception when stopping.");
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/io/mifos/core/test/servicestarter/IntegrationTestEnvironment.java b/src/main/java/io/mifos/core/test/servicestarter/IntegrationTestEnvironment.java
index b57b6f1..558a07a 100644
--- a/src/main/java/io/mifos/core/test/servicestarter/IntegrationTestEnvironment.java
+++ b/src/main/java/io/mifos/core/test/servicestarter/IntegrationTestEnvironment.java
@@ -83,9 +83,11 @@
nextPort = 2020;
this.ports = new HashSet<>();
+ //Prevent the following ports from being allocated to Microservices.
this.ports.add(0);
this.ports.add(3306); //MySQL
this.ports.add(9142); //Cassandra
+ this.ports.add(ActiveMQForTest.PORT);
this.ports.add(EurekaForTest.PORT);
this.applicationNames = new ArrayList<>();
diff --git a/src/main/java/io/mifos/core/test/servicestarter/Microservice.java b/src/main/java/io/mifos/core/test/servicestarter/Microservice.java
index ef5fb14..58c5065 100644
--- a/src/main/java/io/mifos/core/test/servicestarter/Microservice.java
+++ b/src/main/java/io/mifos/core/test/servicestarter/Microservice.java
@@ -67,6 +67,7 @@
processEnvironment.setProperty("eureka.instance.leaseRenewalIntervalInSeconds", "1"); //Speed up registration for test purposes.
processEnvironment.setProperty("eureka.client.initialInstanceInfoReplicationIntervalSeconds", "0"); //Speed up initial registration for test purposes.
processEnvironment.setProperty("eureka.client.instanceInfoReplicationIntervalSeconds", "1");
+ processEnvironment.setProperty("activemq.brokerUrl", ActiveMQForTest.BIND_ADDRESS);
this.integrationTestEnvironment = integrationTestEnvironment;
}