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


Java MockPropertySource.setProperty方法代码示例

本文整理汇总了Java中org.springframework.mock.env.MockPropertySource.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java MockPropertySource.setProperty方法的具体用法?Java MockPropertySource.setProperty怎么用?Java MockPropertySource.setProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.mock.env.MockPropertySource的用法示例。


在下文中一共展示了MockPropertySource.setProperty方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: registerServletParamPropertySources_GenericWebApplicationContext

import org.springframework.mock.env.MockPropertySource; //导入方法依赖的package包/类
@Test
public void registerServletParamPropertySources_GenericWebApplicationContext() {
	MockServletContext servletContext = new MockServletContext();
	servletContext.addInitParameter("pCommon", "pCommonContextValue");
	servletContext.addInitParameter("pContext1", "pContext1Value");

	GenericWebApplicationContext ctx = new GenericWebApplicationContext();
	ctx.setServletContext(servletContext);
	ctx.refresh();

	ConfigurableEnvironment environment = ctx.getEnvironment();
	assertThat(environment, instanceOf(StandardServletEnvironment.class));
	MutablePropertySources propertySources = environment.getPropertySources();
	assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));

	// ServletContext params are available
	assertThat(environment.getProperty("pCommon"), is("pCommonContextValue"));
	assertThat(environment.getProperty("pContext1"), is("pContext1Value"));

	// Servlet* PropertySources have precedence over System* PropertySources
	assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)),
			lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME))));

	// Replace system properties with a mock property source for convenience
	MockPropertySource mockSystemProperties = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
	mockSystemProperties.setProperty("pCommon", "pCommonSysPropsValue");
	mockSystemProperties.setProperty("pSysProps1", "pSysProps1Value");
	propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties);

	// assert that servletcontext init params resolve with higher precedence than sysprops
	assertThat(environment.getProperty("pCommon"), is("pCommonContextValue"));
	assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:EnvironmentSystemIntegrationTests.java

示例4: systemEnvironmentBindingFailuresAreIgnored

import org.springframework.mock.env.MockPropertySource; //导入方法依赖的package包/类
@Test
public void systemEnvironmentBindingFailuresAreIgnored() throws Exception {
	setupFactory();
	MutablePropertySources propertySources = new MutablePropertySources();
	MockPropertySource propertySource = new MockPropertySource(
			StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
	propertySource.setProperty("doesNotExist", "foo");
	propertySource.setProperty("name", "bar");
	propertySources.addFirst(propertySource);
	this.factory.setPropertySources(propertySources);
	this.factory.setIgnoreUnknownFields(false);
	this.factory.afterPropertiesSet();
	Foo foo = this.factory.getObject();
	assertThat(foo.name).isEqualTo("bar");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:16,代码来源:PropertiesConfigurationFactoryTests.java

示例5: systemPropertyBindingFailuresAreIgnored

import org.springframework.mock.env.MockPropertySource; //导入方法依赖的package包/类
@Test
public void systemPropertyBindingFailuresAreIgnored() throws Exception {
	setupFactory();
	MutablePropertySources propertySources = new MutablePropertySources();
	MockPropertySource propertySource = new MockPropertySource(
			StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
	propertySource.setProperty("doesNotExist", "foo");
	propertySource.setProperty("name", "bar");
	propertySources.addFirst(propertySource);
	this.factory.setPropertySources(propertySources);
	this.factory.setIgnoreUnknownFields(false);
	this.factory.afterPropertiesSet();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:PropertiesConfigurationFactoryTests.java

示例6: systemEnvironmentBindingFailuresAreIgnored

import org.springframework.mock.env.MockPropertySource; //导入方法依赖的package包/类
@Test
public void systemEnvironmentBindingFailuresAreIgnored() throws Exception {
	setupFactory();
	MutablePropertySources propertySources = new MutablePropertySources();
	MockPropertySource propertySource = new MockPropertySource(
			StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
	propertySource.setProperty("doesNotExist", "foo");
	propertySource.setProperty("name", "bar");
	propertySources.addFirst(propertySource);
	this.factory.setPropertySources(propertySources);
	this.factory.setIgnoreUnknownFields(false);
	this.factory.afterPropertiesSet();
	Foo foo = this.factory.getObject();
	assertEquals("bar", foo.name);
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:16,代码来源:PropertiesConfigurationFactoryTests.java

示例7: exclude

import org.springframework.mock.env.MockPropertySource; //导入方法依赖的package包/类
public static MockPropertySource exclude(MockPropertySource all, String excludePrefix) {
    MockPropertySource source = new MockPropertySource();
    for (String key : all.getPropertyNames()) {
        if (! key.startsWith(excludePrefix)) {
            source.setProperty(key, all.getProperty(key));
        }
    }
    return source;
}
 
开发者ID:CiscoCTA,项目名称:taxii-log-adapter,代码行数:10,代码来源:PropertySourceHelper.java

示例8: exclude

import org.springframework.mock.env.MockPropertySource; //导入方法依赖的package包/类
private MockPropertySource exclude(MockPropertySource all, String excludePrefix) {
    MockPropertySource source = new MockPropertySource();
    for (String key : all.getPropertyNames()) {
        if (! key.startsWith(excludePrefix)) {
            source.setProperty(key, all.getProperty(key));
        }
    }
    return source;
}
 
开发者ID:CiscoCTA,项目名称:taxii-log-adapter,代码行数:10,代码来源:SettingsConfigurationTest.java

示例9: registerServletParamPropertySources_AbstractRefreshableWebApplicationContext

import org.springframework.mock.env.MockPropertySource; //导入方法依赖的package包/类
@Test
public void registerServletParamPropertySources_AbstractRefreshableWebApplicationContext() {
	MockServletContext servletContext = new MockServletContext();
	servletContext.addInitParameter("pCommon", "pCommonContextValue");
	servletContext.addInitParameter("pContext1", "pContext1Value");

	MockServletConfig servletConfig = new MockServletConfig(servletContext);
	servletConfig.addInitParameter("pCommon", "pCommonConfigValue");
	servletConfig.addInitParameter("pConfig1", "pConfig1Value");

	AbstractRefreshableWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.setConfigLocation(EnvironmentAwareBean.class.getName());
	ctx.setServletConfig(servletConfig);
	ctx.refresh();

	ConfigurableEnvironment environment = ctx.getEnvironment();
	assertThat(environment, instanceOf(StandardServletEnvironment.class));
	MutablePropertySources propertySources = environment.getPropertySources();
	assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));
	assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME), is(true));

	// ServletConfig gets precedence
	assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
	assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
			lessThan(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME))));

	// but all params are available
	assertThat(environment.getProperty("pContext1"), is("pContext1Value"));
	assertThat(environment.getProperty("pConfig1"), is("pConfig1Value"));

	// Servlet* PropertySources have precedence over System* PropertySources
	assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
			lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME))));

	// Replace system properties with a mock property source for convenience
	MockPropertySource mockSystemProperties = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
	mockSystemProperties.setProperty("pCommon", "pCommonSysPropsValue");
	mockSystemProperties.setProperty("pSysProps1", "pSysProps1Value");
	propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties);

	// assert that servletconfig params resolve with higher precedence than sysprops
	assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
	assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:45,代码来源:EnvironmentSystemIntegrationTests.java

示例10: registerServletParamPropertySources_StaticWebApplicationContext

import org.springframework.mock.env.MockPropertySource; //导入方法依赖的package包/类
@Test
public void registerServletParamPropertySources_StaticWebApplicationContext() {
	MockServletContext servletContext = new MockServletContext();
	servletContext.addInitParameter("pCommon", "pCommonContextValue");
	servletContext.addInitParameter("pContext1", "pContext1Value");

	MockServletConfig servletConfig = new MockServletConfig(servletContext);
	servletConfig.addInitParameter("pCommon", "pCommonConfigValue");
	servletConfig.addInitParameter("pConfig1", "pConfig1Value");

	StaticWebApplicationContext ctx = new StaticWebApplicationContext();
	ctx.setServletConfig(servletConfig);
	ctx.refresh();

	ConfigurableEnvironment environment = ctx.getEnvironment();
	MutablePropertySources propertySources = environment.getPropertySources();
	assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME), is(true));
	assertThat(propertySources.contains(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME), is(true));

	// ServletConfig gets precedence
	assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
	assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
			lessThan(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME))));

	// but all params are available
	assertThat(environment.getProperty("pContext1"), is("pContext1Value"));
	assertThat(environment.getProperty("pConfig1"), is("pConfig1Value"));

	// Servlet* PropertySources have precedence over System* PropertySources
	assertThat(propertySources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)),
			lessThan(propertySources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME))));

	// Replace system properties with a mock property source for convenience
	MockPropertySource mockSystemProperties = new MockPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
	mockSystemProperties.setProperty("pCommon", "pCommonSysPropsValue");
	mockSystemProperties.setProperty("pSysProps1", "pSysProps1Value");
	propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockSystemProperties);

	// assert that servletconfig params resolve with higher precedence than sysprops
	assertThat(environment.getProperty("pCommon"), is("pCommonConfigValue"));
	assertThat(environment.getProperty("pSysProps1"), is("pSysProps1Value"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:43,代码来源:EnvironmentSystemIntegrationTests.java

示例11: mockPropertySource

import org.springframework.mock.env.MockPropertySource; //导入方法依赖的package包/类
private MockPropertySource mockPropertySource(String name, String value) {
	MockPropertySource propertySource = new MockPropertySource();
	propertySource.setProperty(name, value);
	return propertySource;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:6,代码来源:ApplicationPidFileWriterTests.java


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