本文整理匯總了Java中org.springframework.mock.env.MockEnvironment類的典型用法代碼示例。如果您正苦於以下問題:Java MockEnvironment類的具體用法?Java MockEnvironment怎麽用?Java MockEnvironment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MockEnvironment類屬於org.springframework.mock.env包,在下文中一共展示了MockEnvironment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initialize
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("admin.api.url", "/admin");
environment.setProperty("admin.i18n.path", "/admin/i18n");
environment.setProperty("admin.debug", "true");
applicationContext.setEnvironment(environment);
}
示例2: postProcessZuulFilterEnvironmentTest
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@Test
public void postProcessZuulFilterEnvironmentTest() {
final String ZUUL_ROOT = "zuul.routes";
final String SERVICE_ID = "serviceID";
//given
MockEnvironment environment = new MockEnvironment();
environment.withProperty(ZUUL_ROOT + "." + SERVICE_ID + ".service-id", SERVICE_ID)
.withProperty(ZUUL_ROOT + "." + SERVICE_ID + ".versions", VERSIONS);
PropertyTranslatorPostProcessor processor = new PropertyTranslatorPostProcessor();
//process
processor.postProcessEnvironment(environment, null);
//check
Assert.assertEquals(VERSIONS, environment.getProperty(CUSTOM_SERVICE_VERSIONS_PROP, HashMap.class).get(SERVICE_ID));
}
開發者ID:gorelikov,項目名稱:spring-cloud-discovery-version-filter,代碼行數:18,代碼來源:PropertyTranslatorPostProcessorTest.java
示例3: testPlaceholderBased
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@Test
public void testPlaceholderBased() throws Exception {
MockEnvironment env = new MockEnvironment();
env.setProperty("serverName", "server");
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.setEnvironment(env);
ctx.register(PlaceholderBasedConfiguration.class);
ctx.refresh();
try {
MBeanServer server = (MBeanServer) ctx.getBean("server");
ObjectName oname = ObjectNameManager.getInstance("bean:name=testBean4");
assertNotNull(server.getObjectInstance(oname));
String name = (String) server.getAttribute(oname, "Name");
assertEquals("Invalid name returned", "TEST", name);
}
finally {
ctx.close();
}
}
示例4: explicitPropertySourcesExcludesEnvironment
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@Test
public void explicitPropertySourcesExcludesEnvironment() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean",
genericBeanDefinition(TestBean.class)
.addPropertyValue("name", "${my.name}")
.getBeanDefinition());
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addLast(new MockPropertySource());
PropertySourcesPlaceholderConfigurer pc = new PropertySourcesPlaceholderConfigurer();
pc.setPropertySources(propertySources);
pc.setEnvironment(new MockEnvironment().withProperty("my.name", "env"));
pc.setIgnoreUnresolvablePlaceholders(true);
pc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("${my.name}"));
assertEquals(pc.getAppliedPropertySources().iterator().next(), propertySources.iterator().next());
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:PropertySourcesPlaceholderConfigurerTests.java
示例5: withNonEnumerablePropertySource
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@Test
public void withNonEnumerablePropertySource() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean",
genericBeanDefinition(TestBean.class)
.addPropertyValue("name", "${foo}")
.getBeanDefinition());
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
PropertySource<?> ps = new PropertySource<Object>("simplePropertySource", new Object()) {
@Override
public Object getProperty(String key) {
return "bar";
}
};
MockEnvironment env = new MockEnvironment();
env.getPropertySources().addFirst(ps);
ppc.setEnvironment(env);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("bar"));
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:PropertySourcesPlaceholderConfigurerTests.java
示例6: localPropertiesOverride
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@SuppressWarnings("serial")
private void localPropertiesOverride(boolean override) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean",
genericBeanDefinition(TestBean.class)
.addPropertyValue("name", "${foo}")
.getBeanDefinition());
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setLocalOverride(override);
ppc.setProperties(new Properties() {{ setProperty("foo", "local"); }});
ppc.setEnvironment(new MockEnvironment().withProperty("foo", "enclosing"));
ppc.postProcessBeanFactory(bf);
if (override) {
assertThat(bf.getBean(TestBean.class).getName(), equalTo("local"));
}
else {
assertThat(bf.getBean(TestBean.class).getName(), equalTo("enclosing"));
}
}
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:PropertySourcesPlaceholderConfigurerTests.java
示例7: trusted_destination_config_with_cidr_and_port_range
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@Test
public void trusted_destination_config_with_cidr_and_port_range() {
MockEnvironment env = new MockEnvironment();
this.context = new AnnotationConfigApplicationContext();
env.setProperty("broker.filter.trusted.destination.hosts", "192.168.0.1/29");
env.setProperty("broker.filter.trusted.destination.ports", "3306-3310");
this.context.setEnvironment(env);
this.context.register(SpecificationConfig.DefaultSpecificationConfig.class, SpecificationConfig.AllowedDestinationSpecificationConfig.class);
this.context.refresh();
final TrustedDestination trustedDestination = this.context.getBean(TrustedDestination.class);
Assertions.assertThat(trustedDestination).isEqualTo(ImmutableTrustedDestination.builder()
.hosts(ImmutableCIDR.of("192.168.0.1/29"))
.ports(ImmutablePortRange.builder().from(ImmutablePort.of(3306)).to(ImmutablePort.of(3310)).build())
.build());
}
示例8: trusted_destination_config_with_cidr_and_port_list
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@Test
public void trusted_destination_config_with_cidr_and_port_list() {
MockEnvironment env = new MockEnvironment();
this.context = new AnnotationConfigApplicationContext();
env.setProperty("broker.filter.trusted.destination.hosts", "192.168.0.1/29");
env.setProperty("broker.filter.trusted.destination.ports", "3306,3310");
this.context.setEnvironment(env);
this.context.register(SpecificationConfig.DefaultSpecificationConfig.class, SpecificationConfig.AllowedDestinationSpecificationConfig.class);
this.context.refresh();
final TrustedDestination trustedDestination = this.context.getBean(TrustedDestination.class);
Assertions.assertThat(trustedDestination).isEqualTo(ImmutableTrustedDestination.builder()
.hosts(ImmutableCIDR.of("192.168.0.1/29"))
.ports(ImmutablePorts.builder().addValue(3306).addValue(3310).build())
.build());
}
示例9: trusted_destination_config_with_cidr_and_single_port
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@Test
public void trusted_destination_config_with_cidr_and_single_port() {
MockEnvironment env = new MockEnvironment();
this.context = new AnnotationConfigApplicationContext();
env.setProperty("broker.filter.trusted.destination.hosts", "192.168.0.1/29");
env.setProperty("broker.filter.trusted.destination.ports", "3306");
this.context.setEnvironment(env);
this.context.register(SpecificationConfig.DefaultSpecificationConfig.class, SpecificationConfig.AllowedDestinationSpecificationConfig.class);
this.context.refresh();
final TrustedDestination trustedDestination = this.context.getBean(TrustedDestination.class);
Assertions.assertThat(trustedDestination).isEqualTo(ImmutableTrustedDestination.builder()
.hosts(ImmutableCIDR.of("192.168.0.1/29"))
.ports(ImmutablePorts.builder().addValue(3306).build())
.build());
}
示例10: testCustomShellProperties
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@Test
public void testCustomShellProperties() throws Exception {
MockEnvironment env = new MockEnvironment();
env.setProperty("management.shell.auth.type", "simple");
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.setEnvironment(env);
ctx.setServletContext(new MockServletContext());
ctx.register(TestShellConfiguration.class);
ctx.register(CrshAutoConfiguration.class);
ctx.refresh();
PluginLifeCycle lifeCycle = ctx.getBean(PluginLifeCycle.class);
String uuid = lifeCycle.getConfig().getProperty("test.uuid");
assertThat(uuid).isEqualTo(TestShellConfiguration.uuid);
ctx.close();
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:17,代碼來源:ShellPropertiesTests.java
示例11: testEndpointMBeanExporterWithProperties
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@Test
public void testEndpointMBeanExporterWithProperties() throws IntrospectionException,
InstanceNotFoundException, MalformedObjectNameException, ReflectionException {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("endpoints.jmx.domain", "test-domain");
environment.setProperty("endpoints.jmx.unique_names", "true");
environment.setProperty("endpoints.jmx.static_names", "key1=value1, key2=value2");
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);
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertThat(mbeanExporter.getServer().getMBeanInfo(ObjectNameManager.getInstance(
getObjectName("test-domain", "healthEndpoint", this.context).toString()
+ ",key1=value1,key2=value2"))).isNotNull();
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:20,代碼來源:EndpointMBeanExportAutoConfigurationTests.java
示例12: testDefaultDomainConfiguredOnMBeanExport
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@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");
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:17,代碼來源:JmxAutoConfigurationTests.java
示例13: setup
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@Before
public void setup() {
servletContext = spy(new MockServletContext());
doReturn(new MockFilterRegistration())
.when(servletContext).addFilter(anyString(), any(Filter.class));
doReturn(new MockServletRegistration())
.when(servletContext).addServlet(anyString(), any(Servlet.class));
env = new MockEnvironment();
props = new JHipsterProperties();
webConfigurer = new WebConfigurer(env, props, new MockHazelcastInstance());
metricRegistry = new MetricRegistry();
webConfigurer.setMetricRegistry(metricRegistry);
}
示例14: setup
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@Before
public void setup() {
servletContext = spy(new MockServletContext());
doReturn(new MockFilterRegistration())
.when(servletContext).addFilter(anyString(), any(Filter.class));
doReturn(new MockServletRegistration())
.when(servletContext).addServlet(anyString(), any(Servlet.class));
env = new MockEnvironment();
props = new JHipsterProperties();
webConfigurer = new WebConfigurer(env, props);
metricRegistry = new MetricRegistry();
webConfigurer.setMetricRegistry(metricRegistry);
}
示例15: setEnvironmentWithSpringApplicationNameShouldSetComponentName
import org.springframework.mock.env.MockEnvironment; //導入依賴的package包/類
@Test
public void setEnvironmentWithSpringApplicationNameShouldSetComponentName() {
CereebroProperties c = new CereebroProperties();
MockEnvironment env = new MockEnvironment();
env.setProperty("spring.application.name", "cyclop");
c.setEnvironment(env);
Assert.assertEquals("cyclop", c.getApplication().getComponent().getName());
}