use of org.springframework.context.support.StaticApplicationContext in project spring-integration by spring-projects.
the class HeaderValueRouterTests method resolveChannelNameFromMapAndCustomeResolver.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void resolveChannelNameFromMapAndCustomeResolver() {
final StaticApplicationContext context = new StaticApplicationContext();
ManagedMap channelMappings = new ManagedMap();
channelMappings.put("testKey", "testChannel");
RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
routerBeanDefinition.getPropertyValues().addPropertyValue("channelMappings", channelMappings);
routerBeanDefinition.getPropertyValues().addPropertyValue("beanFactory", context);
routerBeanDefinition.getPropertyValues().addPropertyValue("channelResolver", (DestinationResolver<MessageChannel>) channelName -> context.getBean("anotherChannel", MessageChannel.class));
context.registerBeanDefinition("router", routerBeanDefinition);
context.registerBeanDefinition("testChannel", new RootBeanDefinition(QueueChannel.class));
context.registerBeanDefinition("anotherChannel", new RootBeanDefinition(QueueChannel.class));
context.refresh();
MessageHandler handler = (MessageHandler) context.getBean("router");
Message<?> message = MessageBuilder.withPayload("test").setHeader("testHeaderName", "testKey").build();
handler.handleMessage(message);
QueueChannel channel = (QueueChannel) context.getBean("anotherChannel");
Message<?> result = channel.receive(1000);
assertNotNull(result);
assertSame(message, result);
context.close();
}
use of org.springframework.context.support.StaticApplicationContext in project spring-integration by spring-projects.
the class HeaderValueRouterTests method resolveMultipleChannelsWithStringArray.
@Test
public void resolveMultipleChannelsWithStringArray() {
StaticApplicationContext context = new StaticApplicationContext();
RootBeanDefinition routerBeanDefinition = new RootBeanDefinition(HeaderValueRouter.class);
routerBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue("testHeaderName");
routerBeanDefinition.getPropertyValues().addPropertyValue("resolutionRequired", "true");
context.registerBeanDefinition("router", routerBeanDefinition);
context.registerBeanDefinition("channel1", new RootBeanDefinition(QueueChannel.class));
context.registerBeanDefinition("channel2", new RootBeanDefinition(QueueChannel.class));
context.refresh();
MessageHandler handler = (MessageHandler) context.getBean("router");
String[] channels = new String[] { "channel1", "channel2" };
Message<?> message = MessageBuilder.withPayload("test").setHeader("testHeaderName", channels).build();
handler.handleMessage(message);
QueueChannel channel1 = (QueueChannel) context.getBean("channel1");
QueueChannel channel2 = (QueueChannel) context.getBean("channel2");
Message<?> result1 = channel1.receive(1000);
Message<?> result2 = channel2.receive(1000);
assertNotNull(result1);
assertNotNull(result2);
assertSame(message, result1);
assertSame(message, result2);
context.close();
}
use of org.springframework.context.support.StaticApplicationContext in project spring-cloud-function by spring-cloud.
the class FunctionProxyApplicationListener method bind.
private void bind(ConfigurableApplicationContext context) {
ConfigurationPropertiesBindingPostProcessor post = new ConfigurationPropertiesBindingPostProcessor();
post.setBeanFactory(new DefaultListableBeanFactory());
post.setEnvironment(context.getEnvironment());
post.setApplicationContext(new StaticApplicationContext());
try {
post.afterPropertiesSet();
} catch (Exception e) {
throw new IllegalStateException("Cannot bind properties", e);
}
post.postProcessBeforeInitialization(this, getClass().getName());
}
use of org.springframework.context.support.StaticApplicationContext in project spring-cloud-stream by spring-cloud.
the class BinderPropertiesTests method testSerializationWithNonStringValues.
@SuppressWarnings("unchecked")
@Test
public void testSerializationWithNonStringValues() {
StaticApplicationContext context = new StaticApplicationContext();
DefaultListableBeanFactory bf = (DefaultListableBeanFactory) context.getBeanFactory();
BindingServiceProperties bindingServiceProperties = new BindingServiceProperties();
bindingServiceProperties.setApplicationContext(context);
bf.registerSingleton("bindingServiceProperties", bindingServiceProperties);
BindingServiceProperties bsp = context.getBean(BindingServiceProperties.class);
bsp.setApplicationContext(context);
BinderProperties bp = new BinderProperties();
bsp.setBinders(Collections.singletonMap("testBinder", bp));
bp.getEnvironment().put("spring.rabbitmq.connection-timeout", 2345);
bp.getEnvironment().put("foo", Collections.singletonMap("bar", "hello"));
// using Spring Boot class to ensure that reliance on the same ObjectMapper configuration
ConfigurationPropertiesReportEndpoint endpoint = new ConfigurationPropertiesReportEndpoint();
endpoint.setApplicationContext(context);
ContextConfigurationProperties configurationProperties = endpoint.configurationProperties().getContexts().values().iterator().next();
Map<String, Object> properties = configurationProperties.getBeans().get("bindingServiceProperties").getProperties();
assertFalse(properties.containsKey("error"));
assertTrue(properties.containsKey("binders"));
Map<String, Object> testBinder = (Map<String, Object>) ((Map<String, Object>) properties.get("binders")).get("testBinder");
Map<String, Object> environment = (Map<String, Object>) testBinder.get("environment");
assertTrue(environment.get("spring.rabbitmq.connection-timeout") instanceof Integer);
assertTrue(environment.get("foo") instanceof Map);
}
use of org.springframework.context.support.StaticApplicationContext in project jetcache by alibaba.
the class DefaultSpringKeyConvertorTest method setup.
@BeforeEach
public void setup() {
context = new StaticApplicationContext();
beanFactory = context.getDefaultListableBeanFactory();
parser = new DefaultSpringKeyConvertorParser();
parser.setApplicationContext(context);
}
Aggregations