当前位置: 首页>>代码示例>>Java>>正文


Java MockPropertySource类代码示例

本文整理汇总了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));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:PropertySourcesPropertyResolverTests.java

示例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"));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:17,代码来源:PropertySourcesPlaceholderConfigurerTests.java

示例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}"));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:19,代码来源:PropertySourcesPlaceholderConfigurerTests.java

示例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;
}
 
开发者ID:ctc-g,项目名称:sinavi-jfw,代码行数:17,代码来源:OverrideProperties.java

示例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"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:EnvironmentAccessorIntegrationTests.java

示例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"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:PropertySourcesPropertyResolverTests.java

示例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"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:PropertySourcesPropertyResolverTests.java

示例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}"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:PropertySourcesPropertyResolverTests.java

示例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"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:PropertySourcesPropertyResolverTests.java

示例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"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:PropertySourcesPropertyResolverTests.java


注:本文中的org.springframework.mock.env.MockPropertySource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。