Commit 8b7c58c0 by Johannes Edmeier

Assert instances synchronized events via hazelcast in tests

parent 76df8b0a
......@@ -26,7 +26,6 @@ import java.util.Map;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
......@@ -37,13 +36,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@Configuration
public class AdminServerWebConfiguration implements WebMvcConfigurer, ApplicationContextAware {
private final ApplicationEventPublisher publisher;
private final AdminServerProperties adminServerProperties;
private ApplicationContext applicationContext;
public AdminServerWebConfiguration(ApplicationEventPublisher publisher,
AdminServerProperties adminServerProperties) {
this.publisher = publisher;
public AdminServerWebConfiguration(AdminServerProperties adminServerProperties) {
this.adminServerProperties = adminServerProperties;
}
......
......@@ -16,14 +16,20 @@
package de.codecentric.boot.admin.server;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import java.util.stream.Collectors;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.test.web.reactive.server.WebTestClient;
import com.hazelcast.config.Config;
import com.hazelcast.config.EvictionPolicy;
import com.hazelcast.config.InMemoryFormat;
......@@ -31,6 +37,7 @@ import com.hazelcast.config.MapConfig;
import com.hazelcast.config.TcpIpConfig;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test to verify the correct functionality of the REST API with Hazelcast
......@@ -40,6 +47,7 @@ import static java.util.Collections.singletonList;
public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest {
private ServletWebServerApplicationContext instance1;
private ServletWebServerApplicationContext instance2;
private WebTestClient webClient2;
@Before
public void setUp() throws Exception {
......@@ -52,6 +60,38 @@ public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest
"--management.security.enabled=false", "--info.test=foobar");
super.setUp(instance1.getWebServer().getPort());
this.webClient2 = createWebClient(instance2.getWebServer().getPort());
}
@Test
@Override
public void lifecycle() {
super.lifecycle();
Mono<String> events1 = getWebClient().get()
.uri("/api/applications/events")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.returnResult(String.class)
.getResponseBody()
.collect(Collectors.joining());
Mono<String> events2 = webClient2.get()
.uri("/api/applications/events")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus()
.isOk()
.returnResult(String.class)
.getResponseBody()
.collect(Collectors.joining());
StepVerifier.create(events1.and(events2))
.assertNext(t -> assertThat(t.getT1()).isEqualTo(t.getT2()))
.verifyComplete();
}
@After
......@@ -67,7 +107,6 @@ public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest
@Bean
public Config hazelcastConfig() {
Config config = new Config();
config.addMapConfig(new MapConfig("spring-boot-admin-event-store").setInMemoryFormat(InMemoryFormat.OBJECT)
.setBackupCount(1)
.setEvictionPolicy(EvictionPolicy.NONE));
......
......@@ -15,6 +15,7 @@
*/
package de.codecentric.boot.admin.server.config;
import de.codecentric.boot.admin.server.discovery.ApplicationDiscoveryListener;
import de.codecentric.boot.admin.server.domain.entities.ApplicationRepository;
import de.codecentric.boot.admin.server.domain.entities.EventSourcingApplicationRepository;
import de.codecentric.boot.admin.server.eventstore.ClientApplicationEventStore;
......@@ -29,6 +30,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration;
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClientAutoConfiguration;
import org.springframework.cloud.commons.util.UtilAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -52,7 +54,7 @@ public class AdminServerWebConfigurationTest {
@Test
public void jacksonMapperPresentFromDefault() {
AdminServerWebConfiguration config = new AdminServerWebConfiguration(null, null);
AdminServerWebConfiguration config = new AdminServerWebConfiguration(null);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
......@@ -65,7 +67,7 @@ public class AdminServerWebConfigurationTest {
@Test
public void jacksonMapperPresentNeedExtend() {
AdminServerWebConfiguration config = new AdminServerWebConfiguration(null, null);
AdminServerWebConfiguration config = new AdminServerWebConfiguration(null);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
config.extendMessageConverters(converters);
......@@ -89,14 +91,12 @@ public class AdminServerWebConfigurationTest {
assertThat(context.getBean(ClientApplicationEventStore.class)).isInstanceOf(HazelcastEventStore.class);
}
//TODO
/*@Test
@Test
public void discoveryConfig() {
load(NoopDiscoveryClientAutoConfiguration.class);
assertThat(context.getBean(ApplicationRepository.class))
.isInstanceOf(EventSourcingApplicationRepository.class);
load(SimpleDiscoveryClientAutoConfiguration.class);
assertThat(context.getBean(ApplicationRepository.class)).isInstanceOf(EventSourcingApplicationRepository.class);
context.getBean(ApplicationDiscoveryListener.class);
}*/
}
@Configuration
static class TestHazelcastConfig {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment