use of org.springframework.mock.env.MockEnvironment in project spring-framework by spring-projects.
the class TestPropertySourceUtilsTests method addInlinedPropertiesToEnvironmentWithEmptyProperty.
@Test
@SuppressWarnings("rawtypes")
public void addInlinedPropertiesToEnvironmentWithEmptyProperty() {
ConfigurableEnvironment environment = new MockEnvironment();
MutablePropertySources propertySources = environment.getPropertySources();
propertySources.remove(MockPropertySource.MOCK_PROPERTIES_PROPERTY_SOURCE_NAME);
assertEquals(0, propertySources.size());
addInlinedPropertiesToEnvironment(environment, asArray(" "));
assertEquals(1, propertySources.size());
assertEquals(0, ((Map) propertySources.iterator().next().getSource()).size());
}
use of org.springframework.mock.env.MockEnvironment in project spring-boot by spring-projects.
the class EndpointMBeanExportAutoConfigurationTests method testEndpointMBeanExporterIsNotInstalled.
@Test(expected = NoSuchBeanDefinitionException.class)
public void testEndpointMBeanExporterIsNotInstalled() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("endpoints.jmx.enabled", "false");
this.context = new AnnotationConfigApplicationContext();
this.context.setEnvironment(environment);
this.context.register(JmxAutoConfiguration.class, EndpointAutoConfiguration.class, EndpointMBeanExportAutoConfiguration.class);
this.context.refresh();
this.context.getBean(EndpointMBeanExporter.class);
}
use of org.springframework.mock.env.MockEnvironment in project spring-boot by spring-projects.
the class JmxAutoConfigurationTests method testDefaultDomainConfiguredOnMBeanExport.
@Test
public void testDefaultDomainConfiguredOnMBeanExport() {
MockEnvironment env = new MockEnvironment();
env.setProperty("spring.jmx.enabled", "true");
env.setProperty("spring.jmx.default-domain", "my-test-domain");
this.context = new AnnotationConfigApplicationContext();
this.context.setEnvironment(env);
this.context.register(TestConfiguration.class, JmxAutoConfiguration.class);
this.context.refresh();
MBeanExporter mBeanExporter = this.context.getBean(MBeanExporter.class);
assertThat(mBeanExporter).isNotNull();
MetadataNamingStrategy naming = (MetadataNamingStrategy) ReflectionTestUtils.getField(mBeanExporter, "namingStrategy");
assertThat(ReflectionTestUtils.getField(naming, "defaultDomain")).isEqualTo("my-test-domain");
}
use of org.springframework.mock.env.MockEnvironment in project spring-boot by spring-projects.
the class ResourceBannerTests method printBanner.
private String printBanner(Resource resource, String bootVersion, String applicationVersion, String applicationTitle) {
ResourceBanner banner = new MockResourceBanner(resource, bootVersion, applicationVersion, applicationTitle);
ConfigurableEnvironment environment = new MockEnvironment();
Map<String, Object> source = Collections.<String, Object>singletonMap("a", "1");
environment.getPropertySources().addLast(new MapPropertySource("map", source));
ByteArrayOutputStream out = new ByteArrayOutputStream();
banner.printBanner(environment, getClass(), new PrintStream(out));
return out.toString();
}
use of org.springframework.mock.env.MockEnvironment in project spring-boot by spring-projects.
the class ImageBannerTests method printBanner.
private String printBanner(String path, String... properties) {
ImageBanner banner = new ImageBanner(new ClassPathResource(path, getClass()));
ConfigurableEnvironment environment = new MockEnvironment();
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment, properties);
ByteArrayOutputStream out = new ByteArrayOutputStream();
banner.printBanner(environment, getClass(), new PrintStream(out));
return out.toString();
}
Aggregations