Convert remaining spring-rabbit tests to JUnit 5

* Fix possible race in testConsumerBatching

* Convert all spring-amqp tests to JUnit 5

* Convert remaining tests to JUnit 5; remove JUnit 4 test dependency

* Remove JUnit vintage engine dependency
This commit is contained in:
Gary Russell
2019-08-22 16:31:58 -04:00
committed by Artem Bilan
parent accd202a1a
commit 868979d9a4
78 changed files with 460 additions and 646 deletions

View File

@@ -124,25 +124,21 @@ subprojects { subproject ->
// dependencies that are common across all java projects
dependencies {
compileOnly "com.google.code.findbugs:jsr305:$googleJsr305Version"
testCompile ("junit:junit:$junit4Version") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testCompile "org.apache.logging.log4j:log4j-core:$log4jVersion"
testCompile "org.hamcrest:hamcrest-all:$hamcrestVersion"
testCompile ("org.mockito:mockito-core:$mockitoVersion") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testCompile "org.mockito:mockito-junit-jupiter:$mockitoVersion"
testCompile "org.springframework:spring-test:$springVersion"
testRuntime "org.apache.logging.log4j:log4j-jcl:$log4jVersion"
testCompile "org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion"
testCompile "org.junit.jupiter:junit-jupiter-params:$junitJupiterVersion"
testRuntime "org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion"
testRuntime "org.junit.platform:junit-platform-launcher:$junitPlatformVersion"
// To support JUnit 4 tests
testRuntime "org.junit.vintage:junit-vintage-engine:$junitJupiterVersion"
// To avoid compiler warnings about @API annotations in JUnit code
testCompileOnly 'org.apiguardian:apiguardian-api:1.0.0'
@@ -368,7 +364,11 @@ project('spring-rabbit-junit') {
dependencies { // no spring-amqp dependencies allowed
compile "org.springframework:spring-core:$springVersion"
compile ("junit:junit:$junit4Version", optional)
compile "org.springframework:spring-test:$springVersion"
compile ("junit:junit:$junit4Version") {
optional(it)
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
compile "com.rabbitmq:amqp-client:$rabbitmqVersion"
compile ("com.rabbitmq:http-client:$rabbitmqHttpClientVersion") {
exclude group: 'org.springframework', module: 'spring-web'
@@ -396,10 +396,6 @@ project('spring-rabbit-test') {
dependencies {
compile project(":spring-rabbit")
compile ("junit:junit:$junit4Version") {
optional(it)
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
compile "org.hamcrest:hamcrest-all:$hamcrestVersion"
compile ("org.mockito:mockito-core:$mockitoVersion") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'

View File

@@ -18,7 +18,7 @@ package org.springframework.amqp.core;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* @author Mark Pollack

View File

@@ -20,8 +20,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
/**
* @author Mark Fisher
@@ -31,7 +31,7 @@ public class BindingBuilderTests {
private static Queue queue;
@BeforeClass
@BeforeAll
public static void setUp() {
queue = new Queue("q");
}

View File

@@ -21,7 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**

View File

@@ -26,7 +26,7 @@ import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.support.converter.SimpleMessageConverter;
import org.springframework.amqp.utils.SerializationUtils;

View File

@@ -21,7 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* Tests for {@link QueueBuilder}

View File

@@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.regex.Pattern;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* @author Gary Russell

View File

@@ -18,7 +18,7 @@ package org.springframework.amqp.core.builder;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;

View File

@@ -22,7 +22,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Address;
import org.springframework.amqp.core.Message;

View File

@@ -17,11 +17,12 @@
package org.springframework.amqp.remoting;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Address;
@@ -58,7 +59,7 @@ public class RemotingTest {
* Set up a rig of directly wired-up proxy and service listener so that both can be tested together without needing
* a running rabbit.
*/
@Before
@BeforeEach
public void initializeTestRig() {
// Set up the service
TestServiceInterface testService = new TestServiceImpl();
@@ -113,15 +114,15 @@ public class RemotingTest {
}
}
@Test(expected = RuntimeException.class)
@Test
public void testExceptionPropagation() {
riggedProxy.exceptionThrowingMethod();
assertThatExceptionOfType(AmqpException.class).isThrownBy(() -> riggedProxy.exceptionThrowingMethod());
}
@Test(expected = GeneralException.class)
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Test
public void testExceptionReturningMethod() {
riggedProxy.notReallyExceptionReturningMethod();
assertThatExceptionOfType(GeneralException.class)
.isThrownBy(() -> riggedProxy.notReallyExceptionReturningMethod());
}
@Test

View File

@@ -16,6 +16,8 @@
package org.springframework.amqp.remoting.testservice;
import org.springframework.amqp.AmqpException;
/**
* @author David Bilge
* @author Gary Russell
@@ -34,7 +36,7 @@ public class TestServiceImpl implements TestServiceInterface {
@Override
public void exceptionThrowingMethod() {
throw new RuntimeException("This is an exception");
throw new AmqpException("This is an exception");
}
@Override

View File

@@ -22,7 +22,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
import java.util.Date;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.core.MessageProperties;

View File

@@ -22,7 +22,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;

View File

@@ -24,7 +24,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageDeliveryMode;

View File

@@ -21,7 +21,7 @@ import static org.assertj.core.api.Assertions.fail;
import java.io.Serializable;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;

View File

@@ -23,10 +23,10 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.amqp.core.MessageProperties;
@@ -35,7 +35,7 @@ import org.springframework.amqp.core.MessageProperties;
* @author Gary Russell
*
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class DefaultClassMapperTests {
@Spy

View File

@@ -24,11 +24,11 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.amqp.core.MessageProperties;
@@ -45,7 +45,7 @@ import com.fasterxml.jackson.databind.type.TypeFactory;
* @author Artem Bilan
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class DefaultJackson2JavaTypeMapperTests {
@Spy
@@ -59,7 +59,7 @@ public class DefaultJackson2JavaTypeMapperTests {
@SuppressWarnings("rawtypes")
private final Class<HashMap> mapClass = HashMap.class;
@Before
@BeforeEach
public void setup() {
this.javaTypeMapper.setTrustedPackages("org.springframework.amqp.support.converter");
}

View File

@@ -24,17 +24,15 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.data.web.JsonPath;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.BeanSerializerFactory;
@@ -47,8 +45,7 @@ import com.fasterxml.jackson.databind.ser.BeanSerializerFactory;
* @author Andreas Asplund
* @author Artem Bilan
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
public class Jackson2JsonMessageConverterTests {
public static final String TRUSTED_PACKAGE = Jackson2JsonMessageConverterTests.class.getPackage().getName();
@@ -60,7 +57,7 @@ public class Jackson2JsonMessageConverterTests {
@Autowired
private Jackson2JsonMessageConverter jsonConverterWithDefaultType;
@Before
@BeforeEach
public void before() {
converter = new Jackson2JsonMessageConverter(TRUSTED_PACKAGE);
trade = new SimpleTrade();

View File

@@ -24,16 +24,14 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import com.fasterxml.jackson.databind.ser.BeanSerializerFactory;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
@@ -44,8 +42,7 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper;
*
* @since 2.1
*/
@ContextConfiguration
@RunWith(SpringRunner.class)
@SpringJUnitConfig
public class Jackson2XmlMessageConverterTests {
public static final String TRUSTED_PACKAGE = Jackson2XmlMessageConverterTests.class.getPackage().getName();
@@ -57,7 +54,7 @@ public class Jackson2XmlMessageConverterTests {
@Autowired
private Jackson2XmlMessageConverter xmlConverterWithDefaultType;
@Before
@BeforeEach
public void before() {
converter = new Jackson2XmlMessageConverter(TRUSTED_PACKAGE);
trade = new SimpleTrade();

View File

@@ -25,7 +25,7 @@ import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;

View File

@@ -19,7 +19,7 @@ package org.springframework.amqp.support.converter;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.messaging.Message;

View File

@@ -27,7 +27,7 @@ import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.amqp.core.Message;

View File

@@ -25,7 +25,7 @@ import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;

View File

@@ -22,7 +22,7 @@ import static org.assertj.core.api.Assertions.fail;
import java.io.Serializable;
import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;

View File

@@ -50,7 +50,7 @@ import org.springframework.core.log.LogAccessor;
public class LogLevelsCondition
implements ExecutionCondition, BeforeEachCallback, AfterEachCallback, BeforeAllCallback, AfterAllCallback {
private static final LogAccessor logger = new LogAccessor(LogFactory.getLog(LogLevelsCondition.class));
private static final LogAccessor LOGGER = new LogAccessor(LogFactory.getLog(LogLevelsCondition.class));
private static final String STORE_ANNOTATION_KEY = "logLevelsAnnotation";
@@ -103,7 +103,7 @@ public class LogLevelsCondition
Optional<Method> testMethod = context.getTestMethod();
if (testMethod.isPresent()
&& this.loggedMethods.putIfAbsent(testMethod.get().getName(), Boolean.TRUE) == null) {
logger.info(() -> "+++++++++++++++++++++++++++++ Begin " + testMethod.get().getName());
LOGGER.info(() -> "+++++++++++++++++++++++++++++ Begin " + testMethod.get().getName());
}
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.amqp.rabbit.test;
package org.springframework.amqp.rabbit.junit;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
@@ -86,7 +86,7 @@ public class RepeatProcessor implements MethodRule {
initializeIfNecessary(target);
if (concurrency <= 0) {
if (this.concurrency <= 0) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
@@ -96,7 +96,8 @@ public class RepeatProcessor implements MethodRule {
base.evaluate();
}
catch (Throwable t) {
throw new IllegalStateException("Failed on iteration: " + i + " of " + repeats + " (started at 0)", t);
throw new IllegalStateException(
"Failed on iteration: " + i + " of " + repeats + " (started at 0)", t);
}
}
}
@@ -110,7 +111,7 @@ public class RepeatProcessor implements MethodRule {
@Override
public void evaluate() throws Throwable {
List<Future<Boolean>> results = new ArrayList<Future<Boolean>>();
ExecutorService executor = Executors.newFixedThreadPool(concurrency);
ExecutorService executor = Executors.newFixedThreadPool(RepeatProcessor.this.concurrency);
CompletionService<Boolean> completionService = new ExecutorCompletionService<Boolean>(executor);
try {
for (int i = 0; i < repeats; i++) {
@@ -142,7 +143,7 @@ public class RepeatProcessor implements MethodRule {
}
private void finalizeIfNecessary(Object target) {
finalizing = true;
this.finalizing = true;
List<FrameworkMethod> afters = new TestClass(target.getClass()).getAnnotatedMethods(After.class);
try {
if (!afters.isEmpty()) {
@@ -160,7 +161,7 @@ public class RepeatProcessor implements MethodRule {
}
}
finally {
finalizing = false;
this.finalizing = false;
}
}
@@ -179,22 +180,23 @@ public class RepeatProcessor implements MethodRule {
catch (Throwable e) {
fail("Unexpected throwable " + e);
}
initialized = true;
this.initialized = true;
}
if (!testClass.getAnnotatedMethods(After.class).isEmpty()) {
initialized = true;
this.initialized = true;
}
}
public boolean isInitialized() {
return initialized;
return this.initialized;
}
public boolean isFinalizing() {
return finalizing;
return this.finalizing;
}
public int getConcurrency() {
return concurrency > 0 ? concurrency : 1;
return this.concurrency > 0 ? this.concurrency : 1;
}
}

View File

@@ -21,7 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.DirectFieldAccessor;

View File

@@ -18,7 +18,7 @@ package org.springframework.amqp.rabbit.repeatable;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;

View File

@@ -17,7 +17,7 @@
package org.springframework.amqp.rabbit.repeatable;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

View File

@@ -17,9 +17,7 @@
package org.springframework.amqp.rabbit.repeatable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.config.RabbitListenerContainerTestFactory;
@@ -37,9 +35,6 @@ import org.springframework.context.annotation.Configuration;
*/
public class EnableRabbitTests extends AbstractRabbitAnnotationDrivenTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Override
@Test
public void rabbitListenerIsRepeatable() {

View File

@@ -20,9 +20,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.TimeUnit;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.amqp.core.AnonymousQueue;
import org.springframework.amqp.core.Queue;
@@ -32,7 +31,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.rabbit.test.RabbitListenerTestHarness.InvocationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -42,7 +41,7 @@ import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
/**
@@ -53,13 +52,11 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
*
*/
@ContextConfiguration(loader = ExampleRabbitListenerCaptureTest.NoBeansOverrideAnnotationConfigContextLoader.class)
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@DirtiesContext
@RabbitAvailable
public class ExampleRabbitListenerCaptureTest {
@Rule
public BrokerRunning brokerRunning = BrokerRunning.isRunning();
@Autowired
private RabbitTemplate rabbitTemplate;

View File

@@ -23,9 +23,7 @@ import static org.mockito.Mockito.verify;
import java.util.concurrent.TimeUnit;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.AnonymousQueue;
import org.springframework.amqp.core.Queue;
@@ -35,7 +33,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.rabbit.test.RabbitListenerTestHarness.InvocationData;
import org.springframework.amqp.rabbit.test.mockito.LatchCountDownAndCallRealMethodAnswer;
import org.springframework.beans.factory.annotation.Autowired;
@@ -44,22 +42,18 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Gary Russell
* @since 1.6
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
@RabbitAvailable
public class ExampleRabbitListenerSpyAndCaptureTest {
@Rule
public BrokerRunning brokerRunning = BrokerRunning.isRunning();
@Autowired
private RabbitTemplate rabbitTemplate;

View File

@@ -23,9 +23,7 @@ import static org.mockito.Mockito.verify;
import java.util.concurrent.TimeUnit;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.AnonymousQueue;
import org.springframework.amqp.core.Queue;
@@ -36,7 +34,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.rabbit.test.mockito.LatchCountDownAndCallRealMethodAnswer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -44,8 +42,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Gary Russell
@@ -54,14 +51,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @since 1.6
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
@RabbitAvailable
public class ExampleRabbitListenerSpyTest {
@Rule
public BrokerRunning brokerRunning = BrokerRunning.isRunning();
@Autowired
private RabbitTemplate rabbitTemplate;

View File

@@ -22,8 +22,7 @@ import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.mock;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
@@ -35,7 +34,7 @@ import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import com.rabbitmq.client.Channel;
@@ -47,7 +46,7 @@ import com.rabbitmq.client.Channel;
* @since 2.0
*
*/
@RunWith(SpringRunner.class)
@SpringJUnitConfig
public class TestRabbitTemplateTests {
@Autowired

View File

@@ -18,10 +18,10 @@ package org.springframework.amqp.rabbit.test.mockito;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.Mockito.spy;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* @author Gary Russell
@@ -33,12 +33,12 @@ public class AnswerTests {
@Test
public void testLambda() {
Foo foo = spy(new Foo());
doAnswer(new LambdaAnswer<String>(true, (i, r) -> r + r)).when(foo).foo(anyString());
willAnswer(new LambdaAnswer<String>(true, (i, r) -> r + r)).given(foo).foo(anyString());
assertThat(foo.foo("foo")).isEqualTo("FOOFOO");
doAnswer(new LambdaAnswer<String>(true, (i, r) -> r + i.getArguments()[0])).when(foo).foo(anyString());
willAnswer(new LambdaAnswer<String>(true, (i, r) -> r + i.getArguments()[0])).given(foo).foo(anyString());
assertThat(foo.foo("foo")).isEqualTo("FOOfoo");
doAnswer(new LambdaAnswer<String>(false, (i, r) ->
"" + i.getArguments()[0] + i.getArguments()[0])).when(foo).foo(anyString());
willAnswer(new LambdaAnswer<String>(false, (i, r) ->
"" + i.getArguments()[0] + i.getArguments()[0])).given(foo).foo(anyString());
assertThat(foo.foo("foo")).isEqualTo("foofoo");
}

View File

@@ -28,9 +28,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Address;
import org.springframework.amqp.core.AmqpMessageReturnedException;
@@ -46,7 +44,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.Confi
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
import org.springframework.amqp.rabbit.listener.adapter.ReplyingMessageListener;
@@ -59,8 +57,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;
@@ -70,14 +67,11 @@ import org.springframework.util.concurrent.ListenableFutureCallback;
*
* @since 1.6
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
@RabbitAvailable
public class AsyncRabbitTemplateTests {
@Rule
public BrokerRunning brokerRunning = BrokerRunning.isRunning();
@Autowired
private AsyncRabbitTemplate asyncTemplate;

View File

@@ -23,7 +23,7 @@ import static org.mockito.Mockito.mock;
import java.util.Collection;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;

View File

@@ -19,7 +19,7 @@ package org.springframework.amqp.rabbit.annotation;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerEndpoint;

View File

@@ -27,9 +27,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
import org.springframework.amqp.ImmediateRequeueAmqpException;
@@ -43,7 +41,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
@@ -51,8 +49,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.SettableListenableFuture;
@@ -63,14 +60,11 @@ import reactor.core.publisher.Mono;
* @since 2.1
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
@RabbitAvailable
public class AsyncListenerTests {
@Rule
public BrokerRunning brokerRunning = BrokerRunning.isRunning();
@Autowired
private EnableRabbitConfig config;

View File

@@ -20,12 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.Level;
import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.AsyncRabbitTemplate;
import org.springframework.amqp.rabbit.AsyncRabbitTemplate.RabbitConverterFuture;
@@ -33,8 +28,8 @@ import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFacto
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.LogLevelAdjuster;
import org.springframework.amqp.rabbit.junit.LogLevels;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
@@ -44,28 +39,24 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Gary Russell
* @since 2.0
*
*/
@RunWith(SpringRunner.class)
@SpringJUnitConfig
@DirtiesContext
@RabbitAvailable(queues = { ComplexTypeJsonIntegrationTests.TEST_QUEUE, ComplexTypeJsonIntegrationTests.TEST_QUEUE2 })
@LogLevels(classes = { RabbitTemplate.class,
MessagingMessageListenerAdapter.class,
SimpleMessageListenerContainer.class })
public class ComplexTypeJsonIntegrationTests {
private static final String TEST_QUEUE = "test.complex.send.and.receive";
public static final String TEST_QUEUE = "test.complex.send.and.receive";
private static final String TEST_QUEUE2 = "test.complex.receive";
@ClassRule
public static BrokerRunning brokerRunning = BrokerRunning.isRunningWithEmptyQueues(TEST_QUEUE, TEST_QUEUE2);
@Rule
public LogLevelAdjuster adjuster = new LogLevelAdjuster(Level.DEBUG, RabbitTemplate.class,
MessagingMessageListenerAdapter.class,
SimpleMessageListenerContainer.class);
public static final String TEST_QUEUE2 = "test.complex.receive";
@Autowired
private RabbitTemplate rabbitTemplate;
@@ -73,11 +64,6 @@ public class ComplexTypeJsonIntegrationTests {
@Autowired
private AsyncRabbitTemplate asyncTemplate;
@AfterClass
public static void tearDown() {
brokerRunning.removeTestQueues();
}
private static Foo<Bar<Baz, Qux>> makeAFoo() {
Foo<Bar<Baz, Qux>> foo = new Foo<>();
Bar<Baz, Qux> bar = new Bar<>();

View File

@@ -21,24 +21,21 @@ import static org.mockito.Mockito.mock;
import java.io.Serializable;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
@@ -47,14 +44,11 @@ import org.springframework.transaction.annotation.Transactional;
* @author Artem Bilan
* @since 1.5.5
*/
@ContextConfiguration(classes = EnableRabbitCglibProxyTests.Config.class)
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
@RabbitAvailable
public class EnableRabbitCglibProxyTests {
@ClassRule
public static final BrokerRunning brokerRunning = BrokerRunning.isRunning();
@Autowired
private RabbitTemplate rabbitTemplate;
@@ -63,7 +57,8 @@ public class EnableRabbitCglibProxyTests {
this.rabbitTemplate.setReplyTimeout(600000);
Foo foo = new Foo();
foo.field = "foo";
assertThat(this.rabbitTemplate.convertSendAndReceive("auto.exch.test", "auto.rk.test", foo)).isEqualTo("Reply: foo: AUTO.RK.TEST");
assertThat(this.rabbitTemplate.convertSendAndReceive("auto.exch.test", "auto.rk.test", foo))
.isEqualTo("Reply: foo: AUTO.RK.TEST");
}
@Configuration

View File

@@ -23,9 +23,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.AnonymousQueue;
import org.springframework.amqp.core.Queue;
@@ -34,7 +32,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.rabbit.listener.ListenerContainerIdleEvent;
import org.springframework.amqp.rabbit.listener.MessageListenerContainer;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
@@ -45,22 +43,18 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Gary Russell
* @since 1.6
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
@RabbitAvailable
public class EnableRabbitIdleContainerTests {
@Rule
public BrokerRunning brokerRunning = BrokerRunning.isRunning();
@Autowired
private Listener listener;

View File

@@ -43,11 +43,9 @@ import java.util.concurrent.atomic.AtomicReference;
import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
@@ -68,8 +66,12 @@ import org.springframework.amqp.rabbit.connection.ConnectionNameStrategy;
import org.springframework.amqp.rabbit.connection.SimplePropertyValueConnectionNameStrategy;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.BrokerRunningSupport;
import org.springframework.amqp.rabbit.junit.LogLevels;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.rabbit.junit.RabbitAvailableCondition;
import org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler;
import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.MessageListenerContainer;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
@@ -120,13 +122,8 @@ import org.springframework.messaging.support.MessageBuilder;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.TestExecutionListeners.MergeMode;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AbstractTestExecutionListener;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
@@ -145,33 +142,28 @@ import com.rabbitmq.http.client.domain.QueueInfo;
*
* @since 1.4
*/
@ContextConfiguration(classes = EnableRabbitIntegrationTests.EnableRabbitConfig.class)
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig(EnableRabbitIntegrationTests.EnableRabbitConfig.class)
@DirtiesContext
@TestExecutionListeners(mergeMode = MergeMode.MERGE_WITH_DEFAULTS,
listeners = EnableRabbitIntegrationTests.DeleteQueuesExecutionListener.class)
@TestPropertySource(properties = "spring.application.name=testConnectionName")
@RabbitAvailable(queues = { "test.manual.container", "test.no.listener.yet",
"test.simple", "test.header", "test.message", "test.reply", "test.sendTo", "test.sendTo.reply",
"test.sendTo.spel", "test.sendTo.reply.spel", "test.sendTo.runtimespel", "test.sendTo.reply.runtimespel",
"test.sendTo.runtimespelsource", "test.sendTo.runtimespelsource.reply",
"test.intercepted", "test.intercepted.withReply",
"test.invalidPojo", "differentTypes", "differentTypes2", "differentTypes3",
"test.inheritance", "test.inheritance.class",
"test.comma.1", "test.comma.2", "test.comma.3", "test.comma.4", "test,with,commas",
"test.converted", "test.converted.list", "test.converted.array", "test.converted.args1",
"test.converted.args2", "test.converted.message", "test.notconverted.message",
"test.notconverted.channel", "test.notconverted.messagechannel", "test.notconverted.messagingmessage",
"test.converted.foomessage", "test.notconverted.messagingmessagenotgeneric", "test.simple.direct",
"test.simple.direct2", "test.generic.list", "test.generic.map",
"amqp656dlq", "test.simple.declare", "test.return.exceptions", "test.pojo.errors", "test.pojo.errors2",
"test.messaging.message", "test.amqp.message", "test.bytes.to.string", "test.projection",
"manual.acks.1", "manual.acks.2", "erit.batch.1", "erit.batch.2", "erit.batch.3" },
purgeAfterEach = false)
public class EnableRabbitIntegrationTests {
@ClassRule
public static final BrokerRunning brokerRunning = BrokerRunning.isRunningWithEmptyQueues(
"test.manual.container", "test.no.listener.yet",
"test.simple", "test.header", "test.message", "test.reply", "test.sendTo", "test.sendTo.reply",
"test.sendTo.spel", "test.sendTo.reply.spel", "test.sendTo.runtimespel", "test.sendTo.reply.runtimespel",
"test.sendTo.runtimespelsource", "test.sendTo.runtimespelsource.reply",
"test.intercepted", "test.intercepted.withReply",
"test.invalidPojo", "differentTypes", "differentTypes2", "differentTypes3",
"test.inheritance", "test.inheritance.class",
"test.comma.1", "test.comma.2", "test.comma.3", "test.comma.4", "test,with,commas",
"test.converted", "test.converted.list", "test.converted.array", "test.converted.args1",
"test.converted.args2", "test.converted.message", "test.notconverted.message",
"test.notconverted.channel", "test.notconverted.messagechannel", "test.notconverted.messagingmessage",
"test.converted.foomessage", "test.notconverted.messagingmessagenotgeneric", "test.simple.direct",
"test.simple.direct2", "test.generic.list", "test.generic.map",
"amqp656dlq", "test.simple.declare", "test.return.exceptions", "test.pojo.errors", "test.pojo.errors2",
"test.messaging.message", "test.amqp.message", "test.bytes.to.string", "test.projection",
"manual.acks.1", "manual.acks.2", "erit.batch.1", "erit.batch.2", "erit.batch.3");
@Autowired
private RabbitTemplate rabbitTemplate;
@@ -217,15 +209,16 @@ public class EnableRabbitIntegrationTests {
@Autowired
private MyService myService;
@BeforeClass
@BeforeAll
public static void setUp() {
System.setProperty(RabbitListenerAnnotationBeanPostProcessor.RABBIT_EMPTY_STRING_ARGUMENTS_PROPERTY,
"test-empty");
}
@AfterClass
@AfterAll
public static void tearDown() {
System.getProperties().remove(RabbitListenerAnnotationBeanPostProcessor.RABBIT_EMPTY_STRING_ARGUMENTS_PROPERTY);
RabbitAvailableCondition.getBrokerRunning().removeTestQueues("sendTo.replies", "sendTo.replies.spel");
}
@Test
@@ -307,6 +300,7 @@ public class EnableRabbitIntegrationTests {
}
@Test
@LogLevels(classes = { DirectMessageListenerContainer.class, RabbitTemplate.class })
public void simpleDirectEndpointWithConcurrency() {
String reply = (String) rabbitTemplate.convertSendAndReceive("test.simple.direct2", "foo");
assertThat(reply).startsWith("FOOfoo");
@@ -1657,6 +1651,7 @@ public class EnableRabbitIntegrationTests {
@Bean
public ConnectionFactory rabbitConnectionFactory() {
BrokerRunningSupport brokerRunning = RabbitAvailableCondition.getBrokerRunning();
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.setHost(brokerRunning.getHostName());
connectionFactory.setPort(brokerRunning.getPort());
@@ -1895,6 +1890,7 @@ public class EnableRabbitIntegrationTests {
@Bean
public ConnectionFactory rabbitConnectionFactory() {
BrokerRunningSupport brokerRunning = RabbitAvailableCondition.getBrokerRunning();
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.setHost(brokerRunning.getHostName());
connectionFactory.setPort(brokerRunning.getPort());
@@ -1982,6 +1978,7 @@ public class EnableRabbitIntegrationTests {
@Bean
public ConnectionFactory rabbitConnectionFactory() {
BrokerRunningSupport brokerRunning = RabbitAvailableCondition.getBrokerRunning();
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.setHost(brokerRunning.getHostName());
connectionFactory.setPort(brokerRunning.getPort());
@@ -2132,25 +2129,6 @@ public class EnableRabbitIntegrationTests {
}
}
/**
* Defer queue deletion until after the context has been stopped by the
* {@link DirtiesContext}.
*
*/
public static class DeleteQueuesExecutionListener extends AbstractTestExecutionListener {
@Override
public void afterTestClass(TestContext testContext) {
brokerRunning.removeTestQueues("sendTo.replies", "sendTo.replies.spel");
}
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
}
interface Sample {
String getUsername();

View File

@@ -25,7 +25,7 @@ import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.rabbit.config.MessageListenerTestContainer;

View File

@@ -35,8 +35,8 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.CustomExchange;
@@ -265,7 +265,7 @@ public class RabbitListenerAnnotationBeanPostProcessorTests {
}
@Test
@Ignore("To slow and doesn't have 100% confirmation")
@Disabled("Too slow and doesn't have 100% confirmation")
public void concurrency() throws InterruptedException, ExecutionException {
final int concurrencyLevel = 8;
final ExecutorService executorService = Executors.newFixedThreadPool(concurrencyLevel);

View File

@@ -21,7 +21,7 @@ import static org.assertj.core.api.Assertions.fail;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;

View File

@@ -21,8 +21,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.concurrent.ExecutorService;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.ConfirmType;
@@ -48,7 +48,7 @@ public final class ConnectionFactoryParserTests {
private DefaultListableBeanFactory beanFactory;
@Before
@BeforeEach
public void setUpDefaultBeanFactory() throws Exception {
beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);

View File

@@ -18,21 +18,20 @@ package org.springframework.amqp.rabbit.config;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.rabbit.junit.RabbitAvailableCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Dave Syer
@@ -40,13 +39,11 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Gunnar Hillert
* @author Artem Bilan
*/
@RunWith(SpringRunner.class)
@SpringJUnitConfig
@DirtiesContext
@RabbitAvailable
public final class ExchangeParserIntegrationTests {
@ClassRule
public static BrokerRunning brokerIsRunning = BrokerRunning.isRunning();
@Autowired
private ConnectionFactory connectionFactory;
@@ -68,10 +65,11 @@ public final class ExchangeParserIntegrationTests {
@Qualifier("bucket.test")
private Queue queue3;
@BeforeClass
@AfterClass
@BeforeAll
@AfterAll
public static void clean() {
brokerIsRunning.deleteExchanges("fanoutTest", "directTest", "topicTest", "headersTest", "headersTestMulti");
RabbitAvailableCondition.getBrokerRunning().deleteExchanges("fanoutTest", "directTest", "topicTest",
"headersTest", "headersTestMulti");
}
@Test

View File

@@ -20,8 +20,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.DirectExchange;
@@ -45,7 +45,7 @@ public final class ExchangeParserTests {
private DefaultListableBeanFactory beanFactory;
@Before
@BeforeEach
public void setUp() throws Exception {
beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);

View File

@@ -25,8 +25,8 @@ import java.util.Collection;
import java.util.Map;
import org.aopalliance.aop.Advice;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.core.Queue;
@@ -55,7 +55,7 @@ public class ListenerContainerParserTests {
private DefaultListableBeanFactory beanFactory;
@Before
@BeforeEach
public void setUp() {
beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);

View File

@@ -22,9 +22,9 @@ import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.core.Queue;
@@ -49,13 +49,13 @@ public final class ListenerContainerPlaceholderParserTests {
private GenericApplicationContext context;
@Before
@BeforeEach
public void setUp() {
this.context = new GenericXmlApplicationContext(
new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass()));
}
@After
@AfterEach
public void closeBeanFactory() throws Exception {
if (this.context != null) {
CachingConnectionFactory cf = this.context.getBean(CachingConnectionFactory.class);

View File

@@ -19,16 +19,15 @@ package org.springframework.amqp.rabbit.config;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.SingleConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.StandardEnvironment;
@@ -41,16 +40,14 @@ import com.rabbitmq.client.Channel;
* @since 1.2
*
*/
@RabbitAvailable
public class MismatchedQueueDeclarationTests {
@Rule
public BrokerRunning brokerIsRunning = BrokerRunning.isRunning();
private SingleConnectionFactory connectionFactory;
private RabbitAdmin admin;
@Before
@BeforeEach
public void setup() throws Exception {
connectionFactory = new SingleConnectionFactory();
connectionFactory.setHost("localhost");
@@ -58,7 +55,7 @@ public class MismatchedQueueDeclarationTests {
deleteQueues();
}
@After
@AfterEach
public void deleteQueues() throws Exception {
this.admin.deleteQueue("mismatch.foo");
this.admin.deleteQueue("mismatch.bar");
@@ -67,7 +64,7 @@ public class MismatchedQueueDeclarationTests {
}
@Test
@Ignore
@Disabled
public void testAdminFailsWithMismatchedQueue() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setConfigLocation("org/springframework/amqp/rabbit/config/MismatchedQueueDeclarationTests-context.xml");

View File

@@ -20,15 +20,13 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
@@ -36,8 +34,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @since 1.0.1
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class QueueArgumentsParserTests {

View File

@@ -20,15 +20,15 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Properties;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.rabbit.junit.RabbitAvailableCondition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
@@ -40,14 +40,12 @@ import org.springframework.core.io.ClassPathResource;
* @since 1.0
*
*/
@RabbitAvailable
public final class QueueParserIntegrationTests {
@ClassRule
public static BrokerRunning brokerIsRunning = BrokerRunning.isRunning();
private DefaultListableBeanFactory beanFactory;
@Before
@BeforeEach
public void setUpDefaultBeanFactory() throws Exception {
beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
@@ -60,7 +58,7 @@ public final class QueueParserIntegrationTests {
Queue queue = beanFactory.getBean("arguments", Queue.class);
assertThat(queue).isNotNull();
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(
brokerIsRunning.getConnectionFactory());
RabbitAvailableCondition.getBrokerRunning().getConnectionFactory());
RabbitTemplate template = new RabbitTemplate(connectionFactory);
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
rabbitAdmin.deleteQueue(queue.getName());
@@ -79,7 +77,7 @@ public final class QueueParserIntegrationTests {
}
connectionFactory.destroy();
brokerIsRunning.deleteQueues("arguments");
RabbitAvailableCondition.getBrokerRunning().deleteQueues("arguments");
}
}

View File

@@ -16,8 +16,8 @@
package org.springframework.amqp.rabbit.config;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
@@ -30,13 +30,14 @@ import org.springframework.core.io.ClassPathResource;
*/
public class QueueParserPlaceholderTests extends QueueParserTests {
@Before
@BeforeEach
@Override
public void setUpDefaultBeanFactory() {
beanFactory = new GenericXmlApplicationContext(new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass()));
beanFactory = new GenericXmlApplicationContext(
new ClassPathResource(getClass().getSimpleName() + "-context.xml", getClass()));
}
@After
@AfterEach
public void closeBeanFactory() {
if (beanFactory != null) {
((ConfigurableApplicationContext) beanFactory).close();

View File

@@ -17,9 +17,10 @@
package org.springframework.amqp.rabbit.config;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.AnonymousQueue;
import org.springframework.amqp.core.Queue;
@@ -41,7 +42,7 @@ public class QueueParserTests {
protected BeanFactory beanFactory;
@Before
@BeforeEach
public void setUpDefaultBeanFactory() throws Exception {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
@@ -176,16 +177,13 @@ public class QueueParserTests {
assertThat(queue.shouldDeclare()).isFalse();
}
@Test(expected = BeanDefinitionStoreException.class)
public void testIllegalAnonymousQueue() throws Exception {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName()
+ "IllegalAnonymous-context.xml", getClass()));
Queue queue = beanFactory.getBean("anonymous", Queue.class);
assertThat(queue).isNotNull();
assertThat(queue.getName()).isNotSameAs("bucket");
assertThat(queue instanceof AnonymousQueue).isTrue();
@Test
public void testIllegalAnonymousQueue() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() ->
reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName()
+ "IllegalAnonymous-context.xml", getClass())));
}
}

View File

@@ -24,8 +24,8 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
@@ -57,7 +57,7 @@ public class RabbitListenerContainerFactoryIntegrationTests {
private final RabbitEndpointSampleBean sample = new RabbitEndpointSampleBean();
@Before
@BeforeEach
public void setup() {
initializeFactory(factory);
}

View File

@@ -24,7 +24,7 @@ import java.util.List;
import java.util.concurrent.Executor;
import org.aopalliance.aop.Advice;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.core.MessagePostProcessor;

View File

@@ -20,8 +20,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.AnonymousQueue;
import org.springframework.amqp.core.Binding;
@@ -47,7 +47,7 @@ public final class RabbitNamespaceHandlerTests {
private DefaultListableBeanFactory beanFactory;
@Before
@BeforeEach
public void setUp() throws Exception {
beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);

View File

@@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.aopalliance.intercept.MethodInterceptor;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.ImmediateRequeueAmqpException;
import org.springframework.amqp.core.AmqpTemplate;

View File

@@ -21,7 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.mockito.Mockito.mock;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.core.Queue;

View File

@@ -20,8 +20,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Queue;
@@ -46,7 +46,7 @@ public final class TemplateParserTests {
private DefaultListableBeanFactory beanFactory;
@Before
@BeforeEach
public void setUpDefaultBeanFactory() throws Exception {
beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);

View File

@@ -21,7 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
import java.util.concurrent.Semaphore;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -59,7 +59,7 @@ public class RabbitReconnectProblemTests {
final Queue myQueue = new Queue("my-queue");
@Before
@BeforeEach
public void setup() {
admin.declareQueue(myQueue);
}

View File

@@ -42,7 +42,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.Binding;

View File

@@ -22,7 +22,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.IOException;
import java.util.UUID;
import org.junit.Assume;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -381,14 +380,14 @@ public class RabbitAdminIntegrationTests {
catch (AmqpIOException e) {
if (RabbitUtils.isExchangeDeclarationFailure(e)
&& e.getCause().getCause().getMessage().contains("exchange type 'x-delayed-message'")) {
Assume.assumeTrue("Broker does not have the delayed message exchange plugin installed", false);
return;
}
else {
throw e;
}
}
catch (@SuppressWarnings("unused") AutoRecoverConnectionNotCurrentlyOpenException e) {
Assume.assumeTrue("Broker does not have the delayed message exchange plugin installed", false);
return;
}
this.rabbitAdmin.declareQueue(queue);
this.rabbitAdmin.declareBinding(binding);

View File

@@ -19,7 +19,9 @@ package org.springframework.amqp.rabbit.listener;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -29,13 +31,12 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.logging.log4j.Level;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.core.BatchMessageListener;
@@ -44,10 +45,11 @@ import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.BrokerTestUtils;
import org.springframework.amqp.rabbit.junit.LogLevelAdjuster;
import org.springframework.amqp.rabbit.junit.LongRunningIntegrationTest;
import org.springframework.amqp.rabbit.junit.JUnitUtils;
import org.springframework.amqp.rabbit.junit.JUnitUtils.LevelsContainer;
import org.springframework.amqp.rabbit.junit.LogLevels;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.beans.factory.DisposableBean;
@@ -65,106 +67,106 @@ import com.rabbitmq.client.Channel;
* @since 1.0
*
*/
@RunWith(Parameterized.class)
@RabbitAvailable(queues = SimpleMessageListenerContainerIntegrationTests.TEST_QUEUE)
@LogLevels(level = "OFF", classes = { RabbitTemplate.class,
ConditionalRejectingErrorHandler.class,
SimpleMessageListenerContainer.class, BlockingQueueConsumer.class, CachingConnectionFactory.class })
public class SimpleMessageListenerContainerIntegrationTests {
public static final String TEST_QUEUE = "test.queue.SimpleMessageListenerContainerIntegrationTests";
private static Log logger = LogFactory.getLog(SimpleMessageListenerContainerIntegrationTests.class);
private final Queue queue = new Queue("test.queue");
private static LevelsContainer levelsContainer;
private final Queue queue = new Queue(TEST_QUEUE);
private final RabbitTemplate template = new RabbitTemplate();
private final int concurrentConsumers;
private int concurrentConsumers;
private final AcknowledgeMode acknowledgeMode;
private AcknowledgeMode acknowledgeMode;
@Rule
public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
// @Rule
// public LogLevelAdjuster testLogLevels = new LogLevelAdjuster(Level.DEBUG,
// SimpleMessageListenerContainerIntegrationTests.class);
@Rule
public LogLevelAdjuster logLevels = new LogLevelAdjuster(Level.OFF, RabbitTemplate.class,
ConditionalRejectingErrorHandler.class,
SimpleMessageListenerContainer.class, BlockingQueueConsumer.class, CachingConnectionFactory.class);
@Rule
public LogLevelAdjuster testLogLevels = new LogLevelAdjuster(Level.DEBUG,
SimpleMessageListenerContainerIntegrationTests.class);
@Rule
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(queue.getName());
private final int messageCount;
private int messageCount;
private SimpleMessageListenerContainer container;
private final int txSize;
private int txSize;
private final boolean externalTransaction;
private boolean externalTransaction;
private final boolean transactional;
private boolean transactional;
public SimpleMessageListenerContainerIntegrationTests(int messageCount, int concurrency,
AcknowledgeMode acknowledgeMode, boolean transactional, int txSize, boolean externalTransaction) {
this.messageCount = messageCount;
this.concurrentConsumers = concurrency;
this.acknowledgeMode = acknowledgeMode;
this.transactional = transactional;
this.txSize = txSize;
this.externalTransaction = externalTransaction;
}
@Parameters
public static List<Object[]> getParameters() {
return Arrays.asList(
params(0, 1, 1, AcknowledgeMode.AUTO),
params(1, 1, 1, AcknowledgeMode.NONE),
params(2, 4, 1, AcknowledgeMode.AUTO),
extern(3, 4, 1, AcknowledgeMode.AUTO),
params(4, 4, 1, AcknowledgeMode.AUTO, false),
params(5, 2, 2, AcknowledgeMode.AUTO),
params(6, 2, 2, AcknowledgeMode.NONE),
params(7, 20, 4, AcknowledgeMode.AUTO),
params(8, 20, 4, AcknowledgeMode.NONE),
params(9, 300, 4, AcknowledgeMode.AUTO),
params(10, 300, 4, AcknowledgeMode.NONE),
params(11, 300, 4, AcknowledgeMode.AUTO, 10)
params(1, 1, AcknowledgeMode.AUTO),
params(1, 1, AcknowledgeMode.NONE),
params(4, 1, AcknowledgeMode.AUTO),
extern(4, 1, AcknowledgeMode.AUTO),
params(4, 1, AcknowledgeMode.AUTO, false),
params(2, 2, AcknowledgeMode.AUTO),
params(2, 2, AcknowledgeMode.NONE),
params(20, 4, AcknowledgeMode.AUTO),
params(20, 4, AcknowledgeMode.NONE),
params(300, 4, AcknowledgeMode.AUTO),
params(300, 4, AcknowledgeMode.NONE),
params(300, 4, AcknowledgeMode.AUTO, 10)
);
}
private static Object[] params(int i, int messageCount, int concurrency, AcknowledgeMode acknowledgeMode,
private static Object[] params(int messageCount, int concurrency, AcknowledgeMode acknowledgeMode,
boolean transactional, int txSize) {
// "i" is just a counter to make it easier to identify the test in the log
return new Object[] { messageCount, concurrency, acknowledgeMode, transactional, txSize, false };
}
private static Object[] params(int i, int messageCount, int concurrency, AcknowledgeMode acknowledgeMode, int txSize) {
// For this test always us a transaction if it makes sense...
return params(i, messageCount, concurrency, acknowledgeMode, acknowledgeMode.isTransactionAllowed(), txSize);
private static Object[] params(int messageCount, int concurrency, AcknowledgeMode acknowledgeMode, int txSize) {
return params(messageCount, concurrency, acknowledgeMode, acknowledgeMode.isTransactionAllowed(), txSize);
}
private static Object[] params(int i, int messageCount, int concurrency, AcknowledgeMode acknowledgeMode,
private static Object[] params(int messageCount, int concurrency, AcknowledgeMode acknowledgeMode,
boolean transactional) {
return params(i, messageCount, concurrency, acknowledgeMode, transactional, 1);
return params(messageCount, concurrency, acknowledgeMode, transactional, 1);
}
private static Object[] params(int i, int messageCount, int concurrency, AcknowledgeMode acknowledgeMode) {
return params(i, messageCount, concurrency, acknowledgeMode, 1);
private static Object[] params(int messageCount, int concurrency, AcknowledgeMode acknowledgeMode) {
return params(messageCount, concurrency, acknowledgeMode, 1);
}
private static Object[] extern(int i, int messageCount, int concurrency, AcknowledgeMode acknowledgeMode) {
private static Object[] extern(int messageCount, int concurrency, AcknowledgeMode acknowledgeMode) {
return new Object[] { messageCount, concurrency, acknowledgeMode, true, 1, true };
}
@Before
@BeforeAll
public static void debugLog() {
levelsContainer = JUnitUtils.adjustLogLevels("SimpleMessageListenerContainerIntegrationTests",
Collections.singletonList(SimpleMessageListenerContainerIntegrationTests.class),
Collections.emptyList(), Level.DEBUG);
}
@AfterAll
public static void unDebugLog() {
if (levelsContainer != null) {
JUnitUtils.revertLevels("SimpleMessageListenerContainerIntegrationTests", levelsContainer);
}
}
@BeforeEach
public void declareQueue() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.setHost("localhost");
connectionFactory.setChannelCacheSize(concurrentConsumers);
connectionFactory.setChannelCacheSize(4);
connectionFactory.setPort(BrokerTestUtils.getPort());
template.setConnectionFactory(connectionFactory);
}
@After
@AfterEach
public void clear() throws Exception {
// Wait for broker communication to finish before trying to stop container
logger.debug("Shutting down at end of test");
@@ -172,64 +174,101 @@ public class SimpleMessageListenerContainerIntegrationTests {
container.shutdown();
}
((DisposableBean) template.getConnectionFactory()).destroy();
this.brokerIsRunning.removeTestQueues();
}
@Test
public void testPojoListenerSunnyDay() throws Exception {
@ParameterizedTest
@MethodSource("getParameters")
public void testPojoListenerSunnyDay(int count, int concurrency, AcknowledgeMode ackMode, boolean tx, int txSz,
boolean externalTx) throws Exception {
loadParams(count, concurrency, ackMode, tx, txSz, externalTx);
CountDownLatch latch = new CountDownLatch(messageCount);
doSunnyDayTest(latch, new MessageListenerAdapter(new PojoListener(latch)));
}
@Test
public void testListenerSunnyDay() throws Exception {
@ParameterizedTest
@MethodSource("getParameters")
public void testListenerSunnyDay(int count, int concurrency, AcknowledgeMode ackMode, boolean tx, int txSz,
boolean externalTx) throws Exception {
loadParams(count, concurrency, ackMode, tx, txSz, externalTx);
CountDownLatch latch = new CountDownLatch(messageCount);
doSunnyDayTest(latch, new Listener(latch));
}
@Test
public void testChannelAwareListenerSunnyDay() throws Exception {
@ParameterizedTest
@MethodSource("getParameters")
public void testChannelAwareListenerSunnyDay(int count, int concurrency, AcknowledgeMode ackMode, boolean tx, int txSz,
boolean externalTx) throws Exception {
loadParams(count, concurrency, ackMode, tx, txSz, externalTx);
CountDownLatch latch = new CountDownLatch(messageCount);
doSunnyDayTest(latch, new ChannelAwareListener(latch));
}
@Test
public void testPojoListenerWithException() throws Exception {
@ParameterizedTest
@MethodSource("getParameters")
public void testPojoListenerWithException(int count, int concurrency, AcknowledgeMode ackMode, boolean tx, int txSz,
boolean externalTx) throws Exception {
loadParams(count, concurrency, ackMode, tx, txSz, externalTx);
CountDownLatch latch = new CountDownLatch(messageCount);
doListenerWithExceptionTest(latch, new MessageListenerAdapter(new PojoListener(latch, true)));
}
@Test
public void testListenerWithException() throws Exception {
@ParameterizedTest
@MethodSource("getParameters")
public void testListenerWithException(int count, int concurrency, AcknowledgeMode ackMode, boolean tx, int txSz,
boolean externalTx) throws Exception {
loadParams(count, concurrency, ackMode, tx, txSz, externalTx);
CountDownLatch latch = new CountDownLatch(messageCount);
doListenerWithExceptionTest(latch, new Listener(latch, true));
}
@Test
public void testChannelAwareListenerWithException() throws Exception {
@ParameterizedTest
@MethodSource("getParameters")
public void testChannelAwareListenerWithException(int count, int concurrency, AcknowledgeMode ackMode, boolean tx, int txSz,
boolean externalTx) throws Exception {
loadParams(count, concurrency, ackMode, tx, txSz, externalTx);
CountDownLatch latch = new CountDownLatch(messageCount);
doListenerWithExceptionTest(latch, new ChannelAwareListener(latch, true));
}
@Test
public void testNullQueue() {
@ParameterizedTest
@MethodSource("getParameters")
public void testNullQueue(int count, int concurrency, AcknowledgeMode ackMode, boolean tx, int txSz,
boolean externalTx) {
loadParams(count, concurrency, ackMode, tx, txSz, externalTx);
assertThatIllegalArgumentException()
.isThrownBy(() -> container = createContainer(m -> { }, (Queue) null));
}
@Test
public void testNullQueueName() {
@ParameterizedTest
@MethodSource("getParameters")
public void testNullQueueName(int count, int concurrency, AcknowledgeMode ackMode, boolean tx, int txSz,
boolean externalTx) {
loadParams(count, concurrency, ackMode, tx, txSz, externalTx);
assertThatIllegalArgumentException()
.isThrownBy(() -> container = createContainer(m -> { }, (String) null));
}
@Test
public void testConsumerBatching() throws InterruptedException {
AtomicReference<List<Message>> received = new AtomicReference<>();
@ParameterizedTest
@MethodSource("getParameters")
public void testConsumerBatching(int count, int concurrency, AcknowledgeMode ackMode, boolean tx, int txSz,
boolean externalTx) throws InterruptedException {
loadParams(count, concurrency, ackMode, tx, txSz, externalTx);
AtomicReference<List<Message>> received = new AtomicReference<>(new ArrayList<>());
CountDownLatch latch = new CountDownLatch(1);
this.container = createContainer((BatchMessageListener) messages -> {
received.set(messages);
latch.countDown();
received.get().addAll(messages);
if (received.get().size() == this.messageCount) {
latch.countDown();
}
}, this.queue);
this.container.setConsumerBatchEnabled(true);
this.container.setBatchSize(this.messageCount);
@@ -319,6 +358,17 @@ public class SimpleMessageListenerContainerIntegrationTests {
return container;
}
private void loadParams(int count, int concurrency, AcknowledgeMode ackMode, boolean tx, int txSz,
boolean externalTx) {
this.messageCount = count;
this.concurrentConsumers = concurrency;
this.acknowledgeMode = ackMode;
this.transactional = tx;
this.txSize = txSz;
this.externalTransaction = externalTx;
}
public static class PojoListener {
private final AtomicInteger count = new AtomicInteger();

View File

@@ -34,10 +34,9 @@ import java.util.concurrent.LinkedBlockingQueue;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
@@ -48,7 +47,8 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.rabbit.junit.RabbitAvailableCondition;
import org.springframework.amqp.utils.test.TestUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.util.ReflectionTestUtils;
@@ -68,27 +68,25 @@ import com.rabbitmq.client.impl.CRDemoMechanism;
*
* @since 1.6
*/
@RabbitAvailable
public class AmqpAppenderTests {
@ClassRule
public static BrokerRunning brokerRunning = BrokerRunning.isRunning();
private static final LoggerContext LOGGER_CONTEXT = (LoggerContext) LogManager.getContext(false);
private static final URI ORIGINAL_LOGGER_CONFIG = LOGGER_CONTEXT.getConfigLocation();
@BeforeClass
@BeforeAll
public static void setup() throws IOException {
LOGGER_CONTEXT.setConfigLocation(new ClassPathResource("log4j2-amqp-appender.xml").getURI());
LOGGER_CONTEXT.reconfigure();
}
@AfterClass
@AfterAll
public static void teardown() {
LOGGER_CONTEXT.setConfigLocation(ORIGINAL_LOGGER_CONFIG);
LOGGER_CONTEXT.reconfigure();
brokerRunning.deleteQueues("log4jTest", "log4j2Test");
brokerRunning.deleteExchanges("log4j2Test", "log4j2Test_uri");
RabbitAvailableCondition.getBrokerRunning().deleteQueues("log4jTest", "log4j2Test");
RabbitAvailableCondition.getBrokerRunning().deleteExchanges("log4j2Test", "log4j2Test_uri");
}
@Test

View File

@@ -27,11 +27,9 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
@@ -40,13 +38,12 @@ import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.SingleConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import ch.qos.logback.classic.Logger;
@@ -57,17 +54,14 @@ import ch.qos.logback.classic.Logger;
*
* @since 1.4
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AmqpAppenderConfiguration.class)
@SpringJUnitConfig(classes = AmqpAppenderConfiguration.class)
@DirtiesContext
@RabbitAvailable
public class AmqpAppenderIntegrationTests {
/* logback will automatically find lockback-test.xml */
private static final Logger log = (Logger) LoggerFactory.getLogger(AmqpAppenderIntegrationTests.class);
@Rule
public BrokerRunning brokerIsRunning = BrokerRunning.isRunning();
@Autowired
private ApplicationContext applicationContext;
@@ -82,13 +76,13 @@ public class AmqpAppenderIntegrationTests {
private SimpleMessageListenerContainer listenerContainer;
@Before
@BeforeEach
public void setUp() {
this.listenerContainer = this.applicationContext.getBean(SimpleMessageListenerContainer.class);
MDC.clear();
}
@After
@AfterEach
public void tearDown() {
MDC.clear();
listenerContainer.shutdown();

View File

@@ -30,7 +30,7 @@ import static org.mockito.Mockito.verify;
import java.net.URI;
import java.net.URISyntaxException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.amqp.UncategorizedAmqpException;

View File

@@ -22,34 +22,28 @@ import static org.assertj.core.api.Assertions.fail;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.remoting.RemoteProxyFailureException;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Gary Russell
* @since 1.2
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
@RabbitAvailable
public class RemotingTests {
@ClassRule
public static BrokerRunning brokerRunning = BrokerRunning.isRunning();
@Autowired
private ServiceInterface client;
@@ -57,8 +51,8 @@ public class RemotingTests {
private static String receivedMessage;
@BeforeClass
@AfterClass
@BeforeAll
@AfterAll
public static void setupAndCleanUp() {
CachingConnectionFactory cf = new CachingConnectionFactory("localhost");
RabbitAdmin admin = new RabbitAdmin(cf);

View File

@@ -34,12 +34,9 @@ import java.util.concurrent.TimeUnit;
import org.aopalliance.aop.Advice;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.logging.log4j.Level;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.amqp.core.Message;
@@ -47,8 +44,9 @@ import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.config.StatefulRetryOperationsInterceptorFactoryBean;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.LogLevelAdjuster;
import org.springframework.amqp.rabbit.junit.LogLevels;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.amqp.rabbit.junit.RabbitAvailableCondition;
import org.springframework.amqp.rabbit.listener.BlockingQueueConsumer;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
@@ -67,25 +65,21 @@ import org.springframework.retry.support.RetryTemplate;
* @since 1.1.2
*
*/
@RabbitAvailable
@LogLevels(classes = {BlockingQueueConsumer.class,
MissingIdRetryTests.class,
RetryTemplate.class, SimpleRetryPolicy.class})
public class MissingIdRetryTests {
private final Log logger = LogFactory.getLog(MissingIdRetryTests.class);
private volatile CountDownLatch latch;
@ClassRule
public static BrokerRunning brokerIsRunning = BrokerRunning.isRunning();
@Rule
public LogLevelAdjuster adjuster = new LogLevelAdjuster(Level.DEBUG, BlockingQueueConsumer.class,
MissingIdRetryTests.class,
RetryTemplate.class, SimpleRetryPolicy.class);
@BeforeClass
@AfterClass
@BeforeAll
@AfterAll
public static void setupAndCleanUp() {
brokerIsRunning.deleteQueues("retry.test.queue");
brokerIsRunning.deleteExchanges("retry.test.exchange");
RabbitAvailableCondition.getBrokerRunning().deleteQueues("retry.test.queue");
RabbitAvailableCondition.getBrokerRunning().deleteExchanges("retry.test.exchange");
}
@SuppressWarnings({ "rawtypes", "unchecked" })

View File

@@ -23,11 +23,11 @@ import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
@@ -41,7 +41,7 @@ import org.springframework.amqp.core.MessageProperties;
*
* @since 1.3
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class RepublishMessageRecovererTest {
private final Message message = new Message("".getBytes(), new MessageProperties());
@@ -53,7 +53,7 @@ public class RepublishMessageRecovererTest {
private RepublishMessageRecoverer recoverer;
@Before
@BeforeEach
public void beforeEach() {
message.getMessageProperties().setReceivedRoutingKey("some.key");
}
@@ -119,6 +119,7 @@ public class RepublishMessageRecovererTest {
message.getMessageProperties().setReceivedDeliveryMode(MessageDeliveryMode.PERSISTENT);
recoverer = new RepublishMessageRecoverer(amqpTemplate, "error") {
@Override
protected Map<? extends String, ? extends Object> additionalHeaders(Message message, Throwable cause) {
message.getMessageProperties().setDeliveryMode(message.getMessageProperties().getReceivedDeliveryMode());
return null;

View File

@@ -22,8 +22,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* @author Dave Syer

View File

@@ -25,8 +25,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.core.MessageProperties;
@@ -52,7 +52,7 @@ public class DefaultMessagePropertiesConverterTests {
private String longStringString;
@Before
@BeforeEach
public void init() throws UnsupportedEncodingException {
longStringString = new String(longString.getBytes(), "UTF-8");
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright 2002-2019 the original author or authors.
*
* 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
*
* https://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.springframework.amqp.rabbit.test;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Assume;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
public class EnvironmentAvailable extends TestWatcher {
private static Log logger = LogFactory.getLog(EnvironmentAvailable.class);
private static final String DEFAULT_ENVIRONMENT_KEY = "ENVIRONMENT";
private final String key;
public EnvironmentAvailable(String key) {
this.key = key;
}
public EnvironmentAvailable() {
this(DEFAULT_ENVIRONMENT_KEY);
}
@Override
public Statement apply(final Statement base, Description description) {
logger.info("Environment: " + key + " active=" + isActive());
Assume.assumeTrue(isActive());
return super.apply(base, description);
}
public boolean isActive() {
return System.getProperty(key) != null;
}
}

View File

@@ -1,63 +0,0 @@
/*
* Copyright 2015-2019 the original author or authors.
*
* 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
*
* https://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.springframework.amqp.rabbit.test;
import org.hamcrest.Description;
import org.hamcrest.DiagnosingMatcher;
import org.hamcrest.Matcher;
/**
* @author Gary Russell
* @since 1.6
*
*/
public final class RabbitMatchers {
private RabbitMatchers() {
super();
}
public static Matcher<String> matchesRegex(String pattern) {
return new RegexMatcher(pattern);
}
private final static class RegexMatcher extends DiagnosingMatcher<String> {
private final String pattern;
RegexMatcher(String pattern) {
this.pattern = pattern;
}
@Override
public void describeTo(Description description) {
description.appendText("the pattern to match ").appendText(this.pattern);
}
@Override
protected boolean matches(Object item, Description mismatchDescription) {
String result = (String) item;
boolean matches = result.matches(this.pattern);
if (!matches) {
mismatchDescription.appendText("is ").appendText(result);
}
return matches;
}
}
}

View File

@@ -22,7 +22,7 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.ConnectException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.AmqpAuthenticationException;
import org.springframework.amqp.AmqpConnectException;

View File

@@ -19,35 +19,33 @@ package org.springframework.amqp.rabbit.transaction;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.junit.BrokerRunning;
import org.springframework.amqp.rabbit.junit.RabbitAvailable;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.transaction.support.TransactionTemplate;
/**
* @author David Syer
* @author Gunnar Hillert
* @author Gary Russell
* @since 1.0
*
*/
@RabbitAvailable(queues = RabbitTransactionManagerIntegrationTests.ROUTE)
public class RabbitTransactionManagerIntegrationTests {
private static final String ROUTE = "test.queue";
public static final String ROUTE = "test.queue.RabbitTransactionManagerIntegrationTests";
private RabbitTemplate template;
private TransactionTemplate transactionTemplate;
@Rule
public BrokerRunning brokerIsRunning = BrokerRunning.isRunningWithEmptyQueues(ROUTE);
@Before
@BeforeEach
public void init() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
connectionFactory.setHost("localhost");
@@ -58,11 +56,10 @@ public class RabbitTransactionManagerIntegrationTests {
transactionTemplate = new TransactionTemplate(transactionManager);
}
@After
@AfterEach
public void cleanup() throws Exception {
this.template.stop();
((DisposableBean) this.template.getConnectionFactory()).destroy();
this.brokerIsRunning.removeTestQueues();
}
@Test