Checkstyle for tests
This commit is contained in:
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.autoconfigure;
|
||||
|
||||
import java.util.List;
|
||||
@@ -13,11 +29,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
@@ -126,16 +138,16 @@ public class LifecycleMvcAutoConfigurationTests {
|
||||
private void beanNotCreated(String beanName, String... contextProperties) {
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(Config.class,
|
||||
contextProperties)) {
|
||||
assertThat("bean was created", context.containsBeanDefinition(beanName),
|
||||
equalTo(false));
|
||||
then(context.containsBeanDefinition(beanName)).as("bean was created")
|
||||
.isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
private void beanCreated(String beanName, String... contextProperties) {
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(Config.class,
|
||||
contextProperties)) {
|
||||
assertThat("bean was not created", context.containsBeanDefinition(beanName),
|
||||
equalTo(true));
|
||||
then(context.containsBeanDefinition(beanName)).as("bean was not created")
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,14 +156,13 @@ public class LifecycleMvcAutoConfigurationTests {
|
||||
Function<T, Object> function, String... properties) {
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(Config.class,
|
||||
properties)) {
|
||||
assertThat("bean was not created", context.containsBeanDefinition(beanName),
|
||||
equalTo(true));
|
||||
then(context.containsBeanDefinition(beanName)).as("bean was not created")
|
||||
.isTrue();
|
||||
|
||||
Object endpoint = context.getBean(beanName, type);
|
||||
Object result = function.apply((T) endpoint);
|
||||
|
||||
assertThat("result is wrong type", result,
|
||||
is(not(instanceOf(ResponseEntity.class))));
|
||||
then(result).as("result is wrong type").isNotInstanceOf(ResponseEntity.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.autoconfigure;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -12,7 +28,7 @@ import org.springframework.cloud.test.ModifiedClassPathRunner;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
@@ -32,10 +48,10 @@ public class RefreshAutoConfigurationClassPathTests {
|
||||
public void refreshEventListenerCreated() {
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(
|
||||
Config.class)) {
|
||||
assertThat(context.getBeansOfType(RefreshEventListener.class))
|
||||
then(context.getBeansOfType(RefreshEventListener.class))
|
||||
.as("RefreshEventListeners not created").isNotEmpty();
|
||||
assertThat(context.containsBean("refreshEndpoint"))
|
||||
.as("refreshEndpoint created").isFalse();
|
||||
then(context.containsBean("refreshEndpoint")).as("refreshEndpoint created")
|
||||
.isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.autoconfigure;
|
||||
|
||||
import org.junit.Rule;
|
||||
@@ -13,7 +29,7 @@ import org.springframework.cloud.test.ModifiedClassPathRunner;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
@@ -37,8 +53,8 @@ public class RefreshAutoConfigurationMoreClassPathTests {
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(Config.class,
|
||||
"debug=true")) {
|
||||
String output = this.outputCapture.toString();
|
||||
assertThat(output).doesNotContain(
|
||||
"Failed to introspect annotations on [class org.springframework.cloud.autoconfigure.RefreshEndpointAutoConfiguration")
|
||||
then(output).doesNotContain("Failed to introspect annotations on "
|
||||
+ "[class org.springframework.cloud.autoconfigure.RefreshEndpointAutoConfiguration")
|
||||
.doesNotContain("TypeNotPresentExceptionProxy");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.autoconfigure;
|
||||
|
||||
import org.junit.Rule;
|
||||
@@ -14,7 +30,7 @@ import org.springframework.cloud.context.refresh.ContextRefresher;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -34,8 +50,8 @@ public class RefreshAutoConfigurationTests {
|
||||
public void noWarnings() {
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(
|
||||
WebApplicationType.NONE, Config.class)) {
|
||||
assertThat(context.containsBean("refreshScope")).isTrue();
|
||||
assertThat(this.output.toString()).doesNotContain("WARN");
|
||||
then(context.containsBean("refreshScope")).isTrue();
|
||||
then(this.output.toString()).doesNotContain("WARN");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +60,7 @@ public class RefreshAutoConfigurationTests {
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(
|
||||
WebApplicationType.SERVLET, Config.class,
|
||||
"spring.cloud.refresh.enabled:false")) {
|
||||
assertThat(context.containsBean("refreshScope")).isFalse();
|
||||
then(context.containsBean("refreshScope")).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bootstrap;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -11,7 +27,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class, properties = "spring.cloud.bootstrap.enabled:false")
|
||||
@@ -22,7 +38,7 @@ public class BootstrapDisabledAutoConfigurationIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void noBootstrapProperties() {
|
||||
assertFalse(this.environment.getPropertySources().contains("bootstrap"));
|
||||
then(this.environment.getPropertySources().contains("bootstrap")).isFalse();
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bootstrap;
|
||||
|
||||
import org.junit.Ignore;
|
||||
@@ -14,8 +30,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class, properties = "encrypt.key:deadbeef")
|
||||
@@ -28,18 +43,19 @@ public class BootstrapOrderingAutoConfigurationIntegrationTests {
|
||||
@Test
|
||||
@Ignore // FIXME: spring boot 2.0.0
|
||||
public void bootstrapPropertiesExist() {
|
||||
assertTrue(this.environment.getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME));
|
||||
then(this.environment.getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalPropertiesDecrypted() {
|
||||
assertEquals("foo", this.environment.resolvePlaceholders("${foo}"));
|
||||
then(this.environment.resolvePlaceholders("${foo}")).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bootstrapPropertiesDecrypted() {
|
||||
assertEquals("bar", this.environment.resolvePlaceholders("${bar}"));
|
||||
then(this.environment.resolvePlaceholders("${bar}")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bootstrap;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -22,8 +38,7 @@ import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class, properties = { "encrypt.key:deadbeef",
|
||||
@@ -37,13 +52,14 @@ public class BootstrapOrderingCustomPropertySourceIntegrationTests {
|
||||
@Test
|
||||
@Ignore // FIXME: spring boot 2.0.0
|
||||
public void bootstrapPropertiesExist() {
|
||||
assertTrue(this.environment.getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME));
|
||||
then(this.environment.getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customPropertiesDecrypted() {
|
||||
assertEquals("bar", this.environment.resolvePlaceholders("${custom.foo}"));
|
||||
then(this.environment.resolvePlaceholders("${custom.foo}")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bootstrap;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
@@ -13,8 +29,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class, properties = "spring.cloud.bootstrap.name:json")
|
||||
@@ -35,9 +50,22 @@ public class BootstrapOrderingSpringApplicationJsonIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void bootstrapPropertiesExist() {
|
||||
assertTrue(this.environment.getPropertySources()
|
||||
.contains("spring.application.json"));
|
||||
assertEquals("From JSON", this.environment.getProperty("message"));
|
||||
/*
|
||||
* Copyright 2012-2019 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. You may obtain a copy of the
|
||||
* License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed
|
||||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
then(this.environment.getProperty("message")).isEqualTo("From JSON");
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bootstrap;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -9,7 +25,7 @@ import org.springframework.cloud.bootstrap.BootstrapOrderingSpringApplicationJso
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapConfiguration.firstToBeCreated;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@@ -19,7 +35,7 @@ public class BootstrapSourcesOrderingTests {
|
||||
@Test
|
||||
public void sourcesAreOrderedCorrectly() {
|
||||
Class<?> firstConstructedClass = firstToBeCreated.get();
|
||||
assertThat(firstConstructedClass).as("bootstrap sources not ordered correctly")
|
||||
then(firstConstructedClass).as("bootstrap sources not ordered correctly")
|
||||
.isEqualTo(TestHigherPriorityBootstrapConfiguration.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -23,7 +23,6 @@ package org.springframework.cloud.bootstrap;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -35,6 +34,8 @@ import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestApplication.class, properties = "debug=true")
|
||||
public class MessageSourceConfigurationTests {
|
||||
@@ -44,8 +45,8 @@ public class MessageSourceConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void loadsMessage() {
|
||||
Assert.assertEquals("Hello World!", this.messageSource.getMessage("hello.message",
|
||||
null, Locale.getDefault()));
|
||||
then(this.messageSource.getMessage("hello.message", null, Locale.getDefault()))
|
||||
.isEqualTo("Hello World!");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bootstrap;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bootstrap;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -40,12 +40,7 @@ import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -84,10 +79,11 @@ public class BootstrapConfigurationTests {
|
||||
.sources(BareConfiguration.class)
|
||||
.properties("spring.cloud.bootstrap.location=" + externalPropertiesPath)
|
||||
.run();
|
||||
assertEquals("externalPropertiesInfoName",
|
||||
this.context.getEnvironment().getProperty("info.name"));
|
||||
assertTrue(this.context.getEnvironment().getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME));
|
||||
then(this.context.getEnvironment().getProperty("info.name"))
|
||||
.isEqualTo("externalPropertiesInfoName");
|
||||
then(this.context.getEnvironment().getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,13 +95,14 @@ public class BootstrapConfigurationTests {
|
||||
public void initialize(
|
||||
ConfigurableApplicationContext applicationContext) {
|
||||
// This property is defined in bootstrap.properties
|
||||
assertEquals("child", applicationContext.getEnvironment()
|
||||
.getProperty("info.name"));
|
||||
then(applicationContext.getEnvironment()
|
||||
.getProperty("info.name")).isEqualTo("child");
|
||||
}
|
||||
})
|
||||
.run();
|
||||
assertTrue(this.context.getEnvironment().getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME));
|
||||
then(this.context.getEnvironment().getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,9 +120,10 @@ public class BootstrapConfigurationTests {
|
||||
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.sources(BareConfiguration.class).run();
|
||||
assertEquals("bar", this.context.getEnvironment().getProperty("bootstrap.foo"));
|
||||
assertTrue(this.context.getEnvironment().getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME));
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("bar");
|
||||
then(this.context.getEnvironment().getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,7 +140,7 @@ public class BootstrapConfigurationTests {
|
||||
System.setProperty("bootstrap.foo", "system");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.sources(BareConfiguration.class).run();
|
||||
assertEquals("bar", this.context.getEnvironment().getProperty("bootstrap.foo"));
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -153,8 +151,8 @@ public class BootstrapConfigurationTests {
|
||||
System.setProperty("bootstrap.foo", "system");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.sources(BareConfiguration.class).run();
|
||||
assertEquals("system",
|
||||
this.context.getEnvironment().getProperty("bootstrap.foo"));
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo"))
|
||||
.isEqualTo("system");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,7 +167,7 @@ public class BootstrapConfigurationTests {
|
||||
System.setProperty("bootstrap.foo", "system");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.sources(BareConfiguration.class).run();
|
||||
assertEquals("bar", this.context.getEnvironment().getProperty("bootstrap.foo"));
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,8 +179,8 @@ public class BootstrapConfigurationTests {
|
||||
System.setProperty("bootstrap.foo", "system");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.sources(BareConfiguration.class).run();
|
||||
assertEquals("system",
|
||||
this.context.getEnvironment().getProperty("bootstrap.foo"));
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo"))
|
||||
.isEqualTo("system");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -195,7 +193,8 @@ public class BootstrapConfigurationTests {
|
||||
Collections.<String, Object>singletonMap("bootstrap.foo", "splat")));
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.environment(environment).sources(BareConfiguration.class).run();
|
||||
assertEquals("splat", this.context.getEnvironment().getProperty("bootstrap.foo"));
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo"))
|
||||
.isEqualTo("splat");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -205,17 +204,18 @@ public class BootstrapConfigurationTests {
|
||||
.properties("spring.cloud.bootstrap.name:other",
|
||||
"spring.config.name:plain")
|
||||
.sources(BareConfiguration.class).run();
|
||||
assertEquals("app",
|
||||
this.context.getEnvironment().getProperty("spring.application.name"));
|
||||
then(this.context.getEnvironment().getProperty("spring.application.name"))
|
||||
.isEqualTo("app");
|
||||
// The parent is called "main" because spring.application.name is specified in
|
||||
// other.properties (the bootstrap properties)
|
||||
assertEquals("main", this.context.getParent().getEnvironment()
|
||||
.getProperty("spring.application.name"));
|
||||
then(this.context.getParent().getEnvironment()
|
||||
.getProperty("spring.application.name")).isEqualTo("main");
|
||||
// The bootstrap context has the same "bootstrap" property source
|
||||
assertEquals(this.context.getEnvironment().getPropertySources().get("bootstrap"),
|
||||
((ConfigurableEnvironment) this.context.getParent().getEnvironment())
|
||||
.getPropertySources().get("bootstrap"));
|
||||
assertEquals("main-1", this.context.getId());
|
||||
then(((ConfigurableEnvironment) this.context.getParent().getEnvironment())
|
||||
.getPropertySources().get("bootstrap"))
|
||||
.isEqualTo(this.context.getEnvironment().getPropertySources()
|
||||
.get("bootstrap"));
|
||||
then(this.context.getId()).isEqualTo("main-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -225,12 +225,12 @@ public class BootstrapConfigurationTests {
|
||||
.properties("spring.cloud.bootstrap.name:application",
|
||||
"spring.config.name:other")
|
||||
.sources(BareConfiguration.class).run();
|
||||
assertEquals("main",
|
||||
this.context.getEnvironment().getProperty("spring.application.name"));
|
||||
then(this.context.getEnvironment().getProperty("spring.application.name"))
|
||||
.isEqualTo("main");
|
||||
// The parent has no name because spring.application.name is not
|
||||
// defined in the bootstrap properties
|
||||
assertEquals(null, this.context.getParent().getEnvironment()
|
||||
.getProperty("spring.application.name"));
|
||||
then(this.context.getParent().getEnvironment()
|
||||
.getProperty("spring.application.name")).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -241,13 +241,13 @@ public class BootstrapConfigurationTests {
|
||||
.sources(BareConfiguration.class).run();
|
||||
// The main context is called "main" because spring.application.name is specified
|
||||
// in other.properties (and not in the main config file)
|
||||
assertEquals("main",
|
||||
this.context.getEnvironment().getProperty("spring.application.name"));
|
||||
then(this.context.getEnvironment().getProperty("spring.application.name"))
|
||||
.isEqualTo("main");
|
||||
// The parent is called "main" because spring.application.name is specified in
|
||||
// other.properties (the bootstrap properties this time)
|
||||
assertEquals("main", this.context.getParent().getEnvironment()
|
||||
.getProperty("spring.application.name"));
|
||||
assertEquals("main-1", this.context.getId());
|
||||
then(this.context.getParent().getEnvironment()
|
||||
.getProperty("spring.application.name")).isEqualTo("main");
|
||||
then(this.context.getId()).isEqualTo("main-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -256,15 +256,15 @@ public class BootstrapConfigurationTests {
|
||||
this.context = new SpringApplicationBuilder().sources(BareConfiguration.class)
|
||||
.environment(new StandardEnvironment()).child(BareConfiguration.class)
|
||||
.web(WebApplicationType.NONE).run();
|
||||
assertEquals("bar", this.context.getEnvironment().getProperty("bootstrap.foo"));
|
||||
assertEquals(this.context.getEnvironment(),
|
||||
this.context.getParent().getEnvironment());
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("bar");
|
||||
then(this.context.getParent().getEnvironment())
|
||||
.isEqualTo(this.context.getEnvironment());
|
||||
MutablePropertySources sources = this.context.getEnvironment()
|
||||
.getPropertySources();
|
||||
PropertySource<?> bootstrap = sources
|
||||
.get(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME);
|
||||
assertNotNull(bootstrap);
|
||||
assertEquals(0, sources.precedenceOf(bootstrap));
|
||||
then(bootstrap).isNotNull();
|
||||
then(sources.precedenceOf(bootstrap)).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,11 +273,11 @@ public class BootstrapConfigurationTests {
|
||||
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
|
||||
this.context = new SpringApplicationBuilder().sources(BareConfiguration.class)
|
||||
.child(BareConfiguration.class).web(WebApplicationType.NONE).run();
|
||||
assertEquals(1, TestHigherPriorityBootstrapConfiguration.count.get());
|
||||
assertNotNull(this.context.getParent());
|
||||
assertEquals("bootstrap", this.context.getParent().getParent().getId());
|
||||
assertNull(this.context.getParent().getParent().getParent());
|
||||
assertEquals("bar", this.context.getEnvironment().getProperty("custom.foo"));
|
||||
then(TestHigherPriorityBootstrapConfiguration.count.get()).isEqualTo(1);
|
||||
then(this.context.getParent()).isNotNull();
|
||||
then(this.context.getParent().getParent().getId()).isEqualTo("bootstrap");
|
||||
then(this.context.getParent().getParent().getParent()).isNull();
|
||||
then(this.context.getEnvironment().getProperty("custom.foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -292,19 +292,21 @@ public class BootstrapConfigurationTests {
|
||||
this.context = builder.child(BareConfiguration.class)
|
||||
.properties("spring.application.name=context")
|
||||
.web(WebApplicationType.NONE).run();
|
||||
assertEquals(1, TestHigherPriorityBootstrapConfiguration.count.get());
|
||||
assertNotNull(this.context.getParent());
|
||||
assertEquals("bootstrap", this.context.getParent().getParent().getId());
|
||||
assertNull(this.context.getParent().getParent().getParent());
|
||||
assertEquals("context", this.context.getEnvironment().getProperty("custom.foo"));
|
||||
assertEquals("context",
|
||||
this.context.getEnvironment().getProperty("spring.application.name"));
|
||||
assertNotNull(this.sibling.getParent());
|
||||
assertEquals("bootstrap", this.sibling.getParent().getParent().getId());
|
||||
assertNull(this.sibling.getParent().getParent().getParent());
|
||||
assertEquals("sibling", this.sibling.getEnvironment().getProperty("custom.foo"));
|
||||
assertEquals("sibling",
|
||||
this.sibling.getEnvironment().getProperty("spring.application.name"));
|
||||
then(TestHigherPriorityBootstrapConfiguration.count.get()).isEqualTo(1);
|
||||
then(this.context.getParent()).isNotNull();
|
||||
then(this.context.getParent().getParent().getId()).isEqualTo("bootstrap");
|
||||
then(this.context.getParent().getParent().getParent()).isNull();
|
||||
then(this.context.getEnvironment().getProperty("custom.foo"))
|
||||
.isEqualTo("context");
|
||||
then(this.context.getEnvironment().getProperty("spring.application.name"))
|
||||
.isEqualTo("context");
|
||||
then(this.sibling.getParent()).isNotNull();
|
||||
then(this.sibling.getParent().getParent().getId()).isEqualTo("bootstrap");
|
||||
then(this.sibling.getParent().getParent().getParent()).isNull();
|
||||
then(this.sibling.getEnvironment().getProperty("custom.foo"))
|
||||
.isEqualTo("sibling");
|
||||
then(this.sibling.getEnvironment().getProperty("spring.application.name"))
|
||||
.isEqualTo("sibling");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -312,14 +314,16 @@ public class BootstrapConfigurationTests {
|
||||
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
|
||||
this.context = new SpringApplicationBuilder().sources(BareConfiguration.class)
|
||||
.child(BareConfiguration.class).web(WebApplicationType.NONE).run();
|
||||
assertEquals("bar", this.context.getEnvironment().getProperty("bootstrap.foo"));
|
||||
assertNotSame(this.context.getEnvironment(),
|
||||
this.context.getParent().getEnvironment());
|
||||
assertTrue(this.context.getEnvironment().getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME));
|
||||
assertTrue(((ConfigurableEnvironment) this.context.getParent().getEnvironment())
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("bar");
|
||||
then(this.context.getParent().getEnvironment())
|
||||
.isNotSameAs(this.context.getEnvironment());
|
||||
then(this.context.getEnvironment().getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME))
|
||||
.isTrue();
|
||||
then(((ConfigurableEnvironment) this.context.getParent().getEnvironment())
|
||||
.getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME));
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -331,26 +335,29 @@ public class BootstrapConfigurationTests {
|
||||
.web(WebApplicationType.NONE).run();
|
||||
this.context = new SpringApplicationBuilder(BareConfiguration.class)
|
||||
.profiles("child").parent(parent).web(WebApplicationType.NONE).run();
|
||||
assertNotSame(this.context.getEnvironment(),
|
||||
this.context.getParent().getEnvironment());
|
||||
then(this.context.getParent().getEnvironment())
|
||||
.isNotSameAs(this.context.getEnvironment());
|
||||
// The ApplicationContext merges profiles (profiles and property sources), see
|
||||
// AbstractEnvironment.merge()
|
||||
assertTrue(this.context.getEnvironment().acceptsProfiles("child", "parent"));
|
||||
then(this.context.getEnvironment().acceptsProfiles("child", "parent")).isTrue();
|
||||
// But the parent is not a child
|
||||
assertFalse(this.context.getParent().getEnvironment().acceptsProfiles("child"));
|
||||
assertTrue(this.context.getParent().getEnvironment().acceptsProfiles("parent"));
|
||||
assertTrue(((ConfigurableEnvironment) this.context.getParent().getEnvironment())
|
||||
then(this.context.getParent().getEnvironment().acceptsProfiles("child"))
|
||||
.isFalse();
|
||||
then(this.context.getParent().getEnvironment().acceptsProfiles("parent"))
|
||||
.isTrue();
|
||||
then(((ConfigurableEnvironment) this.context.getParent().getEnvironment())
|
||||
.getPropertySources().contains(
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME));
|
||||
assertEquals("bar", this.context.getEnvironment().getProperty("bootstrap.foo"));
|
||||
PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME))
|
||||
.isTrue();
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("bar");
|
||||
// The "bootstrap" property source is not shared now, but it has the same
|
||||
// properties in it because they are pulled from the PropertySourceConfiguration
|
||||
// below
|
||||
assertEquals("bar",
|
||||
this.context.getParent().getEnvironment().getProperty("bootstrap.foo"));
|
||||
then(this.context.getParent().getEnvironment().getProperty("bootstrap.foo"))
|
||||
.isEqualTo("bar");
|
||||
// The parent property source is there in the child because they are both in the
|
||||
// "parent" profile (by virtue of the merge in AbstractEnvironment)
|
||||
assertEquals("parent", this.context.getEnvironment().getProperty("info.name"));
|
||||
then(this.context.getEnvironment().getProperty("info.name")).isEqualTo("parent");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -358,8 +365,8 @@ public class BootstrapConfigurationTests {
|
||||
PropertySourceConfiguration.MAP.put("spring.profiles.include", "bar,baz");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.profiles("foo").sources(BareConfiguration.class).run();
|
||||
assertTrue(this.context.getEnvironment().acceptsProfiles("baz"));
|
||||
assertTrue(this.context.getEnvironment().acceptsProfiles("bar"));
|
||||
then(this.context.getEnvironment().acceptsProfiles("baz")).isTrue();
|
||||
then(this.context.getEnvironment().acceptsProfiles("bar")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -367,8 +374,9 @@ public class BootstrapConfigurationTests {
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.sources(BareConfiguration.class)
|
||||
.properties("spring.cloud.bootstrap.name=local").run();
|
||||
assertTrue(this.context.getEnvironment().acceptsProfiles("local"));
|
||||
assertEquals("Hello added!", this.context.getEnvironment().getProperty("added"));
|
||||
then(this.context.getEnvironment().acceptsProfiles("local")).isTrue();
|
||||
then(this.context.getEnvironment().getProperty("added"))
|
||||
.isEqualTo("Hello added!");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -392,8 +400,8 @@ public class BootstrapConfigurationTests {
|
||||
@Override
|
||||
public PropertySource<?> locate(Environment environment) {
|
||||
if (this.name != null) {
|
||||
assertEquals(this.name,
|
||||
environment.getProperty("spring.application.name"));
|
||||
then(this.name)
|
||||
.isEqualTo(environment.getProperty("spring.application.name"));
|
||||
}
|
||||
if (this.fail) {
|
||||
throw new RuntimeException("Planned");
|
||||
|
||||
@@ -23,9 +23,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.springframework.boot.WebApplicationType.NONE;
|
||||
|
||||
/**
|
||||
@@ -41,7 +39,7 @@ public class BootstrapListenerHierarchyIntegrationTests {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
||||
.sources(BasicConfiguration.class).web(NONE).run();
|
||||
|
||||
assertNotNull(context.getParent());
|
||||
then(context.getParent()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,16 +51,16 @@ public class BootstrapListenerHierarchyIntegrationTests {
|
||||
// Should be RootConfiguration based context
|
||||
ConfigurableApplicationContext parent = (ConfigurableApplicationContext) context
|
||||
.getParent();
|
||||
assertEquals("rootBean", parent.getBean("rootBean", String.class));
|
||||
then(parent.getBean("rootBean", String.class)).isEqualTo("rootBean");
|
||||
|
||||
// Parent should have the bootstrap context as parent
|
||||
assertNotNull(parent.getParent());
|
||||
then(parent.getParent()).isNotNull();
|
||||
|
||||
ConfigurableApplicationContext bootstrapContext = (ConfigurableApplicationContext) parent
|
||||
.getParent();
|
||||
|
||||
// Bootstrap should be the root, there should be no other parent
|
||||
assertNull(bootstrapContext.getParent());
|
||||
then(bootstrapContext.getParent()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,16 +73,16 @@ public class BootstrapListenerHierarchyIntegrationTests {
|
||||
// Should be RootConfiguration based context
|
||||
ConfigurableApplicationContext parent = (ConfigurableApplicationContext) context
|
||||
.getParent();
|
||||
assertEquals("rootBean", parent.getBean("rootBean", String.class));
|
||||
then(parent.getBean("rootBean", String.class)).isEqualTo("rootBean");
|
||||
|
||||
// Parent should have the bootstrap context as parent
|
||||
assertNotNull(parent.getParent());
|
||||
then(parent.getParent()).isNotNull();
|
||||
|
||||
ConfigurableApplicationContext bootstrapContext = (ConfigurableApplicationContext) parent
|
||||
.getParent();
|
||||
|
||||
// Bootstrap should be the root, there should be no other parent
|
||||
assertNull(bootstrapContext.getParent());
|
||||
then(bootstrapContext.getParent()).isNull();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
package org.springframework.cloud.bootstrap.encrypt;
|
||||
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
@@ -16,6 +14,8 @@ package org.springframework.cloud.bootstrap.encrypt;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bootstrap.encrypt;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
@@ -24,9 +24,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.security.crypto.encrypt.TextEncryptor;
|
||||
import org.springframework.security.rsa.crypto.RsaAlgorithm;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
public class EncryptionBootstrapConfigurationTests {
|
||||
|
||||
@@ -36,7 +34,7 @@ public class EncryptionBootstrapConfigurationTests {
|
||||
EncryptionBootstrapConfiguration.class).web(WebApplicationType.NONE)
|
||||
.properties("encrypt.key:pie").run();
|
||||
TextEncryptor encryptor = context.getBean(TextEncryptor.class);
|
||||
assertEquals("foo", encryptor.decrypt(encryptor.encrypt("foo")));
|
||||
then(encryptor.decrypt(encryptor.encrypt("foo"))).isEqualTo("foo");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -51,7 +49,7 @@ public class EncryptionBootstrapConfigurationTests {
|
||||
"encrypt.keyStore.secret:changeme")
|
||||
.run();
|
||||
TextEncryptor encryptor = context.getBean(TextEncryptor.class);
|
||||
assertEquals("foo", encryptor.decrypt(encryptor.encrypt("foo")));
|
||||
then(encryptor.decrypt(encryptor.encrypt("foo"))).isEqualTo("foo");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -66,7 +64,7 @@ public class EncryptionBootstrapConfigurationTests {
|
||||
"encrypt.key-store.secret:changeme")
|
||||
.run();
|
||||
TextEncryptor encryptor = context.getBean(TextEncryptor.class);
|
||||
assertEquals("foo", encryptor.decrypt(encryptor.encrypt("foo")));
|
||||
then(encryptor.decrypt(encryptor.encrypt("foo"))).isEqualTo("foo");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -82,9 +80,9 @@ public class EncryptionBootstrapConfigurationTests {
|
||||
"encrypt.rsa.strong:true", "encrypt.rsa.salt:foobar")
|
||||
.run();
|
||||
RsaProperties properties = context.getBean(RsaProperties.class);
|
||||
assertEquals("foobar", properties.getSalt());
|
||||
assertTrue(properties.isStrong());
|
||||
assertEquals(RsaAlgorithm.DEFAULT, properties.getAlgorithm());
|
||||
then(properties.getSalt()).isEqualTo("foobar");
|
||||
then(properties.isStrong()).isTrue();
|
||||
then(properties.getAlgorithm()).isEqualTo(RsaAlgorithm.DEFAULT);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -98,12 +96,12 @@ public class EncryptionBootstrapConfigurationTests {
|
||||
"encrypt.key-store.alias:mytestkey",
|
||||
"encrypt.key-store.secret:changeme")
|
||||
.run();
|
||||
assertThat(false).as(
|
||||
then(false).as(
|
||||
"Should not create an application context with invalid keystore location")
|
||||
.isTrue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e).hasRootCauseInstanceOf(IllegalStateException.class);
|
||||
then(e).hasRootCauseInstanceOf(IllegalStateException.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bootstrap.encrypt;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -9,7 +25,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
public class EncryptionIntegrationTests {
|
||||
|
||||
@@ -20,7 +36,7 @@ public class EncryptionIntegrationTests {
|
||||
"encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
assertEquals("test", context.getEnvironment().getProperty("foo.password"));
|
||||
then(context.getEnvironment().getProperty("foo.password")).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -30,7 +46,7 @@ public class EncryptionIntegrationTests {
|
||||
"encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
assertEquals("test", context.getBean(PasswordProperties.class).getPassword());
|
||||
then(context.getBean(PasswordProperties.class).getPassword()).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bootstrap.encrypt;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
@@ -24,7 +25,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.security.crypto.encrypt.TextEncryptor;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Biju Kunjummen
|
||||
@@ -41,7 +42,7 @@ public class EncryptorFactoryTests {
|
||||
String toEncrypt = "sample text to encrypt";
|
||||
String encrypted = encryptor.encrypt(toEncrypt);
|
||||
|
||||
assertEquals(toEncrypt, encryptor.decrypt(encrypted));
|
||||
then(encryptor.decrypt(encrypted)).isEqualTo(toEncrypt);
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bootstrap.encrypt;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -34,9 +35,7 @@ import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.security.crypto.encrypt.Encryptors;
|
||||
import org.springframework.security.crypto.encrypt.TextEncryptor;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
@@ -57,7 +56,7 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues.of("foo: {cipher}bar").applyTo(context);
|
||||
this.listener.initialize(context);
|
||||
assertEquals("bar", context.getEnvironment().getProperty("foo"));
|
||||
then(context.getEnvironment().getProperty("foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,7 +65,7 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
TestPropertyValues.of("FOO_TEXT: {cipher}bar").applyTo(context.getEnvironment(),
|
||||
TestPropertyValues.Type.SYSTEM_ENVIRONMENT);
|
||||
this.listener.initialize(context);
|
||||
assertEquals("bar", context.getEnvironment().getProperty("foo.text"));
|
||||
then(context.getEnvironment().getProperty("foo.text")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,7 +76,7 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
.addFirst(new MapPropertySource("test_override",
|
||||
Collections.<String, Object>singletonMap("foo", "{cipher}spam")));
|
||||
this.listener.initialize(context);
|
||||
assertEquals("spam", context.getEnvironment().getProperty("foo"));
|
||||
then(context.getEnvironment().getProperty("foo")).isEqualTo("spam");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,7 +87,7 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
.addFirst(new MapPropertySource("test_override",
|
||||
Collections.<String, Object>singletonMap("foo", "spam")));
|
||||
this.listener.initialize(context);
|
||||
assertEquals("spam", context.getEnvironment().getProperty("foo"));
|
||||
then(context.getEnvironment().getProperty("foo")).isEqualTo("spam");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@@ -98,7 +97,7 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues.of("foo: {cipher}bar").applyTo(context);
|
||||
this.listener.initialize(context);
|
||||
assertEquals("bar", context.getEnvironment().getProperty("foo"));
|
||||
then(context.getEnvironment().getProperty("foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,7 +109,7 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
TestPropertyValues.of("foo: {cipher}bar").applyTo(context);
|
||||
this.listener.initialize(context);
|
||||
// Empty is safest fallback for undecryptable cipher
|
||||
assertEquals("", context.getEnvironment().getProperty("foo"));
|
||||
then(context.getEnvironment().getProperty("foo")).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,21 +130,21 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
.applyTo(context.getEnvironment(), Type.MAP, "combinedTest");
|
||||
this.listener.initialize(context);
|
||||
|
||||
assertEquals("Foo", context.getEnvironment().getProperty("mine[0].someValue"));
|
||||
assertEquals("Foo0", context.getEnvironment().getProperty("mine[0].someKey"));
|
||||
assertEquals("Bar", context.getEnvironment().getProperty("mine[1].someValue"));
|
||||
assertEquals("Bar1", context.getEnvironment().getProperty("mine[1].someKey"));
|
||||
assertEquals("yourFoo",
|
||||
context.getEnvironment().getProperty("yours[0].someValue"));
|
||||
assertEquals("yourBar",
|
||||
context.getEnvironment().getProperty("yours[1].someValue"));
|
||||
then(context.getEnvironment().getProperty("mine[0].someValue")).isEqualTo("Foo");
|
||||
then(context.getEnvironment().getProperty("mine[0].someKey")).isEqualTo("Foo0");
|
||||
then(context.getEnvironment().getProperty("mine[1].someValue")).isEqualTo("Bar");
|
||||
then(context.getEnvironment().getProperty("mine[1].someKey")).isEqualTo("Bar1");
|
||||
then(context.getEnvironment().getProperty("yours[0].someValue"))
|
||||
.isEqualTo("yourFoo");
|
||||
then(context.getEnvironment().getProperty("yours[1].someValue"))
|
||||
.isEqualTo("yourBar");
|
||||
|
||||
MutablePropertySources propertySources = context.getEnvironment()
|
||||
.getPropertySources();
|
||||
PropertySource<Map<?, ?>> decrypted = (PropertySource<Map<?, ?>>) propertySources
|
||||
.get(DECRYPTED_PROPERTY_SOURCE_NAME);
|
||||
assertThat("decrypted property source had wrong size",
|
||||
decrypted.getSource().size(), is(4));
|
||||
then(decrypted.getSource().size()).as("decrypted property source had wrong size")
|
||||
.isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -163,7 +162,7 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
|
||||
initializer.initialize(ctx);
|
||||
|
||||
assertEquals("value", ctx.getEnvironment().getProperty("key"));
|
||||
then(ctx.getEnvironment().getProperty("key")).isEqualTo("value");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -188,11 +187,11 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
|
||||
initializer.initialize(ctx);
|
||||
// validate behaviour with encryption
|
||||
assertEquals("value1b", ctx.getEnvironment().getProperty("key1"));
|
||||
then(ctx.getEnvironment().getProperty("key1")).isEqualTo("value1b");
|
||||
// validate behaviour without encryption
|
||||
assertEquals("value2b", ctx.getEnvironment().getProperty("key2"));
|
||||
then(ctx.getEnvironment().getProperty("key2")).isEqualTo("value2b");
|
||||
// validate behaviour without override
|
||||
assertEquals("value3", ctx.getEnvironment().getProperty("key3"));
|
||||
then(ctx.getEnvironment().getProperty("key3")).isEqualTo("value3");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -207,8 +206,8 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
.addFirst(new MapPropertySource("test_override",
|
||||
Collections.<String, Object>singletonMap("foo", "spam")));
|
||||
initializer.initialize(context);
|
||||
assertEquals("spam", context.getEnvironment().getProperty("foo"));
|
||||
assertEquals("bar2", context.getEnvironment().getProperty("foo2"));
|
||||
then(context.getEnvironment().getProperty("foo")).isEqualTo("spam");
|
||||
then(context.getEnvironment().getProperty("foo2")).isEqualTo("bar2");
|
||||
verify(encryptor).decrypt("bar2");
|
||||
verifyNoMoreInteractions(encryptor);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
package org.springframework.cloud.bootstrap.encrypt;
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
@@ -15,6 +14,8 @@ package org.springframework.cloud.bootstrap.encrypt;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bootstrap.encrypt;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -28,8 +29,7 @@ import org.springframework.cloud.test.ClassPathExclusions;
|
||||
import org.springframework.cloud.test.ModifiedClassPathRunner;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
@@ -60,7 +60,7 @@ public class RsaDisabledTests {
|
||||
public void testLoadBalancedRetryFactoryBean() throws Exception {
|
||||
Map<String, RsaProperties> properties = this.context
|
||||
.getBeansOfType(RsaProperties.class);
|
||||
assertThat(properties.values(), hasSize(0));
|
||||
then(properties.values()).hasSize(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,9 +43,8 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
@@ -72,13 +71,13 @@ public class EnvironmentManagerIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testRefresh() throws Exception {
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
String content = property("message", "Foo");
|
||||
|
||||
this.mvc.perform(post(BASE_PATH + "/env").content(content)
|
||||
.contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
|
||||
.andExpect(content().string("{\"message\":\"Foo\"}"));
|
||||
assertEquals("Foo", this.properties.getMessage());
|
||||
then(this.properties.getMessage()).isEqualTo("Foo");
|
||||
}
|
||||
|
||||
private String property(String name, String value) throws JsonProcessingException {
|
||||
@@ -101,7 +100,7 @@ public class EnvironmentManagerIntegrationTests {
|
||||
catch (ServletException e) {
|
||||
// The underlying BindException is not handled by the dispatcher servlet
|
||||
}
|
||||
assertEquals(0, this.properties.getDelay());
|
||||
then(this.properties.getDelay()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,14 +113,14 @@ public class EnvironmentManagerIntegrationTests {
|
||||
public void environmentBeansConfiguredCorrectly() {
|
||||
Map<String, EnvironmentEndpoint> envbeans = this.context
|
||||
.getBeansOfType(EnvironmentEndpoint.class);
|
||||
assertThat(envbeans).hasSize(1).containsKey("environmentEndpoint");
|
||||
assertThat(envbeans.get("environmentEndpoint"))
|
||||
then(envbeans).hasSize(1).containsKey("environmentEndpoint");
|
||||
then(envbeans.get("environmentEndpoint"))
|
||||
.isInstanceOf(WritableEnvironmentEndpoint.class);
|
||||
|
||||
Map<String, EnvironmentEndpointWebExtension> extbeans = this.context
|
||||
.getBeansOfType(EnvironmentEndpointWebExtension.class);
|
||||
assertThat(extbeans).hasSize(1).containsKey("environmentEndpointWebExtension");
|
||||
assertThat(extbeans.get("environmentEndpointWebExtension"))
|
||||
then(extbeans).hasSize(1).containsKey("environmentEndpointWebExtension");
|
||||
then(extbeans.get("environmentEndpointWebExtension"))
|
||||
.isInstanceOf(WritableEnvironmentEndpointWebExtension.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.environment;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -7,7 +23,7 @@ import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -24,22 +40,22 @@ public class EnvironmentManagerTest {
|
||||
|
||||
environmentManager.setProperty("foo", "bar");
|
||||
|
||||
assertThat(environment.getProperty("foo")).isEqualTo("bar");
|
||||
then(environment.getProperty("foo")).isEqualTo("bar");
|
||||
ArgumentCaptor<ApplicationEvent> eventCaptor = ArgumentCaptor
|
||||
.forClass(ApplicationEvent.class);
|
||||
verify(publisher, times(1)).publishEvent(eventCaptor.capture());
|
||||
assertThat(eventCaptor.getValue()).isInstanceOf(EnvironmentChangeEvent.class);
|
||||
then(eventCaptor.getValue()).isInstanceOf(EnvironmentChangeEvent.class);
|
||||
EnvironmentChangeEvent event = (EnvironmentChangeEvent) eventCaptor.getValue();
|
||||
assertThat(event.getKeys()).containsExactly("foo");
|
||||
then(event.getKeys()).containsExactly("foo");
|
||||
|
||||
reset(publisher);
|
||||
|
||||
environmentManager.reset();
|
||||
assertThat(environment.getProperty("foo")).isNull();
|
||||
then(environment.getProperty("foo")).isNull();
|
||||
verify(publisher, times(1)).publishEvent(eventCaptor.capture());
|
||||
assertThat(eventCaptor.getValue()).isInstanceOf(EnvironmentChangeEvent.class);
|
||||
then(eventCaptor.getValue()).isInstanceOf(EnvironmentChangeEvent.class);
|
||||
event = (EnvironmentChangeEvent) eventCaptor.getValue();
|
||||
assertThat(event.getKeys()).containsExactly("foo");
|
||||
then(event.getKeys()).containsExactly("foo");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.named;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -8,11 +24,7 @@ import org.junit.Test;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
@@ -30,24 +42,24 @@ public class NamedContextFactoryTests {
|
||||
getSpec("bar", BarConfig.class)));
|
||||
|
||||
Foo foo = factory.getInstance("foo", Foo.class);
|
||||
assertThat("foo was null", foo, is(notNullValue()));
|
||||
then(foo).as("foo was null").isNotNull();
|
||||
|
||||
Bar bar = factory.getInstance("bar", Bar.class);
|
||||
assertThat("bar was null", bar, is(notNullValue()));
|
||||
then(bar).as("bar was null").isNotNull();
|
||||
|
||||
assertThat("context names not exposed", factory.getContextNames(),
|
||||
hasItems("foo", "bar"));
|
||||
then(factory.getContextNames()).as("context names not exposed").contains("foo",
|
||||
"bar");
|
||||
|
||||
Bar foobar = factory.getInstance("foo", Bar.class);
|
||||
assertThat("bar was not null", foobar, is(nullValue()));
|
||||
then(foobar).as("bar was not null").isNull();
|
||||
|
||||
Map<String, Baz> fooBazes = factory.getInstances("foo", Baz.class);
|
||||
assertThat("fooBazes was null", fooBazes, is(notNullValue()));
|
||||
assertThat("fooBazes size was wrong", fooBazes.size(), is(1));
|
||||
then(fooBazes).as("fooBazes was null").isNotNull();
|
||||
then(fooBazes.size()).as("fooBazes size was wrong").isEqualTo(1);
|
||||
|
||||
Map<String, Baz> barBazes = factory.getInstances("bar", Baz.class);
|
||||
assertThat("barBazes was null", barBazes, is(notNullValue()));
|
||||
assertThat("barBazes size was wrong", barBazes.size(), is(2));
|
||||
then(barBazes).as("barBazes was null").isNotNull();
|
||||
then(barBazes.size()).as("barBazes size was wrong").isEqualTo(2);
|
||||
|
||||
// get the contexts before destroy() to verify these are the old ones
|
||||
AnnotationConfigApplicationContext fooContext = factory.getContext("foo");
|
||||
@@ -55,9 +67,9 @@ public class NamedContextFactoryTests {
|
||||
|
||||
factory.destroy();
|
||||
|
||||
assertThat("foo context wasn't closed", fooContext.isActive(), is(false));
|
||||
then(fooContext.isActive()).as("foo context wasn't closed").isFalse();
|
||||
|
||||
assertThat("bar context wasn't closed", barContext.isActive(), is(false));
|
||||
then(barContext.isActive()).as("bar context wasn't closed").isFalse();
|
||||
}
|
||||
|
||||
private TestSpec getSpec(String name, Class<?> configClass) {
|
||||
@@ -66,7 +78,7 @@ public class NamedContextFactoryTests {
|
||||
|
||||
static class TestClientFactory extends NamedContextFactory<TestSpec> {
|
||||
|
||||
public TestClientFactory() {
|
||||
TestClientFactory() {
|
||||
super(TestSpec.class, "testfactory", "test.client.name");
|
||||
}
|
||||
|
||||
@@ -78,10 +90,10 @@ public class NamedContextFactoryTests {
|
||||
|
||||
private Class<?>[] configuration;
|
||||
|
||||
public TestSpec() {
|
||||
TestSpec() {
|
||||
}
|
||||
|
||||
public TestSpec(String name, Class<?>[] configuration) {
|
||||
TestSpec(String name, Class<?>[] configuration) {
|
||||
this.name = name;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.properties;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@@ -40,7 +41,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class)
|
||||
@@ -62,50 +63,50 @@ public class ConfigurationPropertiesRebinderIntegrationTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testSimpleProperties() throws Exception {
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
assertEquals(1, this.properties.getCount());
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
// Change the dynamic property source...
|
||||
TestPropertyValues.of("message:Foo").applyTo(this.environment);
|
||||
// ...but don't refresh, so the bean stays the same:
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
assertEquals(1, this.properties.getCount());
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshInParent() throws Exception {
|
||||
assertEquals("main", this.config.getName());
|
||||
then(this.config.getName()).isEqualTo("main");
|
||||
// Change the dynamic property source...
|
||||
TestPropertyValues.of("config.name=foo").applyTo(this.environment);
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
this.rebinder.rebind();
|
||||
assertEquals("foo", this.config.getName());
|
||||
then(this.config.getName()).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefresh() throws Exception {
|
||||
assertEquals(1, this.properties.getCount());
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
TestPropertyValues.of("message:Foo").applyTo(this.environment);
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
this.rebinder.rebind();
|
||||
assertEquals("Foo", this.properties.getMessage());
|
||||
assertEquals(2, this.properties.getCount());
|
||||
then(this.properties.getMessage()).isEqualTo("Foo");
|
||||
then(this.properties.getCount()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshByName() throws Exception {
|
||||
assertEquals(1, this.properties.getCount());
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
TestPropertyValues.of("message:Foo").applyTo(this.environment);
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
this.rebinder.rebind("properties");
|
||||
assertEquals("Foo", this.properties.getMessage());
|
||||
assertEquals(2, this.properties.getCount());
|
||||
then(this.properties.getMessage()).isEqualTo("Foo");
|
||||
then(this.properties.getCount()).isEqualTo(2);
|
||||
}
|
||||
|
||||
interface SomeService {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.properties;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -36,8 +37,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class)
|
||||
@@ -55,14 +55,14 @@ public class ConfigurationPropertiesRebinderLifecycleIntegrationTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefresh() throws Exception {
|
||||
assertEquals(0, this.properties.getCount());
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
then(this.properties.getCount()).isEqualTo(0);
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
TestPropertyValues.of("message:Foo").applyTo(this.environment);
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
this.rebinder.rebind();
|
||||
assertEquals("Foo", this.properties.getMessage());
|
||||
assertEquals(1, this.properties.getCount());
|
||||
then(this.properties.getMessage()).isEqualTo("Foo");
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -110,7 +110,7 @@ public class ConfigurationPropertiesRebinderLifecycleIntegrationTests {
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
assertThat(this.message).isNotEmpty();
|
||||
then(this.message).isNotEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.properties;
|
||||
|
||||
import java.util.List;
|
||||
@@ -41,7 +42,7 @@ import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class, properties = "messages=one,two")
|
||||
@@ -59,22 +60,22 @@ public class ConfigurationPropertiesRebinderListIntegrationTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testAppendProperties() throws Exception {
|
||||
assertEquals("[one, two]", this.properties.getMessages().toString());
|
||||
then("[one, two]").isEqualTo(this.properties.getMessages().toString());
|
||||
TestPropertyValues.of("messages[0]:foo").applyTo(this.environment);
|
||||
this.rebinder.rebind();
|
||||
assertEquals("[foo]", this.properties.getMessages().toString());
|
||||
then(this.properties.getMessages().toString()).isEqualTo("[foo]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
@Ignore("Can't rebind to list and re-initialize it (need refresh scope for this to work)")
|
||||
public void testReplaceProperties() throws Exception {
|
||||
assertEquals("[one, two]", this.properties.getMessages().toString());
|
||||
then("[one, two]").isEqualTo(this.properties.getMessages().toString());
|
||||
Map<String, Object> map = findTestProperties();
|
||||
map.clear();
|
||||
TestPropertyValues.of("messages[0]:foo").applyTo(this.environment);
|
||||
this.rebinder.rebind();
|
||||
assertEquals("[foo]", this.properties.getMessages().toString());
|
||||
then(this.properties.getMessages().toString()).isEqualTo("[foo]");
|
||||
}
|
||||
|
||||
private Map<String, Object> findTestProperties() {
|
||||
@@ -91,12 +92,12 @@ public class ConfigurationPropertiesRebinderListIntegrationTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testReplacePropertiesWithCommaSeparated() throws Exception {
|
||||
assertEquals("[one, two]", this.properties.getMessages().toString());
|
||||
then("[one, two]").isEqualTo(this.properties.getMessages().toString());
|
||||
Map<String, Object> map = findTestProperties();
|
||||
map.clear();
|
||||
TestPropertyValues.of("messages:foo").applyTo(this.environment);
|
||||
this.rebinder.rebind();
|
||||
assertEquals("[foo]", this.properties.getMessages().toString());
|
||||
then(this.properties.getMessages().toString()).isEqualTo("[foo]");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.properties;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -40,7 +41,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class, properties = {
|
||||
@@ -61,10 +62,10 @@ public class ConfigurationPropertiesRebinderProxyIntegrationTests {
|
||||
public void testAppendProperties() throws Exception {
|
||||
// This comes out as a String not Integer if the rebinder processes the proxy
|
||||
// instead of the target
|
||||
assertEquals(new Integer(168), this.properties.getExpiry().get("one"));
|
||||
then(this.properties.getExpiry().get("one")).isEqualTo(new Integer(168));
|
||||
TestPropertyValues.of("messages.expiry.one=56").applyTo(this.environment);
|
||||
this.rebinder.rebind();
|
||||
assertEquals(new Integer(56), this.properties.getExpiry().get("one"));
|
||||
then(this.properties.getExpiry().get("one")).isEqualTo(new Integer(56));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.properties;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@@ -37,7 +38,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class)
|
||||
@@ -58,31 +59,31 @@ public class ConfigurationPropertiesRebinderRefreshScopeIntegrationTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testSimpleProperties() throws Exception {
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
TestPropertyValues.of("message:Foo").applyTo(this.environment);
|
||||
// ...but don't refresh, so the bean stays the same:
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
assertEquals(1, this.properties.getCount());
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefresh() throws Exception {
|
||||
assertEquals(1, this.properties.getCount());
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
assertEquals(1, this.properties.getCount());
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
// Change the dynamic property source...
|
||||
TestPropertyValues.of("message:Foo").applyTo(this.environment);
|
||||
// ...rebind, but the bean is not re-initialized:
|
||||
this.rebinder.rebind();
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
assertEquals(1, this.properties.getCount());
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
this.refreshScope.refreshAll();
|
||||
assertEquals("Foo", this.properties.getMessage());
|
||||
then(this.properties.getMessage()).isEqualTo("Foo");
|
||||
// It's a new instance so the initialization count is 1
|
||||
assertEquals(1, this.properties.getCount());
|
||||
then(this.properties.getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.refresh;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -32,7 +33,7 @@ import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class, properties = {
|
||||
@@ -51,33 +52,33 @@ public class ContextRefresherIntegrationTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testSimpleProperties() throws Exception {
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
this.properties.setMessage("Foo");
|
||||
// ...but don't refresh, so the bean stays the same:
|
||||
assertEquals("Foo", this.properties.getMessage());
|
||||
then(this.properties.getMessage()).isEqualTo("Foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshBean() throws Exception {
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
this.properties.setMessage("Foo");
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
this.refresher.refresh();
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testUpdateHikari() throws Exception {
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
TestPropertyValues.of("spring.datasource.hikari.read-only=true")
|
||||
.applyTo(this.environment);
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
this.refresher.refresh();
|
||||
assertEquals("Hello scope!", this.properties.getMessage());
|
||||
then(this.properties.getMessage()).isEqualTo("Hello scope!");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.refresh;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -24,7 +40,7 @@ import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
public class ContextRefresherTests {
|
||||
|
||||
@@ -43,14 +59,14 @@ public class ContextRefresherTests {
|
||||
"--spring.main.bannerMode=OFF")) {
|
||||
context.getEnvironment().setActiveProfiles("refresh");
|
||||
List<String> names = names(context.getEnvironment().getPropertySources());
|
||||
assertThat(names).doesNotContain(
|
||||
then(names).doesNotContain(
|
||||
"applicationConfig: [classpath:/bootstrap-refresh.properties]");
|
||||
ContextRefresher refresher = new ContextRefresher(context, this.scope);
|
||||
refresher.refresh();
|
||||
names = names(context.getEnvironment().getPropertySources());
|
||||
assertThat(names).contains(
|
||||
then(names).contains(
|
||||
"applicationConfig: [classpath:/bootstrap-refresh.properties]");
|
||||
assertThat(names).containsSequence(
|
||||
then(names).containsSequence(
|
||||
"applicationConfig: [classpath:/application.properties]",
|
||||
"applicationConfig: [classpath:/bootstrap-refresh.properties]",
|
||||
"applicationConfig: [classpath:/bootstrap.properties]");
|
||||
@@ -67,14 +83,14 @@ public class ContextRefresherTests {
|
||||
"--spring.cloud.bootstrap.name=refresh")) {
|
||||
List<String> names = names(context.getEnvironment().getPropertySources());
|
||||
System.err.println("***** " + context.getEnvironment().getPropertySources());
|
||||
assertThat(names).doesNotContain("bootstrapProperties");
|
||||
then(names).doesNotContain("bootstrapProperties");
|
||||
ContextRefresher refresher = new ContextRefresher(context, this.scope);
|
||||
TestPropertyValues.of(
|
||||
"spring.cloud.bootstrap.sources: org.springframework.cloud.context.refresh.ContextRefresherTests.PropertySourceConfiguration")
|
||||
TestPropertyValues.of("spring.cloud.bootstrap.sources: "
|
||||
+ "org.springframework.cloud.context.refresh.ContextRefresherTests.PropertySourceConfiguration")
|
||||
.applyTo(context.getEnvironment(), Type.MAP, "defaultProperties");
|
||||
refresher.refresh();
|
||||
names = names(context.getEnvironment().getPropertySources());
|
||||
assertThat(names).first().isEqualTo("bootstrapProperties");
|
||||
then(names).first().isEqualTo("bootstrapProperties");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,16 +103,16 @@ public class ContextRefresherTests {
|
||||
"--debug=false", "--spring.main.bannerMode=OFF",
|
||||
"--spring.cloud.bootstrap.name=refresh")) {
|
||||
ContextRefresher refresher = new ContextRefresher(context, this.scope);
|
||||
TestPropertyValues.of(
|
||||
"spring.cloud.bootstrap.sources: org.springframework.cloud.context.refresh.ContextRefresherTests.PropertySourceConfiguration")
|
||||
TestPropertyValues.of("spring.cloud.bootstrap.sources: "
|
||||
+ "org.springframework.cloud.context.refresh.ContextRefresherTests.PropertySourceConfiguration")
|
||||
.applyTo(context);
|
||||
ConfigurableApplicationContext refresherContext = refresher
|
||||
.addConfigFilesToEnvironment();
|
||||
assertThat(refresherContext.getParent()).isNotNull()
|
||||
then(refresherContext.getParent()).isNotNull()
|
||||
.isInstanceOf(ConfigurableApplicationContext.class);
|
||||
ConfigurableApplicationContext parent = (ConfigurableApplicationContext) refresherContext
|
||||
.getParent();
|
||||
assertThat(parent.isActive()).isFalse();
|
||||
then(parent.isActive()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,15 +122,15 @@ public class ContextRefresherTests {
|
||||
TestLoggingSystem.class.getName());
|
||||
TestLoggingSystem system = (TestLoggingSystem) LoggingSystem
|
||||
.get(getClass().getClassLoader());
|
||||
assertThat(system.getCount()).isEqualTo(0);
|
||||
then(system.getCount()).isEqualTo(0);
|
||||
try (ConfigurableApplicationContext context = SpringApplication.run(Empty.class,
|
||||
"--spring.main.web-application-type=none", "--debug=false",
|
||||
"--spring.main.bannerMode=OFF",
|
||||
"--spring.cloud.bootstrap.name=refresh")) {
|
||||
assertThat(system.getCount()).isEqualTo(4);
|
||||
then(system.getCount()).isEqualTo(4);
|
||||
ContextRefresher refresher = new ContextRefresher(context, this.scope);
|
||||
refresher.refresh();
|
||||
assertThat(system.getCount()).isEqualTo(4);
|
||||
then(system.getCount()).isEqualTo(4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +146,7 @@ public class ContextRefresherTests {
|
||||
context.getEnvironment().setActiveProfiles("refresh");
|
||||
ContextRefresher refresher = new ContextRefresher(context, this.scope);
|
||||
refresher.refresh();
|
||||
assertThat(TestBootstrapConfiguration.fooSightings).containsExactly("bar",
|
||||
"bar");
|
||||
then(TestBootstrapConfiguration.fooSightings).containsExactly("bar", "bar");
|
||||
}
|
||||
|
||||
TestBootstrapConfiguration.fooSightings = null;
|
||||
|
||||
@@ -25,10 +25,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.LiveBeansView;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
public class RestartIntegrationTests {
|
||||
|
||||
@@ -53,26 +50,26 @@ public class RestartIntegrationTests {
|
||||
"--spring.liveBeansView.mbeanDomain=livebeans");
|
||||
|
||||
RestartEndpoint endpoint = this.context.getBean(RestartEndpoint.class);
|
||||
assertNotNull(this.context.getParent());
|
||||
assertNull(this.context.getParent().getParent());
|
||||
then(this.context.getParent()).isNotNull();
|
||||
then(this.context.getParent().getParent()).isNull();
|
||||
this.context = endpoint.doRestart();
|
||||
|
||||
assertNotNull(this.context);
|
||||
assertNotNull(this.context.getParent());
|
||||
assertNull(this.context.getParent().getParent());
|
||||
then(this.context).isNotNull();
|
||||
then(this.context.getParent()).isNotNull();
|
||||
then(this.context.getParent().getParent()).isNull();
|
||||
|
||||
RestartEndpoint next = this.context.getBean(RestartEndpoint.class);
|
||||
assertNotSame(endpoint, next);
|
||||
then(next).isNotSameAs(endpoint);
|
||||
this.context = next.doRestart();
|
||||
|
||||
assertNotNull(this.context);
|
||||
assertNotNull(this.context.getParent());
|
||||
assertNull(this.context.getParent().getParent());
|
||||
then(this.context).isNotNull();
|
||||
then(this.context.getParent()).isNotNull();
|
||||
then(this.context.getParent().getParent()).isNull();
|
||||
|
||||
LiveBeansView beans = new LiveBeansView();
|
||||
String json = beans.getSnapshotAsJson();
|
||||
assertThat(json).containsOnlyOnce("parent\": \"bootstrap");
|
||||
assertThat(json).containsOnlyOnce("parent\": null");
|
||||
then(json).containsOnlyOnce("parent\": \"bootstrap");
|
||||
then(json).containsOnlyOnce("parent\": null");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -28,7 +29,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class)
|
||||
@@ -45,10 +46,10 @@ public class ImportRefreshScopeIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testSimpleProperties() throws Exception {
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
assertEquals("refresh",
|
||||
this.beanFactory.getBeanDefinition("scopedTarget.service").getScope());
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.beanFactory.getBeanDefinition("scopedTarget.service").getScope())
|
||||
.isEqualTo("refresh");
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
}
|
||||
|
||||
@Configuration("service")
|
||||
|
||||
@@ -42,10 +42,8 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class)
|
||||
@@ -62,7 +60,7 @@ public class MoreRefreshScopeIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
assertEquals(1, TestService.getInitCount());
|
||||
then(TestService.getInitCount()).isEqualTo(1);
|
||||
TestService.reset();
|
||||
}
|
||||
|
||||
@@ -74,20 +72,20 @@ public class MoreRefreshScopeIntegrationTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testSimpleProperties() throws Exception {
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
assertTrue(this.service instanceof Advised);
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.service instanceof Advised).isTrue();
|
||||
// Change the dynamic property source...
|
||||
TestPropertyValues.of("message:Foo").applyTo(this.environment);
|
||||
// ...but don't refresh, so the bean stays the same:
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
assertEquals(0, TestService.getInitCount());
|
||||
assertEquals(0, TestService.getDestroyCount());
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
then(TestService.getInitCount()).isEqualTo(0);
|
||||
then(TestService.getDestroyCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefresh() throws Exception {
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
String id1 = this.service.toString();
|
||||
// Change the dynamic property source...
|
||||
TestPropertyValues.of("message:Foo").applyTo(this.environment, Type.MAP,
|
||||
@@ -96,16 +94,16 @@ public class MoreRefreshScopeIntegrationTests {
|
||||
this.scope.refreshAll();
|
||||
String id2 = this.service.toString();
|
||||
String message = this.service.getMessage();
|
||||
assertEquals("Foo", message);
|
||||
assertEquals(1, TestService.getInitCount());
|
||||
assertEquals(1, TestService.getDestroyCount());
|
||||
assertNotSame(id1, id2);
|
||||
then(message).isEqualTo("Foo");
|
||||
then(TestService.getInitCount()).isEqualTo(1);
|
||||
then(TestService.getDestroyCount()).isEqualTo(1);
|
||||
then(id2).isNotSameAs(id1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshFails() throws Exception {
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
// Change the dynamic property source...
|
||||
TestPropertyValues.of("message:Foo", "delay:foo").applyTo(this.environment);
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
@@ -113,7 +111,7 @@ public class MoreRefreshScopeIntegrationTests {
|
||||
try {
|
||||
// If a refresh fails (e.g. a binding error in this case) the application is
|
||||
// basically hosed.
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
fail("expected BeanCreationException");
|
||||
}
|
||||
catch (BeanCreationException e) {
|
||||
@@ -122,7 +120,7 @@ public class MoreRefreshScopeIntegrationTests {
|
||||
TestPropertyValues.of("delay:0").applyTo(this.environment);
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
this.scope.refreshAll();
|
||||
assertEquals("Foo", this.service.getMessage());
|
||||
then(this.service.getMessage()).isEqualTo("Foo");
|
||||
}
|
||||
|
||||
public static class TestService implements InitializingBean, DisposableBean {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -42,7 +43,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
@@ -50,7 +51,8 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ClientApp.class, properties = "management.endpoints.web.exposure.include=*", webEnvironment = RANDOM_PORT)
|
||||
@SpringBootTest(classes = ClientApp.class, properties = {
|
||||
"management.endpoints.web.exposure.include=*" }, webEnvironment = RANDOM_PORT)
|
||||
public class RefreshEndpointIntegrationTests {
|
||||
|
||||
private static final String BASE_PATH = new WebEndpointProperties().getBasePath();
|
||||
@@ -69,7 +71,7 @@ public class RefreshEndpointIntegrationTests {
|
||||
null, String.class);
|
||||
String message = template.getForObject("http://localhost:" + this.port + "/",
|
||||
String.class);
|
||||
assertEquals("Hello Dave!", message);
|
||||
then(message).isEqualTo("Hello Dave!");
|
||||
}
|
||||
|
||||
private RequestEntity<?> getUrlEncodedEntity(String uri, String key, String value)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -46,9 +47,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.Repeat;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class)
|
||||
@@ -72,7 +71,7 @@ public class RefreshScopeConcurrencyTests {
|
||||
@DirtiesContext
|
||||
public void testConcurrentRefresh() throws Exception {
|
||||
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
this.properties.setMessage("Foo");
|
||||
this.properties.setDelay(500);
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
@@ -89,19 +88,19 @@ public class RefreshScopeConcurrencyTests {
|
||||
}
|
||||
}
|
||||
});
|
||||
assertTrue(latch.await(1500, TimeUnit.MILLISECONDS));
|
||||
then(latch.await(15000, TimeUnit.MILLISECONDS)).isTrue();
|
||||
logger.info("Refreshing");
|
||||
this.scope.refreshAll();
|
||||
assertEquals("Foo", this.service.getMessage());
|
||||
then(this.service.getMessage()).isEqualTo("Foo");
|
||||
/*
|
||||
* This is the most important assertion: we don't want a null value because that
|
||||
* means the bean was destroyed and not re-initialized before we accessed it.
|
||||
*/
|
||||
assertNotNull(result.get());
|
||||
assertEquals("Hello scope!", result.get());
|
||||
then(result.get()).isNotNull();
|
||||
then(result.get()).isEqualTo("Hello scope!");
|
||||
}
|
||||
|
||||
public static interface Service {
|
||||
public interface Service {
|
||||
|
||||
String getMessage();
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -49,11 +50,11 @@ import org.springframework.test.annotation.Repeat;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class, properties = "logging.level.org.springframework.cloud.context.scope.refresh.RefreshScopeConfigurationScaleTests=DEBUG")
|
||||
@SpringBootTest(classes = TestConfiguration.class, properties = {
|
||||
"logging.level.org.springframework.cloud.context.scope.refresh.RefreshScopeConfigurationScaleTests=DEBUG" })
|
||||
public class RefreshScopeConfigurationScaleTests {
|
||||
|
||||
private static Log logger = LogFactory
|
||||
@@ -106,14 +107,14 @@ public class RefreshScopeConfigurationScaleTests {
|
||||
}
|
||||
});
|
||||
}
|
||||
assertTrue(latch.await(15000, TimeUnit.MILLISECONDS));
|
||||
assertEquals("Foo", this.service.getMessage());
|
||||
then(latch.await(15000, TimeUnit.MILLISECONDS)).isTrue();
|
||||
then(this.service.getMessage()).isEqualTo("Foo");
|
||||
for (Future<String> result : results) {
|
||||
assertEquals("Foo", result.get());
|
||||
then(result.get()).isEqualTo("Foo");
|
||||
}
|
||||
}
|
||||
|
||||
public static interface Service {
|
||||
public interface Service {
|
||||
|
||||
String getMessage();
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -34,7 +35,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -74,12 +75,12 @@ public class RefreshScopeConfigurationTests {
|
||||
RefreshAutoConfiguration.class,
|
||||
LifecycleMvcEndpointAutoConfiguration.class);
|
||||
Application application = this.context.getBean(Application.class);
|
||||
assertEquals("refresh",
|
||||
this.context.getBeanDefinition("scopedTarget.application").getScope());
|
||||
then(this.context.getBeanDefinition("scopedTarget.application").getScope())
|
||||
.isEqualTo("refresh");
|
||||
application.hello();
|
||||
refresh();
|
||||
String message = application.hello();
|
||||
assertEquals("Hello Dave!", message);
|
||||
then(message).isEqualTo("Hello Dave!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,7 +93,7 @@ public class RefreshScopeConfigurationTests {
|
||||
application.hello();
|
||||
refresh();
|
||||
String message = application.hello();
|
||||
assertEquals("Hello Dave!", message);
|
||||
then(message).isEqualTo("Hello Dave!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +106,7 @@ public class RefreshScopeConfigurationTests {
|
||||
application.hello();
|
||||
refresh();
|
||||
String message = application.hello();
|
||||
assertEquals("Hello Dave!", message);
|
||||
then(message).isEqualTo("Hello Dave!");
|
||||
}
|
||||
|
||||
// WTF? Maven can't compile without the FQN on this one (not the others).
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -41,10 +42,7 @@ import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class)
|
||||
@@ -61,7 +59,7 @@ public class RefreshScopeIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
assertEquals(1, ExampleService.getInitCount());
|
||||
then(ExampleService.getInitCount()).isEqualTo(1);
|
||||
ExampleService.reset();
|
||||
}
|
||||
|
||||
@@ -73,53 +71,53 @@ public class RefreshScopeIntegrationTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testSimpleProperties() throws Exception {
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
assertTrue(this.service instanceof Advised);
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.service instanceof Advised).isTrue();
|
||||
// Change the dynamic property source...
|
||||
this.properties.setMessage("Foo");
|
||||
// ...but don't refresh, so the bean stays the same:
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
assertEquals(0, ExampleService.getInitCount());
|
||||
assertEquals(0, ExampleService.getDestroyCount());
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
then(ExampleService.getInitCount()).isEqualTo(0);
|
||||
then(ExampleService.getDestroyCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefresh() throws Exception {
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
String id1 = this.service.toString();
|
||||
// Change the dynamic property source...
|
||||
this.properties.setMessage("Foo");
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
this.scope.refreshAll();
|
||||
String id2 = this.service.toString();
|
||||
assertEquals("Foo", this.service.getMessage());
|
||||
assertEquals(1, ExampleService.getInitCount());
|
||||
assertEquals(1, ExampleService.getDestroyCount());
|
||||
assertNotSame(id1, id2);
|
||||
assertNotNull(ExampleService.event);
|
||||
assertEquals(RefreshScopeRefreshedEvent.DEFAULT_NAME,
|
||||
ExampleService.event.getName());
|
||||
then(this.service.getMessage()).isEqualTo("Foo");
|
||||
then(ExampleService.getInitCount()).isEqualTo(1);
|
||||
then(ExampleService.getDestroyCount()).isEqualTo(1);
|
||||
then(id2).isNotSameAs(id1);
|
||||
then(ExampleService.event).isNotNull();
|
||||
then(ExampleService.event.getName())
|
||||
.isEqualTo(RefreshScopeRefreshedEvent.DEFAULT_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshBean() throws Exception {
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
String id1 = this.service.toString();
|
||||
// Change the dynamic property source...
|
||||
this.properties.setMessage("Foo");
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
this.scope.refresh("service");
|
||||
String id2 = this.service.toString();
|
||||
assertEquals("Foo", this.service.getMessage());
|
||||
assertEquals("Foo", this.service.getMessage());
|
||||
assertEquals(1, ExampleService.getInitCount());
|
||||
assertEquals(1, ExampleService.getDestroyCount());
|
||||
assertNotSame(id1, id2);
|
||||
assertNotNull(ExampleService.event);
|
||||
assertEquals(GenericScope.SCOPED_TARGET_PREFIX + "service",
|
||||
ExampleService.event.getName());
|
||||
then(this.service.getMessage()).isEqualTo("Foo");
|
||||
then(this.service.getMessage()).isEqualTo("Foo");
|
||||
then(ExampleService.getInitCount()).isEqualTo(1);
|
||||
then(ExampleService.getDestroyCount()).isEqualTo(1);
|
||||
then(id2).isNotSameAs(id1);
|
||||
then(ExampleService.event).isNotNull();
|
||||
then(ExampleService.event.getName())
|
||||
.isEqualTo(GenericScope.SCOPED_TARGET_PREFIX + "service");
|
||||
}
|
||||
|
||||
// see gh-349
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -43,10 +44,7 @@ import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class)
|
||||
@@ -64,7 +62,7 @@ public class RefreshScopeLazyIntegrationTests {
|
||||
@Before
|
||||
public void init() {
|
||||
// The RefreshScope is lazy (eager=false) so it won't have been instantiated yet
|
||||
assertEquals(0, ExampleService.getInitCount());
|
||||
then(ExampleService.getInitCount()).isEqualTo(0);
|
||||
ExampleService.reset();
|
||||
}
|
||||
|
||||
@@ -76,55 +74,55 @@ public class RefreshScopeLazyIntegrationTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testSimpleProperties() throws Exception {
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
assertTrue(this.service instanceof Advised);
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.service instanceof Advised).isTrue();
|
||||
// Change the dynamic property source...
|
||||
this.properties.setMessage("Foo");
|
||||
// ...but don't refresh, so the bean stays the same:
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
assertEquals(1, ExampleService.getInitCount());
|
||||
assertEquals(0, ExampleService.getDestroyCount());
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
then(ExampleService.getInitCount()).isEqualTo(1);
|
||||
then(ExampleService.getDestroyCount()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefresh() throws Exception {
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
String id1 = this.service.toString();
|
||||
// Change the dynamic property source...
|
||||
this.properties.setMessage("Foo");
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
this.scope.refreshAll();
|
||||
String id2 = this.service.toString();
|
||||
assertEquals("Foo", this.service.getMessage());
|
||||
assertEquals(2, ExampleService.getInitCount());
|
||||
assertEquals(1, ExampleService.getDestroyCount());
|
||||
assertNotSame(id1, id2);
|
||||
assertNotNull(ExampleService.event);
|
||||
assertEquals(RefreshScopeRefreshedEvent.DEFAULT_NAME,
|
||||
ExampleService.event.getName());
|
||||
then(this.service.getMessage()).isEqualTo("Foo");
|
||||
then(ExampleService.getInitCount()).isEqualTo(2);
|
||||
then(ExampleService.getDestroyCount()).isEqualTo(1);
|
||||
then(id2).isNotSameAs(id1);
|
||||
then(ExampleService.event).isNotNull();
|
||||
then(ExampleService.event.getName())
|
||||
.isEqualTo(RefreshScopeRefreshedEvent.DEFAULT_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshBean() throws Exception {
|
||||
assertEquals("Hello scope!", this.service.getMessage());
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
String id1 = this.service.toString();
|
||||
// Change the dynamic property source...
|
||||
this.properties.setMessage("Foo");
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
this.scope.refresh("service");
|
||||
String id2 = this.service.toString();
|
||||
assertEquals("Foo", this.service.getMessage());
|
||||
assertEquals(2, ExampleService.getInitCount());
|
||||
assertEquals(1, ExampleService.getDestroyCount());
|
||||
assertNotSame(id1, id2);
|
||||
assertNotNull(ExampleService.event);
|
||||
assertEquals(GenericScope.SCOPED_TARGET_PREFIX + "service",
|
||||
ExampleService.event.getName());
|
||||
then(this.service.getMessage()).isEqualTo("Foo");
|
||||
then(ExampleService.getInitCount()).isEqualTo(2);
|
||||
then(ExampleService.getDestroyCount()).isEqualTo(1);
|
||||
then(id2).isNotSameAs(id1);
|
||||
then(ExampleService.event).isNotNull();
|
||||
then(ExampleService.event.getName())
|
||||
.isEqualTo(GenericScope.SCOPED_TARGET_PREFIX + "service");
|
||||
}
|
||||
|
||||
public static interface Service {
|
||||
public interface Service {
|
||||
|
||||
String getMessage();
|
||||
|
||||
@@ -212,7 +210,8 @@ public class RefreshScopeLazyIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public static org.springframework.cloud.context.scope.refresh.RefreshScope refreshScope() {
|
||||
org.springframework.cloud.context.scope.refresh.RefreshScope scope = new org.springframework.cloud.context.scope.refresh.RefreshScope();
|
||||
org.springframework.cloud.context.scope.refresh.RefreshScope scope = null;
|
||||
scope = new org.springframework.cloud.context.scope.refresh.RefreshScope();
|
||||
scope.setEager(false);
|
||||
return scope;
|
||||
}
|
||||
|
||||
@@ -42,8 +42,7 @@ import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class, properties = { "test.messages[0]=one",
|
||||
@@ -62,23 +61,23 @@ public class RefreshScopeListBindingIntegrationTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testAppendProperties() throws Exception {
|
||||
assertEquals("[one, two]", this.properties.getMessages().toString());
|
||||
assertTrue(this.properties instanceof Advised);
|
||||
then("[one, two]").isEqualTo(this.properties.getMessages().toString());
|
||||
then(this.properties instanceof Advised).isTrue();
|
||||
TestPropertyValues.of("test.messages[0]:foo").applyTo(this.environment);
|
||||
this.scope.refreshAll();
|
||||
assertEquals("[foo]", this.properties.getMessages().toString());
|
||||
then(this.properties.getMessages().toString()).isEqualTo("[foo]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testReplaceProperties() throws Exception {
|
||||
assertEquals("[one, two]", this.properties.getMessages().toString());
|
||||
assertTrue(this.properties instanceof Advised);
|
||||
then("[one, two]").isEqualTo(this.properties.getMessages().toString());
|
||||
then(this.properties instanceof Advised).isTrue();
|
||||
Map<String, Object> map = findTestProperties();
|
||||
map.clear();
|
||||
TestPropertyValues.of("test.messages[0]:foo").applyTo(this.environment);
|
||||
this.scope.refreshAll();
|
||||
assertEquals("[foo]", this.properties.getMessages().toString());
|
||||
then(this.properties.getMessages().toString()).isEqualTo("[foo]");
|
||||
}
|
||||
|
||||
private Map<String, Object> findTestProperties() {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -29,7 +30,7 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = {
|
||||
@@ -45,8 +46,8 @@ public class RefreshScopeNullBeanIntegrationTests {
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testRefreshBean() {
|
||||
assertThat(this.myCustomComponent.optionalService).isNotNull();
|
||||
assertThat(this.scope).isNotNull();
|
||||
then(this.myCustomComponent.optionalService).isNotNull();
|
||||
then(this.scope).isNotNull();
|
||||
// ...and then refresh, so the bean is re-initialized:
|
||||
// this.scope.refreshAll();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -45,8 +46,7 @@ import org.springframework.test.annotation.Repeat;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class)
|
||||
@@ -96,14 +96,14 @@ public class RefreshScopePureScaleTests {
|
||||
}
|
||||
});
|
||||
}
|
||||
assertTrue(latch.await(15000, TimeUnit.MILLISECONDS));
|
||||
assertEquals("Foo", this.service.getMessage());
|
||||
then(latch.await(15000, TimeUnit.MILLISECONDS)).isTrue();
|
||||
then(this.service.getMessage()).isEqualTo("Foo");
|
||||
for (Future<String> result : results) {
|
||||
assertEquals("Foo", result.get());
|
||||
then(result.get()).isEqualTo("Foo");
|
||||
}
|
||||
}
|
||||
|
||||
public static interface Service {
|
||||
public interface Service {
|
||||
|
||||
String getMessage();
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -46,9 +47,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.Repeat;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = TestConfiguration.class)
|
||||
@@ -95,14 +94,14 @@ public class RefreshScopeScaleTests {
|
||||
}
|
||||
});
|
||||
}
|
||||
assertTrue(latch.await(15000, TimeUnit.MILLISECONDS));
|
||||
assertEquals("Foo", this.service.getMessage());
|
||||
assertNotNull(result.get());
|
||||
assertEquals("Foo", result.get());
|
||||
assertEquals(1, ExampleService.count);
|
||||
then(latch.await(15000, TimeUnit.MILLISECONDS)).isTrue();
|
||||
then(this.service.getMessage()).isEqualTo("Foo");
|
||||
then(result.get()).isNotNull();
|
||||
then(result.get()).isEqualTo("Foo");
|
||||
then(ExampleService.count).isEqualTo(1);
|
||||
}
|
||||
|
||||
public static interface Service {
|
||||
public interface Service {
|
||||
|
||||
String getMessage();
|
||||
|
||||
|
||||
@@ -25,11 +25,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -40,16 +36,16 @@ public class RefreshScopeSerializationTests {
|
||||
public void defaultApplicationContextId() throws Exception {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
TestConfiguration.class).web(WebApplicationType.NONE).run();
|
||||
assertThat(context.getId(), is(equalTo("application-1")));
|
||||
then(context.getId()).isEqualTo("application-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializationIdReproducible() throws Exception {
|
||||
String first = getBeanFactory().getSerializationId();
|
||||
String second = getBeanFactory().getSerializationId();
|
||||
assertThat(first, is(notNullValue()));
|
||||
assertThat(first, is(not(equalTo("application"))));
|
||||
assertThat(first, is(equalTo(second)));
|
||||
then(first).isNotNull();
|
||||
then(first).isNotEqualTo("application");
|
||||
then(first).isEqualTo(second);
|
||||
}
|
||||
|
||||
private DefaultListableBeanFactory getBeanFactory() {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.context.scope.refresh;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -33,7 +34,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -57,8 +58,8 @@ public class RefreshScopeWebIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void scopeOnBeanDefinition() throws Exception {
|
||||
assertEquals("refresh", this.beanFactory
|
||||
.getBeanDefinition("scopedTarget.application").getScope());
|
||||
then(this.beanFactory.getBeanDefinition("scopedTarget.application").getScope())
|
||||
.isEqualTo("refresh");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +68,7 @@ public class RefreshScopeWebIntegrationTests {
|
||||
this.environmentManager.setProperty("message", "Hello Dave!");
|
||||
this.scope.refreshAll();
|
||||
String message = this.application.hello();
|
||||
assertEquals("Hello Dave!", message);
|
||||
then(message).isEqualTo("Hello Dave!");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -47,9 +47,7 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -77,7 +75,7 @@ public class RefreshEndpointTests {
|
||||
ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
|
||||
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
|
||||
Collection<String> keys = endpoint.refresh();
|
||||
assertTrue("Wrong keys: " + keys, keys.contains("added"));
|
||||
then(keys.contains("added")).isTrue().as("Wrong keys: " + keys);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,7 +89,7 @@ public class RefreshEndpointTests {
|
||||
ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
|
||||
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
|
||||
Collection<String> keys = endpoint.refresh();
|
||||
assertTrue("Wrong keys: " + keys, keys.contains("message"));
|
||||
then(keys.contains("message")).isTrue().as("Wrong keys: " + keys);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,7 +106,7 @@ public class RefreshEndpointTests {
|
||||
ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
|
||||
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
|
||||
Collection<String> keys = endpoint.refresh();
|
||||
assertTrue("Wrong keys: " + keys, keys.contains("external.message"));
|
||||
then(keys.contains("external.message")).isTrue().as("Wrong keys: " + keys);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,7 +126,7 @@ public class RefreshEndpointTests {
|
||||
ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
|
||||
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
|
||||
Collection<String> keys = endpoint.refresh();
|
||||
assertFalse("Wrong keys: " + keys, keys.contains("external.message"));
|
||||
then(keys.contains("external.message")).as("Wrong keys: " + keys).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,8 +140,8 @@ public class RefreshEndpointTests {
|
||||
Empty empty = this.context.getBean(Empty.class);
|
||||
endpoint.refresh();
|
||||
int after = empty.events.size();
|
||||
assertEquals("Shutdown hooks not cleaned on refresh", 2, after);
|
||||
assertTrue(empty.events.get(0) instanceof EnvironmentChangeEvent);
|
||||
then(2).isEqualTo(after).as("Shutdown hooks not cleaned on refresh");
|
||||
then(empty.events.get(0) instanceof EnvironmentChangeEvent).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,7 +155,7 @@ public class RefreshEndpointTests {
|
||||
int count = countShutdownHooks();
|
||||
endpoint.refresh();
|
||||
int after = countShutdownHooks();
|
||||
assertEquals("Shutdown hooks not cleaned on refresh", count, after);
|
||||
then(count).isEqualTo(after).as("Shutdown hooks not cleaned on refresh");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.boot.actuate.health.Status;
|
||||
import org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder;
|
||||
import org.springframework.cloud.context.scope.refresh.RefreshScope;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -56,21 +56,21 @@ public class RefreshScopeHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
public void sunnyDay() {
|
||||
assertEquals(Status.UP, this.indicator.health().getStatus());
|
||||
then(this.indicator.health().getStatus()).isEqualTo(Status.UP);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void binderError() {
|
||||
when(this.rebinder.getErrors())
|
||||
.thenReturn(Collections.singletonMap("foo", new RuntimeException("FOO")));
|
||||
assertEquals(Status.DOWN, this.indicator.health().getStatus());
|
||||
then(this.indicator.health().getStatus()).isEqualTo(Status.DOWN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scopeError() {
|
||||
when(this.scope.getErrors())
|
||||
.thenReturn(Collections.singletonMap("foo", new RuntimeException("FOO")));
|
||||
assertEquals(Status.DOWN, this.indicator.health().getStatus());
|
||||
then(this.indicator.health().getStatus()).isEqualTo(Status.DOWN);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,14 +79,14 @@ public class RefreshScopeHealthIndicatorTests {
|
||||
.thenReturn(Collections.singletonMap("foo", new RuntimeException("FOO")));
|
||||
when(this.scope.getErrors())
|
||||
.thenReturn(Collections.singletonMap("bar", new RuntimeException("BAR")));
|
||||
assertEquals(Status.DOWN, this.indicator.health().getStatus());
|
||||
then(this.indicator.health().getStatus()).isEqualTo(Status.DOWN);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullRefreshScope() {
|
||||
ObjectProvider<RefreshScope> scopeProvider = mock(ObjectProvider.class);
|
||||
BDDMockito.willReturn(null).given(scopeProvider).getIfAvailable();
|
||||
assertEquals(Status.UP, this.indicator.health().getStatus());
|
||||
then(this.indicator.health().getStatus()).isEqualTo(Status.UP);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.logging;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -28,8 +29,7 @@ import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -49,26 +49,26 @@ public class LoggingRebinderTests {
|
||||
|
||||
@Test
|
||||
public void logLevelsChanged() {
|
||||
assertFalse(this.logger.isTraceEnabled());
|
||||
then(this.logger.isTraceEnabled()).isFalse();
|
||||
StandardEnvironment environment = new StandardEnvironment();
|
||||
TestPropertyValues.of("logging.level.org.springframework.web=TRACE")
|
||||
.applyTo(environment);
|
||||
this.rebinder.setEnvironment(environment);
|
||||
this.rebinder.onApplicationEvent(new EnvironmentChangeEvent(environment,
|
||||
Collections.singleton("logging.level.org.springframework.web")));
|
||||
assertTrue(this.logger.isTraceEnabled());
|
||||
then(this.logger.isTraceEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logLevelsLowerCase() {
|
||||
assertFalse(this.logger.isTraceEnabled());
|
||||
then(this.logger.isTraceEnabled()).isFalse();
|
||||
StandardEnvironment environment = new StandardEnvironment();
|
||||
TestPropertyValues.of("logging.level.org.springframework.web=trace")
|
||||
.applyTo(environment);
|
||||
this.rebinder.setEnvironment(environment);
|
||||
this.rebinder.onApplicationEvent(new EnvironmentChangeEvent(environment,
|
||||
Collections.singleton("logging.level.org.springframework.web")));
|
||||
assertTrue(this.logger.isTraceEnabled());
|
||||
then(this.logger.isTraceEnabled()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user