Bumping versions

This commit is contained in:
buildmaster
2024-07-23 11:18:40 +00:00
parent 8445b044de
commit c4f557d5e5
17 changed files with 139 additions and 123 deletions

View File

@@ -73,7 +73,7 @@ public class BusAmqpIntegrationTests {
"spring.rabbitmq.port=" + rabbitMQContainer.getAmqpPort(),
"management.endpoints.web.exposure.include=*", "spring.cloud.bus.id=app:2",
"spring.autoconfigure.exclude=org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration")
.run();
.run();
}
@AfterAll

View File

@@ -68,8 +68,9 @@ public class BusJacksonIntegrationTests {
assertThat(this.converter.isMapperCreated()).isFalse();
// set by configuration
assertThat(this.converter.getMapper().getSerializationConfig()
.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)).isTrue();
assertThat(this.converter.getMapper()
.getSerializationConfig()
.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)).isTrue();
Map map = this.rest.getForObject("http://localhost:" + this.port + "/date", Map.class);
assertThat(map).containsOnlyKeys("date");

View File

@@ -49,7 +49,7 @@ public class BusEnvironmentPostProcessor implements EnvironmentPostProcessor {
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
if (environment.containsProperty(ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED)) {
if (Boolean.FALSE.toString()
.equalsIgnoreCase(environment.getProperty(ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED))) {
.equalsIgnoreCase(environment.getProperty(ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED))) {
return;
}
}

View File

@@ -105,8 +105,13 @@ public class BusProperties {
@Override
public String toString() {
return new ToStringCreator(this).append("ack", ack).append("trace", trace).append("destination", destination)
.append("id", id).append("contentType", contentType).append("enabled", enabled).toString();
return new ToStringCreator(this).append("ack", ack)
.append("trace", trace)
.append("destination", destination)
.append("id", id)
.append("contentType", contentType)
.append("enabled", enabled)
.toString();
}
@@ -143,8 +148,9 @@ public class BusProperties {
@Override
public String toString() {
return new ToStringCreator(this).append("enabled", enabled).append("destinationService", destinationService)
.toString();
return new ToStringCreator(this).append("enabled", enabled)
.append("destinationService", destinationService)
.toString();
}
}

View File

@@ -85,8 +85,11 @@ public class EnvironmentChangeRemoteApplicationEvent extends RemoteApplicationEv
@Override
public String toString() {
return new ToStringCreator(this).append("id", getId()).append("originService", getOriginService())
.append("destinationService", getDestinationService()).append("values", values).toString();
return new ToStringCreator(this).append("id", getId())
.append("originService", getOriginService())
.append("destinationService", getDestinationService())
.append("values", values)
.toString();
}

View File

@@ -140,8 +140,10 @@ public abstract class RemoteApplicationEvent extends ApplicationEvent {
@Override
public String toString() {
return new ToStringCreator(this).append("id", id).append("originService", originService)
.append("destinationService", destinationService).toString();
return new ToStringCreator(this).append("id", id)
.append("originService", originService)
.append("destinationService", destinationService)
.toString();
}

View File

@@ -59,9 +59,12 @@ public class UnknownRemoteApplicationEvent extends RemoteApplicationEvent {
@Override
public String toString() {
return new ToStringCreator(this).append("id", getId()).append("originService", getOriginService())
.append("destinationService", getDestinationService()).append("typeInfo", typeInfo)
.append("payload", getPayloadAsString()).toString();
return new ToStringCreator(this).append("id", getId())
.append("originService", getOriginService())
.append("destinationService", getDestinationService())
.append("typeInfo", typeInfo)
.append("payload", getPayloadAsString())
.toString();
}

View File

@@ -47,7 +47,7 @@ public class RemoteApplicationEventRegistrar implements ImportBeanDefinitionRegi
final BeanDefinitionRegistry registry) {
Map<String, Object> componentScan = importingClassMetadata
.getAnnotationAttributes(RemoteApplicationEventScan.class.getName(), false);
.getAnnotationAttributes(RemoteApplicationEventScan.class.getName(), false);
Set<String> basePackages = new HashSet<>();
for (String pkg : (String[]) componentScan.get("value")) {
@@ -70,7 +70,7 @@ public class RemoteApplicationEventRegistrar implements ImportBeanDefinitionRegi
if (!registry.containsBeanDefinition(BUS_JSON_CONVERTER)) {
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder
.genericBeanDefinition(BusJacksonMessageConverter.class);
.genericBeanDefinition(BusJacksonMessageConverter.class);
beanDefinitionBuilder.addPropertyValue(PACKAGES_TO_SCAN,
basePackages.toArray(new String[basePackages.size()]));
AbstractBeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition();
@@ -80,16 +80,18 @@ public class RemoteApplicationEventRegistrar implements ImportBeanDefinitionRegi
}
else {
basePackages.addAll(getEarlierPackagesToScan(registry));
registry.getBeanDefinition(BUS_JSON_CONVERTER).getPropertyValues().addPropertyValue(PACKAGES_TO_SCAN,
basePackages.toArray(new String[basePackages.size()]));
registry.getBeanDefinition(BUS_JSON_CONVERTER)
.getPropertyValues()
.addPropertyValue(PACKAGES_TO_SCAN, basePackages.toArray(new String[basePackages.size()]));
}
}
private Set<String> getEarlierPackagesToScan(final BeanDefinitionRegistry registry) {
if (registry.containsBeanDefinition(BUS_JSON_CONVERTER)
&& registry.getBeanDefinition(BUS_JSON_CONVERTER).getPropertyValues().get(PACKAGES_TO_SCAN) != null) {
String[] earlierValues = (String[]) registry.getBeanDefinition(BUS_JSON_CONVERTER).getPropertyValues()
.get(PACKAGES_TO_SCAN);
String[] earlierValues = (String[]) registry.getBeanDefinition(BUS_JSON_CONVERTER)
.getPropertyValues()
.get(PACKAGES_TO_SCAN);
return new HashSet<>(Arrays.asList(earlierValues));
}

View File

@@ -32,10 +32,10 @@ public class BusAutoConfigurationClassPathTests {
@Test
public void refreshListenerCreatedWithoutActuator() {
new ApplicationContextRunner().withClassLoader(new FilteredClassLoader("org.springframework.boot.actuate"))
.withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class,
PathServiceMatcherAutoConfiguration.class, BusRefreshAutoConfiguration.class))
.run(context -> assertThat(context).hasSingleBean(RefreshListener.class)
.doesNotHaveBean(RefreshBusEndpoint.class));
.withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class,
PathServiceMatcherAutoConfiguration.class, BusRefreshAutoConfiguration.class))
.run(context -> assertThat(context).hasSingleBean(RefreshListener.class)
.doesNotHaveBean(RefreshBusEndpoint.class));
}
}

View File

@@ -65,7 +65,8 @@ public class BusAutoConfigurationTests {
public void defaultId() {
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--server.port=0");
assertThat(this.context.getBean(BusProperties.class).getId().startsWith("application:0:"))
.as("Wrong ID: " + this.context.getBean(BusProperties.class).getId()).isTrue();
.as("Wrong ID: " + this.context.getBean(BusProperties.class).getId())
.isTrue();
}
@Test
@@ -73,7 +74,7 @@ public class BusAutoConfigurationTests {
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=foo",
"--server.port=0");
this.context.getBean(BusConstants.INPUT, MessageChannel.class)
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "bar", "bar")));
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "bar", "bar")));
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNull();
}
@@ -82,7 +83,7 @@ public class BusAutoConfigurationTests {
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=foo",
"--server.port=0");
this.context.getBean(BusConstants.INPUT, MessageChannel.class)
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", (String) null)));
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", (String) null)));
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNull();
}
@@ -91,7 +92,7 @@ public class BusAutoConfigurationTests {
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar",
"--server.port=0");
this.context.getBean(BusConstants.INPUT, MessageChannel.class)
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", (String) null)));
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", (String) null)));
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNotNull();
}
@@ -103,7 +104,7 @@ public class BusAutoConfigurationTests {
new String[] { "--spring.cloud.bus.id=bar", "--server.port=0",
"--spring.main.allow-bean-definition-overriding=true" });
this.context.getBean(BusConstants.INPUT, MessageChannel.class)
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", (String) null)));
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", (String) null)));
RefreshRemoteApplicationEvent refresh = this.context.getBean(InboundMessageHandlerConfiguration.class).refresh;
assertThat(refresh).isNotNull();
TestStreamBusBridge busBridge = this.context.getBean(TestStreamBusBridge.class);
@@ -135,8 +136,9 @@ public class BusAutoConfigurationTests {
AckMessageConfiguration.class },
new String[] { "--spring.cloud.bus.trace.enabled=true", "--spring.cloud.bus.id=bar",
"--server.port=0" });
this.context.getBean(BusConsumer.class).accept(new AckRemoteApplicationEvent(this, "foo",
new PathDestinationFactory().getDestination(null), "ID", "bar", RefreshRemoteApplicationEvent.class));
this.context.getBean(BusConsumer.class)
.accept(new AckRemoteApplicationEvent(this, "foo", new PathDestinationFactory().getDestination(null), "ID",
"bar", RefreshRemoteApplicationEvent.class));
AckMessageConfiguration ack = this.context.getBean(AckMessageConfiguration.class);
assertThat(ack.latch.await(5, TimeUnit.SECONDS)).isTrue();
assertThat(ack.event).isNotNull();
@@ -166,7 +168,7 @@ public class BusAutoConfigurationTests {
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar:1000",
"--server.port=0");
this.context.getBean(BusConstants.INPUT, MessageChannel.class)
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", "bar:*")));
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", "bar:*")));
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNotNull();
}
@@ -175,7 +177,7 @@ public class BusAutoConfigurationTests {
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class,
"--spring.cloud.bus.id=bar:test:1000", "--server.port=0");
this.context.getBean(BusConstants.INPUT, MessageChannel.class)
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", "bar:**")));
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", "bar:**")));
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNotNull();
}
@@ -184,7 +186,7 @@ public class BusAutoConfigurationTests {
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar",
"--server.port=0");
this.context.getBean(BusConstants.INPUT, MessageChannel.class)
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", "bar*")));
.send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", "bar*")));
assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNotNull();
}
@@ -194,7 +196,7 @@ public class BusAutoConfigurationTests {
this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar",
"--server.port=0");
this.context.getBean(BusConstants.INPUT, MessageChannel.class)
.send(new GenericMessage<>(new UnknownRemoteApplicationEvent(this, "UnknownEvent", "yada".getBytes())));
.send(new GenericMessage<>(new UnknownRemoteApplicationEvent(this, "UnknownEvent", "yada".getBytes())));
// No Exception expected
}

View File

@@ -49,7 +49,7 @@ public class BusEnvironmentPostProcessorTests {
@Test
void testWithActiveProfile() {
MockEnvironment env = new MockEnvironment().withProperty("cachedrandom.application.value", "123")
.withProperty("spring.profiles.active", "dev");
.withProperty("spring.profiles.active", "dev");
new BusEnvironmentPostProcessor().postProcessEnvironment(env, mock(SpringApplication.class));
assertThat(env.getProperty(FunctionProperties.PREFIX + ".definition")).isEqualTo(BUS_CONSUMER);
assertThat(env.getProperty("spring.cloud.stream.function.bindings." + BUS_CONSUMER + "-in-0")).isEqualTo(INPUT);
@@ -65,15 +65,16 @@ public class BusEnvironmentPostProcessorTests {
String fnDefKey = FunctionProperties.PREFIX + ".definition";
String idKey = BusProperties.PREFIX + ".id";
MockEnvironment env = new MockEnvironment().withProperty("cachedrandom.application.value", "123")
.withProperty(BusProperties.PREFIX + ".destination", "mydestination").withProperty(idKey, "app:1")
.withProperty(fnDefKey, "uppercase");
.withProperty(BusProperties.PREFIX + ".destination", "mydestination")
.withProperty(idKey, "app:1")
.withProperty(fnDefKey, "uppercase");
new BusEnvironmentPostProcessor().postProcessEnvironment(env, mock(SpringApplication.class));
assertThat(env.getProperty(fnDefKey)).isEqualTo("uppercase;" + BUS_CONSUMER);
assertThat(env.getProperty("spring.cloud.stream.function.bindings." + BUS_CONSUMER + "-in-0")).isEqualTo(INPUT);
assertThat(env.getProperty("spring.cloud.stream.bindings." + INPUT + ".destination"))
.isEqualTo("mydestination");
.isEqualTo("mydestination");
assertThat(env.getProperty("spring.cloud.stream.bindings." + OUTPUT + ".destination"))
.isEqualTo("mydestination");
.isEqualTo("mydestination");
assertThat(env.getProperty(idKey)).isEqualTo("app:1");
assertThat(env.getPropertySources().contains(OVERRIDES_PROPERTY_SOURCE_NAME));
assertThat(env.getPropertySources().contains(DEFAULTS_PROPERTY_SOURCE_NAME));

View File

@@ -61,7 +61,7 @@ public class ConditionalOnBusEnabledTests {
public void busDisabled() {
load(MyBusEnabledConfig.class, ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED + ":false");
assertThat(this.context.containsBean("foo")).as("bean exists from disabled @ConditionalOnBusEnabled config")
.isFalse();
.isFalse();
}
private void load(Class<?> config, String... environment) {

View File

@@ -51,91 +51,88 @@ public class PathServiceMatcherTests {
@Test
public void fromSelf() {
assertThat(this.matcher.isFromSelf(
new EnvironmentChangeRemoteApplicationEvent(this, "one:two:8888", "foo:bar:spam", EMPTY_MAP))).isTrue();
assertThat(this.matcher
.isFromSelf(new EnvironmentChangeRemoteApplicationEvent(this, "one:two:8888", "foo:bar:spam", EMPTY_MAP)))
.isTrue();
}
@Test
public void forSelf() {
assertThat(this.matcher.isForSelf(
new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:8888", EMPTY_MAP))).isTrue();
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:8888", EMPTY_MAP)))
.isTrue();
}
@Test
public void forSelfWithWildcard() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:*", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:*", EMPTY_MAP)))
.isTrue();
}
@Test
public void forSelfWithGlobalWildcard() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "**", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "**", EMPTY_MAP))).isTrue();
}
@Test
public void forSelfWithWildcardName() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP))).isTrue();
}
@Test
public void forSelfWithWildcardNameAndProfile() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:t*", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:t*", EMPTY_MAP))).isTrue();
}
@Test
public void forSelfWithWildcardString() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP))).isTrue();
}
@Test
public void notForSelfWithWildCardNameAndMismatchingProfile() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:f*", EMPTY_MAP)))
.isFalse();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:f*", EMPTY_MAP)))
.isFalse();
}
@Test
public void forSelfWithDoubleWildcard() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:**", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:**", EMPTY_MAP)))
.isTrue();
}
@Test
public void forSelfWithNoWildcard() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one", EMPTY_MAP))).isTrue();
}
@Test
public void forSelfWithProfileNoWildcard() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two", EMPTY_MAP)))
.isTrue();
}
@Test
public void notForSelf() {
assertThat(this.matcher.isForSelf(
new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:9999", EMPTY_MAP)))
.isFalse();
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:9999", EMPTY_MAP)))
.isFalse();
}
@Test
public void notFromSelf() {
assertThat(this.matcher.isFromSelf(
new EnvironmentChangeRemoteApplicationEvent(this, "one:two:9999", "foo:bar:spam", EMPTY_MAP)))
.isFalse();
assertThat(this.matcher
.isFromSelf(new EnvironmentChangeRemoteApplicationEvent(this, "one:two:9999", "foo:bar:spam", EMPTY_MAP)))
.isFalse();
}
/**
@@ -146,7 +143,7 @@ public class PathServiceMatcherTests {
initMatcher("customerportal:dev,cloud:80");
assertThat(this.matcher.isForSelf(
new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "customerportal:cloud:*", EMPTY_MAP)))
.isTrue();
.isTrue();
}
/**
@@ -156,8 +153,8 @@ public class PathServiceMatcherTests {
public void notForSelfWithMultipleProfiles() {
initMatcher("customerportal:dev,cloud:80");
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP)))
.isFalse();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP)))
.isFalse();
}
/**
@@ -167,7 +164,8 @@ public class PathServiceMatcherTests {
public void notForSelfWithMultipleProfilesDifferentPort() {
initMatcher("customerportal:dev,cloud:80");
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam",
"customerportal:cloud:8008", EMPTY_MAP))).isFalse();
"customerportal:cloud:8008", EMPTY_MAP)))
.isFalse();
}
}

View File

@@ -52,101 +52,97 @@ public class PathServiceMatcherWithConfigNamesTests {
@Test
public void forSelfWithWildcard() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:*", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:*", EMPTY_MAP)))
.isTrue();
}
@Test
public void forSelfWithWildcardAndOtherConfigName() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "three:two:*", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "three:two:*", EMPTY_MAP)))
.isTrue();
}
@Test
public void forSelfWithGlobalWildcard() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "**", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "**", EMPTY_MAP))).isTrue();
}
@Test
public void forSelfWithWildcardName() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP))).isTrue();
}
@Test
public void forSelfWithWildcardNameAndProfile() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:t*", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:t*", EMPTY_MAP))).isTrue();
}
@Test
public void forSelfWithWildcardString() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP))).isTrue();
}
@Test
public void notForSelfWithWildCardNameAndMismatchingProfile() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:f*", EMPTY_MAP)))
.isFalse();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:f*", EMPTY_MAP)))
.isFalse();
}
@Test
public void forSelfWithDoubleWildcard() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:**", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:**", EMPTY_MAP)))
.isTrue();
}
@Test
public void forSelfWithNoWildcard() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one", EMPTY_MAP))).isTrue();
}
@Test
public void forSelfWithProfileNoWildcard() {
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two", EMPTY_MAP)))
.isTrue();
}
@Test
public void notForSelf() {
assertThat(this.matcher.isForSelf(
new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:9999", EMPTY_MAP)))
.isFalse();
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:9999", EMPTY_MAP)))
.isFalse();
}
@Test
public void forSelfWithMultipleProfiles() {
initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" });
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:cloud:*", EMPTY_MAP)))
.isTrue();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:cloud:*", EMPTY_MAP)))
.isTrue();
}
@Test
public void notForSelfWithMultipleProfiles() {
initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" });
assertThat(this.matcher
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP)))
.isFalse();
.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP)))
.isFalse();
}
@Test
public void notForSelfWithMultipleProfilesDifferentPort() {
initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" });
assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam",
"customerportal:cloud:8008", EMPTY_MAP))).isFalse();
"customerportal:cloud:8008", EMPTY_MAP)))
.isFalse();
}
}

View File

@@ -55,9 +55,9 @@ public class RefreshListenerIntegrationTests {
public void testEndpoint() {
System.out.println(rest.getForObject("/actuator", String.class));
assertThat(rest.postForEntity("/actuator/busrefresh/demoapp", new HashMap<>(), String.class).getStatusCode())
.isEqualTo(HttpStatus.NO_CONTENT);
.isEqualTo(HttpStatus.NO_CONTENT);
assertThat(rest.postForEntity("/actuator/busrefresh/foobar", new HashMap<>(), String.class).getStatusCode())
.isEqualTo(HttpStatus.NO_CONTENT);
.isEqualTo(HttpStatus.NO_CONTENT);
verify(busBridge, times(2)).send(any());
}

View File

@@ -88,8 +88,9 @@ public class RemoteApplicationEventScanTests {
}
private ConfigurableApplicationContext createTestContext(Class<?> configuration) {
return new SpringApplicationBuilder(configuration).web(WebApplicationType.NONE).bannerMode(Banner.Mode.OFF)
.run();
return new SpringApplicationBuilder(configuration).web(WebApplicationType.NONE)
.bannerMode(Banner.Mode.OFF)
.run();
}
private void assertConverterBeanAfterPropertiesSet(final String[] expectedPackageToScan,
@@ -98,20 +99,22 @@ public class RemoteApplicationEventScanTests {
@SuppressWarnings("unchecked")
final LinkedHashSet<NamedType> registeredSubtypes = (LinkedHashSet<NamedType>) ReflectionTestUtils
.getField(mapper.getSubtypeResolver(), "_registeredSubtypes");
.getField(mapper.getSubtypeResolver(), "_registeredSubtypes");
final List<Class<?>> expectedRegisterdClassesAsList = new ArrayList<>(Arrays.asList(expectedRegisterdClasses));
addStandardSpringCloudEventBusEvents(expectedRegisterdClassesAsList);
assertThat(expectedRegisterdClassesAsList.size() == registeredSubtypes.size())
.as("Wrong RemoteApplicationEvent classes are registerd in object mapper").isTrue();
.as("Wrong RemoteApplicationEvent classes are registerd in object mapper")
.isTrue();
for (final NamedType namedType : registeredSubtypes) {
assertThat(expectedRegisterdClassesAsList.contains(namedType.getType())).isTrue();
}
assertThat(Arrays.asList((String[]) ReflectionTestUtils.getField(this.converter, "packagesToScan")))
.as("RemoteApplicationEvent packages not registered").contains(expectedPackageToScan);
.as("RemoteApplicationEvent packages not registered")
.contains(expectedPackageToScan);
}

View File

@@ -65,8 +65,9 @@ public class SubtypeModuleTests {
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(mapper);
converter.afterPropertiesSet();
Object event = converter.fromMessage(MessageBuilder
.withPayload("{\"type\":\"TestRemoteApplicationEvent\", \"origin_service\":\"myorigin\"}").build(),
Object event = converter.fromMessage(
MessageBuilder.withPayload("{\"type\":\"TestRemoteApplicationEvent\", \"origin_service\":\"myorigin\"}")
.build(),
RemoteApplicationEvent.class);
assertThat(event).isNotNull().isInstanceOf(TestRemoteApplicationEvent.class);
assertThat(TestRemoteApplicationEvent.class.cast(event).getOriginService()).isEqualTo("myorigin");
@@ -91,9 +92,9 @@ public class SubtypeModuleTests {
RemoteApplicationEvent.class);
assertThat(event instanceof UnknownRemoteApplicationEvent).as("event is wrong type").isTrue();
assertThat(((UnknownRemoteApplicationEvent) event).getTypeInfo()).as("type information is wrong")
.isEqualTo("NotDefinedTestRemoteApplicationEvent");
.isEqualTo("NotDefinedTestRemoteApplicationEvent");
assertThat(((UnknownRemoteApplicationEvent) event).getPayloadAsString()).as("payload is wrong")
.isEqualTo("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}");
.isEqualTo("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}");
}
@Test
@@ -112,15 +113,14 @@ public class SubtypeModuleTests {
public void testDeserializeAckRemoteApplicationEventWithKnownType() throws Exception {
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null);
converter.afterPropertiesSet();
Object event = converter
.fromMessage(MessageBuilder
.withPayload("{\"type\":\"AckRemoteApplicationEvent\", "
+ "\"event\":\"org.springframework.cloud.bus.event.test.TestRemoteApplicationEvent\"}")
.build(), RemoteApplicationEvent.class);
Object event = converter.fromMessage(MessageBuilder
.withPayload("{\"type\":\"AckRemoteApplicationEvent\", "
+ "\"event\":\"org.springframework.cloud.bus.event.test.TestRemoteApplicationEvent\"}")
.build(), RemoteApplicationEvent.class);
assertThat(event instanceof AckRemoteApplicationEvent).as("event is no ack").isTrue();
AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event);
assertThat(ackEvent.getEvent()).as("inner ack event has wrong type")
.isEqualTo(TestRemoteApplicationEvent.class);
.isEqualTo(TestRemoteApplicationEvent.class);
}
/**
@@ -131,13 +131,12 @@ public class SubtypeModuleTests {
BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null);
converter.afterPropertiesSet();
Object event = converter.fromMessage(MessageBuilder
.withPayload(
"{\"type\":\"AckRemoteApplicationEvent\", \"event\":\"foo.bar.TestRemoteApplicationEvent\"}")
.build(), RemoteApplicationEvent.class);
.withPayload("{\"type\":\"AckRemoteApplicationEvent\", \"event\":\"foo.bar.TestRemoteApplicationEvent\"}")
.build(), RemoteApplicationEvent.class);
assertThat(event instanceof AckRemoteApplicationEvent).as("event is no ack").isTrue();
AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event);
assertThat(ackEvent.getEvent()).as("inner ack event has wrong type")
.isEqualTo(UnknownRemoteApplicationEvent.class);
.isEqualTo(UnknownRemoteApplicationEvent.class);
}
@SuppressWarnings("serial")