Merge branch '1.5.x'
This commit is contained in:
@@ -64,6 +64,58 @@ public class ActiveMQAutoConfigurationTests {
|
||||
.isTrue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultsConnectionFactoryAreApplied() {
|
||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
||||
.withPropertyValues("spring.activemq.pool.enabled=false").run((loaded) -> {
|
||||
assertThat(loaded.getBeansOfType(ActiveMQConnectionFactory.class)).hasSize(1);
|
||||
ActiveMQConnectionFactory connectionFactory = loaded.getBean(
|
||||
ActiveMQConnectionFactory.class);
|
||||
ActiveMQConnectionFactory defaultFactory = new ActiveMQConnectionFactory(
|
||||
"vm://localhost?broker.persistent=false");
|
||||
assertThat(connectionFactory.getUserName()).isEqualTo(
|
||||
defaultFactory.getUserName());
|
||||
assertThat(connectionFactory.getPassword()).isEqualTo(
|
||||
defaultFactory.getPassword());
|
||||
assertThat(connectionFactory.getCloseTimeout()).isEqualTo(
|
||||
defaultFactory.getCloseTimeout());
|
||||
assertThat(connectionFactory.isNonBlockingRedelivery()).isEqualTo(
|
||||
defaultFactory.isNonBlockingRedelivery());
|
||||
assertThat(connectionFactory.getSendTimeout()).isEqualTo(
|
||||
defaultFactory.getSendTimeout());
|
||||
assertThat(connectionFactory.isTrustAllPackages()).isEqualTo(
|
||||
defaultFactory.isTrustAllPackages());
|
||||
assertThat(connectionFactory.getTrustedPackages()).containsExactly(
|
||||
defaultFactory.getTrustedPackages().toArray(new String[] {}));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customConnectionFactoryAreApplied() {
|
||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
||||
.withPropertyValues("spring.activemq.pool.enabled=false",
|
||||
"spring.activemq.brokerUrl=vm://localhost?useJmx=false&broker.persistent=false",
|
||||
"spring.activemq.user=foo",
|
||||
"spring.activemq.password=bar",
|
||||
"spring.activemq.closeTimeout=500",
|
||||
"spring.activemq.nonBlockingRedelivery=true",
|
||||
"spring.activemq.sendTimeout=1000",
|
||||
"spring.activemq.packages.trust-all=false",
|
||||
"spring.activemq.packages.trusted=com.example.acme").run((loaded) -> {
|
||||
assertThat(loaded.getBeansOfType(ActiveMQConnectionFactory.class)).hasSize(1);
|
||||
ActiveMQConnectionFactory connectionFactory = loaded.getBean(
|
||||
ActiveMQConnectionFactory.class);
|
||||
assertThat(connectionFactory.getUserName()).isEqualTo("foo");
|
||||
assertThat(connectionFactory.getPassword()).isEqualTo("bar");
|
||||
assertThat(connectionFactory.getCloseTimeout()).isEqualTo(500);
|
||||
assertThat(connectionFactory.isNonBlockingRedelivery()).isEqualTo(true);
|
||||
assertThat(connectionFactory.getSendTimeout()).isEqualTo(1000);
|
||||
assertThat(connectionFactory.isTrustAllPackages()).isFalse();
|
||||
assertThat(connectionFactory.getTrustedPackages()).containsExactly(
|
||||
"com.example.acme");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultsPooledConnectionFactoryAreApplied() {
|
||||
this.context.withUserConfiguration(EmptyConfiguration.class)
|
||||
@@ -153,4 +205,17 @@ public class ActiveMQAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomizerConfiguration {
|
||||
|
||||
@Bean
|
||||
public ActiveMQConnectionFactoryCustomizer activeMQConnectionFactoryCustomizer() {
|
||||
return factory -> {
|
||||
factory.setBrokerURL(
|
||||
"vm://localhost?useJmx=false&broker.persistent=false");
|
||||
factory.setUserName("foobar");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 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.
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jms.activemq;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -38,49 +40,53 @@ public class ActiveMQPropertiesTests {
|
||||
|
||||
@Test
|
||||
public void getBrokerUrlIsInMemoryByDefault() {
|
||||
assertThat(new ActiveMQConnectionFactoryFactory(this.properties)
|
||||
.determineBrokerUrl()).isEqualTo(DEFAULT_EMBEDDED_BROKER_URL);
|
||||
assertThat(createFactory(this.properties).determineBrokerUrl()).isEqualTo(
|
||||
DEFAULT_EMBEDDED_BROKER_URL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBrokerUrlUseExplicitBrokerUrl() {
|
||||
this.properties.setBrokerUrl("vm://foo-bar");
|
||||
assertThat(new ActiveMQConnectionFactoryFactory(this.properties)
|
||||
.determineBrokerUrl()).isEqualTo("vm://foo-bar");
|
||||
assertThat(createFactory(this.properties).determineBrokerUrl()).isEqualTo(
|
||||
"vm://foo-bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBrokerUrlWithInMemorySetToFalse() {
|
||||
this.properties.setInMemory(false);
|
||||
assertThat(new ActiveMQConnectionFactoryFactory(this.properties)
|
||||
.determineBrokerUrl()).isEqualTo(DEFAULT_NETWORK_BROKER_URL);
|
||||
assertThat(createFactory(this.properties).determineBrokerUrl()).isEqualTo(
|
||||
DEFAULT_NETWORK_BROKER_URL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExplicitBrokerUrlAlwaysWins() {
|
||||
this.properties.setBrokerUrl("vm://foo-bar");
|
||||
this.properties.setInMemory(false);
|
||||
assertThat(new ActiveMQConnectionFactoryFactory(this.properties)
|
||||
.determineBrokerUrl()).isEqualTo("vm://foo-bar");
|
||||
assertThat(createFactory(this.properties).determineBrokerUrl()).isEqualTo(
|
||||
"vm://foo-bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTrustAllPackages() {
|
||||
this.properties.getPackages().setTrustAll(true);
|
||||
assertThat(new ActiveMQConnectionFactoryFactory(this.properties)
|
||||
.createConnectionFactory(ActiveMQConnectionFactory.class)
|
||||
.isTrustAllPackages()).isEqualTo(true);
|
||||
assertThat(createFactory(this.properties).createConnectionFactory(
|
||||
ActiveMQConnectionFactory.class).isTrustAllPackages()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTrustedPackages() {
|
||||
this.properties.getPackages().setTrustAll(false);
|
||||
this.properties.getPackages().getTrusted().add("trusted.package");
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactoryFactory(
|
||||
this.properties).createConnectionFactory(ActiveMQConnectionFactory.class);
|
||||
ActiveMQConnectionFactory factory = createFactory(this.properties)
|
||||
.createConnectionFactory(ActiveMQConnectionFactory.class);
|
||||
assertThat(factory.isTrustAllPackages()).isEqualTo(false);
|
||||
assertThat(factory.getTrustedPackages().size()).isEqualTo(1);
|
||||
assertThat(factory.getTrustedPackages().get(0)).isEqualTo("trusted.package");
|
||||
}
|
||||
|
||||
private ActiveMQConnectionFactoryFactory createFactory(ActiveMQProperties properties) {
|
||||
return new ActiveMQConnectionFactoryFactory(properties,
|
||||
Collections.<ActiveMQConnectionFactoryCustomizer>emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user