|
|
@ -27,9 +27,9 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
|
|
|
|
import static junit.framework.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static junit.framework.Assert.assertNotNull;
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
import static junit.framework.Assert.fail;
|
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Tests for {@link RabbitTemplateAutoConfiguration}.
|
|
|
|
* Tests for {@link RabbitTemplateAutoConfiguration}.
|
|
|
@ -43,10 +43,12 @@ public class RabbitTemplateAutoconfigurationTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testDefaultRabbitTemplate() {
|
|
|
|
public void testDefaultRabbitTemplate() {
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context.register(TestConfiguration.class, RabbitTemplateAutoConfiguration.class);
|
|
|
|
this.context.register(TestConfiguration.class,
|
|
|
|
|
|
|
|
RabbitTemplateAutoConfiguration.class);
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
|
|
|
|
RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
|
|
|
|
CachingConnectionFactory connectionFactory = this.context.getBean(CachingConnectionFactory.class);
|
|
|
|
CachingConnectionFactory connectionFactory = this.context
|
|
|
|
|
|
|
|
.getBean(CachingConnectionFactory.class);
|
|
|
|
RabbitAdmin amqpAdmin = this.context.getBean(RabbitAdmin.class);
|
|
|
|
RabbitAdmin amqpAdmin = this.context.getBean(RabbitAdmin.class);
|
|
|
|
assertNotNull(rabbitTemplate);
|
|
|
|
assertNotNull(rabbitTemplate);
|
|
|
|
assertNotNull(connectionFactory);
|
|
|
|
assertNotNull(connectionFactory);
|
|
|
@ -58,11 +60,14 @@ public class RabbitTemplateAutoconfigurationTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testRabbitTemplateWithOverrides() {
|
|
|
|
public void testRabbitTemplateWithOverrides() {
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context.register(TestConfiguration.class, RabbitTemplateAutoConfiguration.class);
|
|
|
|
this.context.register(TestConfiguration.class,
|
|
|
|
|
|
|
|
RabbitTemplateAutoConfiguration.class);
|
|
|
|
TestUtils.addEnviroment(this.context, "spring.rabbitmq.host:remote-server",
|
|
|
|
TestUtils.addEnviroment(this.context, "spring.rabbitmq.host:remote-server",
|
|
|
|
"spring.rabbitmq.port:9000", "spring.rabbitmq.username:alice", "spring.rabbitmq.password:secret");
|
|
|
|
"spring.rabbitmq.port:9000", "spring.rabbitmq.username:alice",
|
|
|
|
|
|
|
|
"spring.rabbitmq.password:secret");
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
CachingConnectionFactory connectionFactory = this.context.getBean(CachingConnectionFactory.class);
|
|
|
|
CachingConnectionFactory connectionFactory = this.context
|
|
|
|
|
|
|
|
.getBean(CachingConnectionFactory.class);
|
|
|
|
assertEquals(connectionFactory.getHost(), "remote-server");
|
|
|
|
assertEquals(connectionFactory.getHost(), "remote-server");
|
|
|
|
assertEquals(connectionFactory.getPort(), 9000);
|
|
|
|
assertEquals(connectionFactory.getPort(), 9000);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -70,10 +75,12 @@ public class RabbitTemplateAutoconfigurationTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testConnectionFactoryBackoff() {
|
|
|
|
public void testConnectionFactoryBackoff() {
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context.register(TestConfiguration2.class, RabbitTemplateAutoConfiguration.class);
|
|
|
|
this.context.register(TestConfiguration2.class,
|
|
|
|
|
|
|
|
RabbitTemplateAutoConfiguration.class);
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
|
|
|
|
RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
|
|
|
|
CachingConnectionFactory connectionFactory = this.context.getBean(CachingConnectionFactory.class);
|
|
|
|
CachingConnectionFactory connectionFactory = this.context
|
|
|
|
|
|
|
|
.getBean(CachingConnectionFactory.class);
|
|
|
|
assertEquals(rabbitTemplate.getConnectionFactory(), connectionFactory);
|
|
|
|
assertEquals(rabbitTemplate.getConnectionFactory(), connectionFactory);
|
|
|
|
assertEquals(connectionFactory.getHost(), "otherserver");
|
|
|
|
assertEquals(connectionFactory.getHost(), "otherserver");
|
|
|
|
assertEquals(connectionFactory.getPort(), 8001);
|
|
|
|
assertEquals(connectionFactory.getPort(), 8001);
|
|
|
@ -82,13 +89,16 @@ public class RabbitTemplateAutoconfigurationTests {
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testStaticQueues() {
|
|
|
|
public void testStaticQueues() {
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context.register(TestConfiguration.class, RabbitTemplateAutoConfiguration.class);
|
|
|
|
this.context.register(TestConfiguration.class,
|
|
|
|
|
|
|
|
RabbitTemplateAutoConfiguration.class);
|
|
|
|
TestUtils.addEnviroment(this.context, "spring.rabbitmq.dynamic:false");
|
|
|
|
TestUtils.addEnviroment(this.context, "spring.rabbitmq.dynamic:false");
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
this.context.getBean(AmqpAdmin.class);
|
|
|
|
this.context.getBean(AmqpAdmin.class);
|
|
|
|
fail("There should NOT be an AmqpAdmin bean when dynamic is switch to false");
|
|
|
|
fail("There should NOT be an AmqpAdmin bean when dynamic is switch to false");
|
|
|
|
} catch (Exception e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|