本文整理汇总了Java中org.springframework.mock.env.MockPropertySource类的典型用法代码示例。如果您正苦于以下问题:Java MockPropertySource类的具体用法?Java MockPropertySource怎么用?Java MockPropertySource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MockPropertySource类属于org.springframework.mock.env包,在下文中一共展示了MockPropertySource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: explicitPropertySources
import org.springframework.mock.env.MockPropertySource; //导入依赖的package包/类
@Test
public void explicitPropertySources() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean",
genericBeanDefinition(TestBean.class)
.addPropertyValue("name", "${my.name}")
.getBeanDefinition());
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addLast(new MockPropertySource().withProperty("my.name", "foo"));
PropertySourcesPlaceholderConfigurer pc = new PropertySourcesPlaceholderConfigurer();
pc.setPropertySources(propertySources);
pc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("foo"));
assertEquals(pc.getAppliedPropertySources().iterator().next(), propertySources.iterator().next());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:PropertySourcesPlaceholderConfigurerTests.java
示例2: explicitPropertySourcesExcludesEnvironment
import org.springframework.mock.env.MockPropertySource; //导入依赖的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
示例3: explicitPropertySourcesExcludesLocalProperties
import org.springframework.mock.env.MockPropertySource; //导入依赖的package包/类
@Test
@SuppressWarnings("serial")
public void explicitPropertySourcesExcludesLocalProperties() {
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.setProperties(new Properties() {{
put("my.name", "local");
}});
pc.setIgnoreUnresolvablePlaceholders(true);
pc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("${my.name}"));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:PropertySourcesPlaceholderConfigurerTests.java
示例4: getPropertySources_replacePropertySource
import org.springframework.mock.env.MockPropertySource; //导入依赖的package包/类
@Test
public void getPropertySources_replacePropertySource() {
propertySources = new MutablePropertySources();
propertyResolver = new PropertySourcesPropertyResolver(propertySources);
propertySources.addLast(new MockPropertySource("local").withProperty("foo", "localValue"));
propertySources.addLast(new MockPropertySource("system").withProperty("foo", "systemValue"));
// 'local' was added first so has precedence
assertThat(propertyResolver.getProperty("foo"), equalTo("localValue"));
// replace 'local' with new property source
propertySources.replace("local", new MockPropertySource("new").withProperty("foo", "newValue"));
// 'system' now has precedence
assertThat(propertyResolver.getProperty("foo"), equalTo("newValue"));
assertThat(propertySources.size(), is(2));
}
示例5: explicitPropertySources
import org.springframework.mock.env.MockPropertySource; //导入依赖的package包/类
@Test
public void explicitPropertySources() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean",
genericBeanDefinition(TestBean.class)
.addPropertyValue("name", "${my.name}")
.getBeanDefinition());
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addLast(new MockPropertySource().withProperty("my.name", "foo"));
PropertySourcesPlaceholderConfigurer pc = new PropertySourcesPlaceholderConfigurer();
pc.setPropertySources(propertySources);
pc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("foo"));
}
示例6: explicitPropertySourcesExcludesEnvironment
import org.springframework.mock.env.MockPropertySource; //导入依赖的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}"));
}
示例7: placeHolderConfigurer
import org.springframework.mock.env.MockPropertySource; //导入依赖的package包/类
@Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setIgnoreResourceNotFound(true);
configurer.setIgnoreUnresolvablePlaceholders(true);
MutablePropertySources propertySources = new MutablePropertySources();
MockPropertySource source = new MockPropertySource()
.withProperty("rabbitmq.host", "192.168.10.10")
.withProperty("rabbitmq.port", "5673")
.withProperty("rabbitmq.username", "jfw")
.withProperty("rabbitmq.password", "jfw")
.withProperty("rabbitmq.channel-cache-size", 100);
propertySources.addLast(source);
configurer.setPropertySources(propertySources);
return configurer;
}
示例8: handleReturnValue_withExpressionInSendToName_templateIsCalled
import org.springframework.mock.env.MockPropertySource; //导入依赖的package包/类
@Test
public void handleReturnValue_withExpressionInSendToName_templateIsCalled() throws Exception {
// Arrange
Method validSendToMethod = this.getClass().getDeclaredMethod("expressionMethod");
MethodParameter methodParameter = new MethodParameter(validSendToMethod, -1);
GenericApplicationContext applicationContext = new GenericApplicationContext();
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("queueName", "myTestQueue");
applicationContext.getEnvironment().getPropertySources().addLast(propertySource);
applicationContext.refresh();
SendToHandlerMethodReturnValueHandler sendToHandlerMethodReturnValueHandler = new SendToHandlerMethodReturnValueHandler(this.messageTemplate);
sendToHandlerMethodReturnValueHandler.setBeanFactory(applicationContext.getAutowireCapableBeanFactory());
// Act
sendToHandlerMethodReturnValueHandler.handleReturnValue("expression method", methodParameter, MessageBuilder.withPayload("Nothing").build());
// Assert
verify(this.messageTemplate, times(1)).convertAndSend(eq("myTestQueue"), eq("expression method"));
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:23,代码来源:SendToHandlerMethodReturnValueHandlerTest.java
示例9: handleReturnValue_withPlaceHolderInSendToName_templateIsCalled
import org.springframework.mock.env.MockPropertySource; //导入依赖的package包/类
@Test
public void handleReturnValue_withPlaceHolderInSendToName_templateIsCalled() throws Exception {
// Arrange
Method validSendToMethod = this.getClass().getDeclaredMethod("placeHolderMethod");
MethodParameter methodParameter = new MethodParameter(validSendToMethod, -1);
GenericApplicationContext applicationContext = new GenericApplicationContext();
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("placeholderQueueName", "myTestQueue");
applicationContext.getEnvironment().getPropertySources().addLast(propertySource);
applicationContext.registerBeanDefinition("resolver", BeanDefinitionBuilder.genericBeanDefinition(PropertySourcesPlaceholderConfigurer.class).getBeanDefinition());
applicationContext.refresh();
SendToHandlerMethodReturnValueHandler sendToHandlerMethodReturnValueHandler = new SendToHandlerMethodReturnValueHandler(this.messageTemplate);
sendToHandlerMethodReturnValueHandler.setBeanFactory(applicationContext.getAutowireCapableBeanFactory());
// Act
sendToHandlerMethodReturnValueHandler.handleReturnValue("placeholder method", methodParameter, MessageBuilder.withPayload("Nothing").build());
// Assert
verify(this.messageTemplate, times(1)).convertAndSend(eq("myTestQueue"), eq("placeholder method"));
}
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:25,代码来源:SendToHandlerMethodReturnValueHandlerTest.java
示例10: braceAccess
import org.springframework.mock.env.MockPropertySource; //导入依赖的package包/类
@Test
@SuppressWarnings("all")
public void braceAccess() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean",
genericBeanDefinition(TestBean.class)
.addPropertyValue("name", "#{environment['my.name']}")
.getBeanDefinition());
GenericApplicationContext ctx = new GenericApplicationContext(bf);
ctx.getEnvironment().getPropertySources().addFirst(new MockPropertySource().withProperty("my.name", "myBean"));
ctx.refresh();
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("myBean"));
}
示例11: getProperty_propertySourceSearchOrderIsFIFO
import org.springframework.mock.env.MockPropertySource; //导入依赖的package包/类
@Test
public void getProperty_propertySourceSearchOrderIsFIFO() {
MutablePropertySources sources = new MutablePropertySources();
PropertyResolver resolver = new PropertySourcesPropertyResolver(sources);
sources.addFirst(new MockPropertySource("ps1").withProperty("pName", "ps1Value"));
assertThat(resolver.getProperty("pName"), equalTo("ps1Value"));
sources.addFirst(new MockPropertySource("ps2").withProperty("pName", "ps2Value"));
assertThat(resolver.getProperty("pName"), equalTo("ps2Value"));
sources.addFirst(new MockPropertySource("ps3").withProperty("pName", "ps3Value"));
assertThat(resolver.getProperty("pName"), equalTo("ps3Value"));
}
示例12: resolvePlaceholders
import org.springframework.mock.env.MockPropertySource; //导入依赖的package包/类
@Test
public void resolvePlaceholders() {
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new MockPropertySource().withProperty("key", "value"));
PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
assertThat(resolver.resolvePlaceholders("Replace this ${key}"), equalTo("Replace this value"));
}
示例13: resolvePlaceholders_withUnresolvable
import org.springframework.mock.env.MockPropertySource; //导入依赖的package包/类
@Test
public void resolvePlaceholders_withUnresolvable() {
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new MockPropertySource().withProperty("key", "value"));
PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
assertThat(resolver.resolvePlaceholders("Replace this ${key} plus ${unknown}"),
equalTo("Replace this value plus ${unknown}"));
}
示例14: resolvePlaceholders_withDefaultValue
import org.springframework.mock.env.MockPropertySource; //导入依赖的package包/类
@Test
public void resolvePlaceholders_withDefaultValue() {
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new MockPropertySource().withProperty("key", "value"));
PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
assertThat(resolver.resolvePlaceholders("Replace this ${key} plus ${unknown:defaultValue}"),
equalTo("Replace this value plus defaultValue"));
}
示例15: resolveRequiredPlaceholders
import org.springframework.mock.env.MockPropertySource; //导入依赖的package包/类
@Test
public void resolveRequiredPlaceholders() {
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addFirst(new MockPropertySource().withProperty("key", "value"));
PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
assertThat(resolver.resolveRequiredPlaceholders("Replace this ${key}"), equalTo("Replace this value"));
}