Merge branch '1.3.x
This commit is contained in:
commit
18d99245dd
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-2016 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.
|
||||
|
|
@ -44,6 +44,7 @@ import org.springframework.util.Assert;
|
|||
* {@link MBeanServer}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Andy Wilkinson
|
||||
* @since 1.3.0
|
||||
*/
|
||||
public class SpringApplicationAdminMXBeanRegistrar
|
||||
|
|
@ -80,7 +81,9 @@ public class SpringApplicationAdminMXBeanRegistrar
|
|||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationReadyEvent event) {
|
||||
this.ready = true;
|
||||
if (this.applicationContext.equals(event.getApplicationContext())) {
|
||||
this.ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -30,18 +30,22 @@ import org.junit.Test;
|
|||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link SpringApplicationAdminMXBeanRegistrar}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class SpringApplicationAdminMXBeanRegistrarTests {
|
||||
|
||||
|
|
@ -87,6 +91,25 @@ public class SpringApplicationAdminMXBeanRegistrarTests {
|
|||
assertThat(isApplicationReady(objectName)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eventsFromOtherContextsAreIgnored() throws MalformedObjectNameException {
|
||||
SpringApplicationAdminMXBeanRegistrar registrar = new SpringApplicationAdminMXBeanRegistrar(
|
||||
OBJECT_NAME);
|
||||
ConfigurableApplicationContext context = mock(
|
||||
ConfigurableApplicationContext.class);
|
||||
registrar.setApplicationContext(context);
|
||||
registrar.onApplicationEvent(new ApplicationReadyEvent(new SpringApplication(),
|
||||
null, mock(ConfigurableApplicationContext.class)));
|
||||
assertThat(isApplicationReady(registrar)).isFalse();
|
||||
registrar.onApplicationEvent(
|
||||
new ApplicationReadyEvent(new SpringApplication(), null, context));
|
||||
assertThat(isApplicationReady(registrar)).isTrue();
|
||||
}
|
||||
|
||||
private boolean isApplicationReady(SpringApplicationAdminMXBeanRegistrar registrar) {
|
||||
return (Boolean) ReflectionTestUtils.getField(registrar, "ready");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void environmentIsExposed() {
|
||||
final ObjectName objectName = createObjectName(OBJECT_NAME);
|
||||
|
|
|
|||
Loading…
Reference in New Issue