Commit e364adfe by Johannes Edmeier

Simplify port & ready-state detection

By using local.server.port, local.managment.port and ApplicationReadyEvent the port detection and ready state detection can be simplyfied in boot 1.3
parent 66385226
...@@ -22,10 +22,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -22,10 +22,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties; import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
...@@ -74,53 +72,48 @@ public class AdminClientProperties { ...@@ -74,53 +72,48 @@ public class AdminClientProperties {
@Autowired @Autowired
private ServerProperties server; private ServerProperties server;
private int serverPort = -1; private Integer serverPort;
private int managementPort = -1; private Integer managementPort;
private boolean serverInitialized = false; private boolean ready = false;
@EventListener @EventListener
public void onStartedEmbeddedContainer(EmbeddedServletContainerInitializedEvent event) { public void onApplicationReady(ApplicationReadyEvent event) {
if ("management".equals(event.getApplicationContext().getNamespace())) { serverPort = event.getApplicationContext().getEnvironment().getProperty("local.server.port",
managementPort = event.getEmbeddedServletContainer().getPort(); Integer.class);
} else { managementPort = event.getApplicationContext().getEnvironment()
serverPort = event.getEmbeddedServletContainer().getPort(); .getProperty("local.management.port", Integer.class, serverPort);
} ready = true;
serverInitialized = true;
}
@EventListener
public void onStartedDeployedWar(ContextRefreshedEvent event) {
if (event.getApplicationContext() instanceof EmbeddedWebApplicationContext) {
EmbeddedWebApplicationContext context = (EmbeddedWebApplicationContext) event
.getApplicationContext();
if (context.getEmbeddedServletContainer() == null) {
if (!StringUtils.hasText(serviceUrl)) {
throw new RuntimeException(
"spring.boot.admin.client.serviceUrl must be set for deployed war files!");
}
serverInitialized = true;
}
}
} }
public String getManagementUrl() { public String getManagementUrl() {
if (managementUrl != null) { if (managementUrl != null) {
return managementUrl; return managementUrl;
} }
if (managementPort == -1) {
if ((managementPort == null || managementPort.equals(serverPort))
&& getServiceUrl() != null) {
return append(getServiceUrl(), management.getContextPath()); return append(getServiceUrl(), management.getContextPath());
} }
if (ready && managementPort == null) {
throw new IllegalStateException(
"serviceUrl must be set when deployed to servlet-container");
}
if (preferIp) { if (preferIp) {
Assert.notNull(management.getAddress(), Assert.notNull(management.getAddress(),
"management.address must be set when using preferIp"); "management.address must be set when using preferIp");
return append(createLocalUri(management.getAddress().getHostAddress(), managementPort), return append(
append(createLocalUri(management.getAddress().getHostAddress(), managementPort),
server.getContextPath()),
management.getContextPath()); management.getContextPath());
} }
return append(createLocalUri(getHostname(), managementPort), management.getContextPath()); return append(
append(createLocalUri(getHostname(), managementPort), server.getContextPath()),
management.getContextPath());
} }
public void setManagementUrl(String managementUrl) { public void setManagementUrl(String managementUrl) {
...@@ -143,9 +136,9 @@ public class AdminClientProperties { ...@@ -143,9 +136,9 @@ public class AdminClientProperties {
return serviceUrl; return serviceUrl;
} }
if (serverPort == -1) { if (ready && serverPort == null) {
throw new IllegalStateException( throw new IllegalStateException(
"EmbeddedServletContainer has not been initialized yet!"); "serviceUrl must be set when deployed to servlet-container");
} }
if (preferIp) { if (preferIp) {
...@@ -161,8 +154,8 @@ public class AdminClientProperties { ...@@ -161,8 +154,8 @@ public class AdminClientProperties {
this.serviceUrl = serviceUrl; this.serviceUrl = serviceUrl;
} }
public boolean isServerInitialized() { public boolean isReady() {
return serverInitialized; return ready;
} }
public String getName() { public String getName() {
......
...@@ -78,7 +78,7 @@ public class SpringBootAdminClientAutoConfiguration { ...@@ -78,7 +78,7 @@ public class SpringBootAdminClientAutoConfiguration {
Runnable registratorTask = new Runnable() { Runnable registratorTask = new Runnable() {
@Override @Override
public void run() { public void run() {
if (client.isServerInitialized()) { if (client.isReady()) {
registrator().register(); registrator().register();
} }
} }
......
package de.codecentric.boot.admin.services; package de.codecentric.boot.admin.services;
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
import org.springframework.context.event.ApplicationContextEvent;
import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
...@@ -16,7 +13,8 @@ public class RegistrationApplicationListener { ...@@ -16,7 +13,8 @@ public class RegistrationApplicationListener {
private boolean autoDeregister = false; private boolean autoDeregister = false;
private final TaskExecutor executor; private final TaskExecutor executor;
public RegistrationApplicationListener(ApplicationRegistrator registrator, TaskExecutor executor) { public RegistrationApplicationListener(ApplicationRegistrator registrator,
TaskExecutor executor) {
this.registrator = registrator; this.registrator = registrator;
this.executor = executor; this.executor = executor;
} }
...@@ -27,7 +25,7 @@ public class RegistrationApplicationListener { ...@@ -27,7 +25,7 @@ public class RegistrationApplicationListener {
@EventListener @EventListener
@Order(Ordered.LOWEST_PRECEDENCE) @Order(Ordered.LOWEST_PRECEDENCE)
public void onStartedEmbeddedServer(EmbeddedServletContainerInitializedEvent event) { public void onApplicationReady(ApplicationReadyEvent event) {
executor.execute(new Runnable() { executor.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -38,24 +36,6 @@ public class RegistrationApplicationListener { ...@@ -38,24 +36,6 @@ public class RegistrationApplicationListener {
@EventListener @EventListener
@Order(Ordered.LOWEST_PRECEDENCE) @Order(Ordered.LOWEST_PRECEDENCE)
public void onStartedDeployedWar(ContextRefreshedEvent event) {
ApplicationContextEvent contextEvent = event;
if (contextEvent.getApplicationContext() instanceof EmbeddedWebApplicationContext) {
EmbeddedWebApplicationContext context = (EmbeddedWebApplicationContext) contextEvent
.getApplicationContext();
if (context.getEmbeddedServletContainer() == null) {
executor.execute(new Runnable() {
@Override
public void run() {
registrator.register();
}
});
}
}
}
@EventListener
@Order(Ordered.LOWEST_PRECEDENCE)
public void onClosedContext(ContextClosedEvent event) { public void onClosedContext(ContextClosedEvent event) {
if (autoDeregister) { if (autoDeregister) {
executor.execute(new Runnable() { executor.execute(new Runnable() {
......
...@@ -5,21 +5,18 @@ import static org.junit.Assert.assertFalse; ...@@ -5,21 +5,18 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.ManagementServerPropertiesAutoConfiguration;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
import org.springframework.boot.context.embedded.EmbeddedServletContainer; import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
public class AdminClientPropertiesTest { public class AdminClientPropertiesTest {
...@@ -35,39 +32,27 @@ public class AdminClientPropertiesTest { ...@@ -35,39 +32,27 @@ public class AdminClientPropertiesTest {
@Test @Test
public void test_isServerStarted_false() { public void test_isServerStarted_false() {
assertFalse(new AdminClientProperties().isServerInitialized()); assertFalse(new AdminClientProperties().isReady());
} }
@Test @Test
public void test_isServerStarted_true_embedded() { public void test_isServerStarted_true() {
load();
AdminClientProperties clientProperties = new AdminClientProperties(); AdminClientProperties clientProperties = new AdminClientProperties();
clientProperties.setServiceUrl("http://localhost");
publishServletContainerInitializedEvent(clientProperties, 8080, null);
assertTrue(clientProperties.isServerInitialized());
}
@Test publishApplicationReadyEvent(clientProperties);
public void test_isServerStarted_true_war() {
AdminClientProperties clientProperties = new AdminClientProperties();
clientProperties.setServiceUrl("http://localhost");
publishContextRefreshedEvent(clientProperties);
assertTrue(clientProperties.isServerInitialized());
}
@Test(expected = RuntimeException.class) assertTrue(clientProperties.isReady());
public void test_isServerStarted_exception_war() {
AdminClientProperties clientProperties = new AdminClientProperties();
publishContextRefreshedEvent(clientProperties);
} }
@Test @Test
public void test_mgmtPortPath() { public void test_mgmtPortPath() {
load("management.contextPath=/admin", "endpoints.health.id=alive"); load("management.contextPath=/admin", "endpoints.health.id=alive", "local.server.port=8080",
"local.management.port=8081");
AdminClientProperties clientProperties = new AdminClientProperties(); AdminClientProperties clientProperties = new AdminClientProperties();
context.getAutowireCapableBeanFactory().autowireBean(clientProperties); context.getAutowireCapableBeanFactory().autowireBean(clientProperties);
publishServletContainerInitializedEvent(clientProperties, 8080, null); publishApplicationReadyEvent(clientProperties);
publishServletContainerInitializedEvent(clientProperties, 8081, "management");
assertThat(clientProperties.getManagementUrl(), assertThat(clientProperties.getManagementUrl(),
is("http://" + getHostname() + ":8081/admin")); is("http://" + getHostname() + ":8081/admin"));
...@@ -77,26 +62,12 @@ public class AdminClientPropertiesTest { ...@@ -77,26 +62,12 @@ public class AdminClientPropertiesTest {
} }
@Test @Test
public void test_mgmtPort() {
load();
AdminClientProperties clientProperties = new AdminClientProperties();
context.getAutowireCapableBeanFactory().autowireBean(clientProperties);
publishServletContainerInitializedEvent(clientProperties, 8080, null);
publishServletContainerInitializedEvent(clientProperties, 8081, "management");
assertThat(clientProperties.getManagementUrl(), is("http://" + getHostname() + ":8081"));
assertThat(clientProperties.getHealthUrl(), is("http://" + getHostname() + ":8081/health"));
assertThat(clientProperties.getServiceUrl(), is("http://" + getHostname() + ":8080"));
}
@Test
public void test_contextPath_mgmtPath() { public void test_contextPath_mgmtPath() {
load("server.context-path=app", "management.context-path=/admin"); load("server.context-path=app", "management.context-path=/admin", "local.server.port=8080");
AdminClientProperties clientProperties = new AdminClientProperties(); AdminClientProperties clientProperties = new AdminClientProperties();
context.getAutowireCapableBeanFactory().autowireBean(clientProperties); context.getAutowireCapableBeanFactory().autowireBean(clientProperties);
publishServletContainerInitializedEvent(clientProperties, 8080, null); publishApplicationReadyEvent(clientProperties);
assertThat(clientProperties.getManagementUrl(), assertThat(clientProperties.getManagementUrl(),
is("http://" + getHostname() + ":8080/app/admin")); is("http://" + getHostname() + ":8080/app/admin"));
...@@ -107,11 +78,11 @@ public class AdminClientPropertiesTest { ...@@ -107,11 +78,11 @@ public class AdminClientPropertiesTest {
@Test @Test
public void test_contextPath() { public void test_contextPath() {
load("server.context-path=app"); load("server.context-path=app", "local.server.port=80");
AdminClientProperties clientProperties = new AdminClientProperties(); AdminClientProperties clientProperties = new AdminClientProperties();
context.getAutowireCapableBeanFactory().autowireBean(clientProperties); context.getAutowireCapableBeanFactory().autowireBean(clientProperties);
publishServletContainerInitializedEvent(clientProperties, 80, null); publishApplicationReadyEvent(clientProperties);
assertThat(clientProperties.getManagementUrl(), is("http://" + getHostname() + ":80/app")); assertThat(clientProperties.getManagementUrl(), is("http://" + getHostname() + ":80/app"));
assertThat(clientProperties.getHealthUrl(), assertThat(clientProperties.getHealthUrl(),
...@@ -121,11 +92,11 @@ public class AdminClientPropertiesTest { ...@@ -121,11 +92,11 @@ public class AdminClientPropertiesTest {
@Test @Test
public void test_default() { public void test_default() {
load(); load("local.server.port=8080");
AdminClientProperties clientProperties = new AdminClientProperties(); AdminClientProperties clientProperties = new AdminClientProperties();
context.getAutowireCapableBeanFactory().autowireBean(clientProperties); context.getAutowireCapableBeanFactory().autowireBean(clientProperties);
publishServletContainerInitializedEvent(clientProperties, 8080, null); publishApplicationReadyEvent(clientProperties);
assertThat(clientProperties.getManagementUrl(), is("http://" + getHostname() + ":8080")); assertThat(clientProperties.getManagementUrl(), is("http://" + getHostname() + ":8080"));
assertThat(clientProperties.getHealthUrl(), is("http://" + getHostname() + ":8080/health")); assertThat(clientProperties.getHealthUrl(), is("http://" + getHostname() + ":8080/health"));
...@@ -134,11 +105,12 @@ public class AdminClientPropertiesTest { ...@@ -134,11 +105,12 @@ public class AdminClientPropertiesTest {
@Test @Test
public void testSsl() { public void testSsl() {
load("server.ssl.key-store=somefile.jks", "server.ssl.key-store-password=password"); load("server.ssl.key-store=somefile.jks", "server.ssl.key-store-password=password",
"local.server.port=8080");
AdminClientProperties clientProperties = new AdminClientProperties(); AdminClientProperties clientProperties = new AdminClientProperties();
context.getAutowireCapableBeanFactory().autowireBean(clientProperties); context.getAutowireCapableBeanFactory().autowireBean(clientProperties);
publishServletContainerInitializedEvent(clientProperties, 8080, null); publishApplicationReadyEvent(clientProperties);
assertThat(clientProperties.getManagementUrl(), is("https://" + getHostname() + ":8080")); assertThat(clientProperties.getManagementUrl(), is("https://" + getHostname() + ":8080"));
assertThat(clientProperties.getHealthUrl(), assertThat(clientProperties.getHealthUrl(),
...@@ -148,38 +120,37 @@ public class AdminClientPropertiesTest { ...@@ -148,38 +120,37 @@ public class AdminClientPropertiesTest {
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void test_preferIpAddress_serveraddress_missing() { public void test_preferIpAddress_serveraddress_missing() {
load(); load("local.server.port=8080");
AdminClientProperties clientProperties = new AdminClientProperties(); AdminClientProperties clientProperties = new AdminClientProperties();
clientProperties.setPreferIp(true); clientProperties.setPreferIp(true);
context.getAutowireCapableBeanFactory().autowireBean(clientProperties); context.getAutowireCapableBeanFactory().autowireBean(clientProperties);
publishServletContainerInitializedEvent(clientProperties, 8080, null); publishApplicationReadyEvent(clientProperties);
clientProperties.getServiceUrl(); clientProperties.getServiceUrl();
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void test_preferIpAddress_managementaddress_missing() { public void test_preferIpAddress_managementaddress_missing() {
load(); load("local.server.port=8080", "local.management.port=8081");
AdminClientProperties clientProperties = new AdminClientProperties(); AdminClientProperties clientProperties = new AdminClientProperties();
clientProperties.setPreferIp(true); clientProperties.setPreferIp(true);
context.getAutowireCapableBeanFactory().autowireBean(clientProperties); context.getAutowireCapableBeanFactory().autowireBean(clientProperties);
publishServletContainerInitializedEvent(clientProperties, 8080, null); publishApplicationReadyEvent(clientProperties);
publishServletContainerInitializedEvent(clientProperties, 8081, "management");
clientProperties.getManagementUrl(); clientProperties.getManagementUrl();
} }
@Test @Test
public void test_preferIpAddress() { public void test_preferIpAddress() {
load("server.address=127.0.0.1", "management.address=127.0.0.2"); load("server.address=127.0.0.1", "management.address=127.0.0.2", "local.server.port=8080",
"local.management.port=8081");
AdminClientProperties clientProperties = new AdminClientProperties(); AdminClientProperties clientProperties = new AdminClientProperties();
clientProperties.setPreferIp(true); clientProperties.setPreferIp(true);
context.getAutowireCapableBeanFactory().autowireBean(clientProperties); context.getAutowireCapableBeanFactory().autowireBean(clientProperties);
publishServletContainerInitializedEvent(clientProperties, 8080, null); publishApplicationReadyEvent(clientProperties);
publishServletContainerInitializedEvent(clientProperties, 8081, "management");
assertThat(clientProperties.getManagementUrl(), is("http://127.0.0.2:8081")); assertThat(clientProperties.getManagementUrl(), is("http://127.0.0.2:8081"));
assertThat(clientProperties.getHealthUrl(), is("http://127.0.0.2:8081/health")); assertThat(clientProperties.getHealthUrl(), is("http://127.0.0.2:8081/health"));
...@@ -194,21 +165,9 @@ public class AdminClientPropertiesTest { ...@@ -194,21 +165,9 @@ public class AdminClientPropertiesTest {
} }
} }
private void publishServletContainerInitializedEvent(AdminClientProperties client, int port, private void publishApplicationReadyEvent(AdminClientProperties client) {
String namespace) { client.onApplicationReady(
EmbeddedServletContainer eventSource = mock(EmbeddedServletContainer.class); new ApplicationReadyEvent(mock(SpringApplication.class), new String[] {}, context));
when(eventSource.getPort()).thenReturn(port);
EmbeddedWebApplicationContext eventContext = mock(EmbeddedWebApplicationContext.class);
when(eventContext.getNamespace()).thenReturn(namespace);
when(eventContext.getEmbeddedServletContainer()).thenReturn(eventSource);
client.onStartedEmbeddedContainer(new EmbeddedServletContainerInitializedEvent(
eventContext, eventSource));
}
private void publishContextRefreshedEvent(AdminClientProperties client) {
client.onStartedDeployedWar(new ContextRefreshedEvent(
mock(EmbeddedWebApplicationContext.class)));
} }
private void load(String... environment) { private void load(String... environment) {
......
...@@ -3,14 +3,12 @@ package de.codecentric.boot.admin.services; ...@@ -3,14 +3,12 @@ package de.codecentric.boot.admin.services;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.context.embedded.EmbeddedServletContainer; import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.task.SyncTaskExecutor; import org.springframework.core.task.SyncTaskExecutor;
public class RegistrationApplicationListenerTest { public class RegistrationApplicationListenerTest {
...@@ -18,10 +16,11 @@ public class RegistrationApplicationListenerTest { ...@@ -18,10 +16,11 @@ public class RegistrationApplicationListenerTest {
@Test @Test
public void test_register_embedded() { public void test_register_embedded() {
ApplicationRegistrator registrator = mock(ApplicationRegistrator.class); ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, new SyncTaskExecutor()); RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator,
new SyncTaskExecutor());
listener.onStartedEmbeddedServer(new EmbeddedServletContainerInitializedEvent( listener.onApplicationReady(
mock(EmbeddedWebApplicationContext.class), mock(EmbeddedServletContainer.class))); new ApplicationReadyEvent(mock(SpringApplication.class), null, null));
verify(registrator).register(); verify(registrator).register();
} }
...@@ -29,30 +28,20 @@ public class RegistrationApplicationListenerTest { ...@@ -29,30 +28,20 @@ public class RegistrationApplicationListenerTest {
@Test @Test
public void test_register_war() { public void test_register_war() {
ApplicationRegistrator registrator = mock(ApplicationRegistrator.class); ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, new SyncTaskExecutor()); RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator,
new SyncTaskExecutor());
listener.onStartedDeployedWar(new ContextRefreshedEvent( listener.onApplicationReady(
mock(EmbeddedWebApplicationContext.class))); new ApplicationReadyEvent(mock(SpringApplication.class), null, null));
verify(registrator).register(); verify(registrator).register();
} }
@Test @Test
public void test_no_register_war() {
ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, new SyncTaskExecutor());
EmbeddedWebApplicationContext context = mock(EmbeddedWebApplicationContext.class);
when(context.getEmbeddedServletContainer())
.thenReturn(mock(EmbeddedServletContainer.class));
listener.onStartedDeployedWar(new ContextRefreshedEvent(context));
verify(registrator, never()).register();
}
@Test
public void test_no_deregister() { public void test_no_deregister() {
ApplicationRegistrator registrator = mock(ApplicationRegistrator.class); ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, new SyncTaskExecutor()); RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator,
new SyncTaskExecutor());
listener.onClosedContext(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class))); listener.onClosedContext(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class)));
...@@ -62,7 +51,8 @@ public class RegistrationApplicationListenerTest { ...@@ -62,7 +51,8 @@ public class RegistrationApplicationListenerTest {
@Test @Test
public void test_deregister() { public void test_deregister() {
ApplicationRegistrator registrator = mock(ApplicationRegistrator.class); ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, new SyncTaskExecutor()); RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator,
new SyncTaskExecutor());
listener.setAutoDeregister(true); listener.setAutoDeregister(true);
listener.onClosedContext(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class))); listener.onClosedContext(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class)));
......
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