|
|
|
|
@ -17,6 +17,7 @@
@@ -17,6 +17,7 @@
|
|
|
|
|
package org.springframework.boot.autoconfigure.amqp; |
|
|
|
|
|
|
|
|
|
import java.time.Duration; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import com.rabbitmq.stream.BackOffDelayPolicy; |
|
|
|
|
import com.rabbitmq.stream.Codec; |
|
|
|
|
@ -124,12 +125,14 @@ class RabbitStreamConfigurationTests {
@@ -124,12 +125,14 @@ class RabbitStreamConfigurationTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void environmentUsesPropertyDefaultsByDefault() { |
|
|
|
|
void environmentUsesConnectionDetailsByDefault() { |
|
|
|
|
EnvironmentBuilder builder = mock(EnvironmentBuilder.class); |
|
|
|
|
RabbitProperties properties = new RabbitProperties(); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties, |
|
|
|
|
new TestRabbitConnectionDetails("guest", "guest", "vhost")); |
|
|
|
|
then(builder).should().port(5552); |
|
|
|
|
then(builder).should().host("localhost"); |
|
|
|
|
then(builder).should().virtualHost("vhost"); |
|
|
|
|
then(builder).should().lazyInitialization(true); |
|
|
|
|
then(builder).should().username("guest"); |
|
|
|
|
then(builder).should().password("guest"); |
|
|
|
|
@ -141,7 +144,8 @@ class RabbitStreamConfigurationTests {
@@ -141,7 +144,8 @@ class RabbitStreamConfigurationTests {
|
|
|
|
|
EnvironmentBuilder builder = mock(EnvironmentBuilder.class); |
|
|
|
|
RabbitProperties properties = new RabbitProperties(); |
|
|
|
|
properties.getStream().setPort(5553); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties, |
|
|
|
|
new TestRabbitConnectionDetails("guest", "guest", "vhost")); |
|
|
|
|
then(builder).should().port(5553); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -150,7 +154,8 @@ class RabbitStreamConfigurationTests {
@@ -150,7 +154,8 @@ class RabbitStreamConfigurationTests {
|
|
|
|
|
EnvironmentBuilder builder = mock(EnvironmentBuilder.class); |
|
|
|
|
RabbitProperties properties = new RabbitProperties(); |
|
|
|
|
properties.getStream().setHost("stream.rabbit.example.com"); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties, |
|
|
|
|
new TestRabbitConnectionDetails("guest", "guest", "vhost")); |
|
|
|
|
then(builder).should().host("stream.rabbit.example.com"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -159,7 +164,8 @@ class RabbitStreamConfigurationTests {
@@ -159,7 +164,8 @@ class RabbitStreamConfigurationTests {
|
|
|
|
|
EnvironmentBuilder builder = mock(EnvironmentBuilder.class); |
|
|
|
|
RabbitProperties properties = new RabbitProperties(); |
|
|
|
|
properties.getStream().setVirtualHost("stream-virtual-host"); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties, |
|
|
|
|
new TestRabbitConnectionDetails("guest", "guest", "vhost")); |
|
|
|
|
then(builder).should().virtualHost("stream-virtual-host"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -167,20 +173,22 @@ class RabbitStreamConfigurationTests {
@@ -167,20 +173,22 @@ class RabbitStreamConfigurationTests {
|
|
|
|
|
void whenStreamVirtualHostIsNotSetButDefaultVirtualHostIsSetThenEnvironmentUsesDefaultVirtualHost() { |
|
|
|
|
EnvironmentBuilder builder = mock(EnvironmentBuilder.class); |
|
|
|
|
RabbitProperties properties = new RabbitProperties(); |
|
|
|
|
properties.setVirtualHost("default-virtual-host"); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties); |
|
|
|
|
properties.setVirtualHost("properties-virtual-host"); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties, |
|
|
|
|
new TestRabbitConnectionDetails("guest", "guest", "default-virtual-host")); |
|
|
|
|
then(builder).should().virtualHost("default-virtual-host"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void whenStreamCredentialsAreNotSetThenEnvironmentUsesRabbitCredentials() { |
|
|
|
|
void whenStreamCredentialsAreNotSetThenEnvironmentUsesConnectionDetailsCredentials() { |
|
|
|
|
EnvironmentBuilder builder = mock(EnvironmentBuilder.class); |
|
|
|
|
RabbitProperties properties = new RabbitProperties(); |
|
|
|
|
properties.setUsername("alice"); |
|
|
|
|
properties.setPassword("secret"); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties); |
|
|
|
|
then(builder).should().username("alice"); |
|
|
|
|
then(builder).should().password("secret"); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties, |
|
|
|
|
new TestRabbitConnectionDetails("bob", "password", "vhost")); |
|
|
|
|
then(builder).should().username("bob"); |
|
|
|
|
then(builder).should().password("password"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -191,7 +199,8 @@ class RabbitStreamConfigurationTests {
@@ -191,7 +199,8 @@ class RabbitStreamConfigurationTests {
|
|
|
|
|
properties.setPassword("secret"); |
|
|
|
|
properties.getStream().setUsername("bob"); |
|
|
|
|
properties.getStream().setPassword("confidential"); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties); |
|
|
|
|
RabbitStreamConfiguration.configure(builder, properties, |
|
|
|
|
new TestRabbitConnectionDetails("charlotte", "hidden", "vhost")); |
|
|
|
|
then(builder).should().username("bob"); |
|
|
|
|
then(builder).should().password("confidential"); |
|
|
|
|
} |
|
|
|
|
@ -345,4 +354,40 @@ class RabbitStreamConfigurationTests {
@@ -345,4 +354,40 @@ class RabbitStreamConfigurationTests {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static final class TestRabbitConnectionDetails implements RabbitConnectionDetails { |
|
|
|
|
|
|
|
|
|
private final String username; |
|
|
|
|
|
|
|
|
|
private final String password; |
|
|
|
|
|
|
|
|
|
private final String virtualHost; |
|
|
|
|
|
|
|
|
|
private TestRabbitConnectionDetails(String username, String password, String virtualHost) { |
|
|
|
|
this.username = username; |
|
|
|
|
this.password = password; |
|
|
|
|
this.virtualHost = virtualHost; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String getUsername() { |
|
|
|
|
return this.username; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String getPassword() { |
|
|
|
|
return this.password; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String getVirtualHost() { |
|
|
|
|
return this.virtualHost; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<Address> getAddresses() { |
|
|
|
|
throw new UnsupportedOperationException(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|