Search in sources :

Example 41 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-integration by spring-projects.

the class ExpressionUtilsTests method testEvaluationContext.

@Test
public void testEvaluationContext() {
    GenericApplicationContext context = new GenericApplicationContext();
    context.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME, new RootBeanDefinition(IntegrationEvaluationContextFactoryBean.class));
    context.registerBeanDefinition(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, new RootBeanDefinition(ConversionServiceFactoryBean.class));
    context.refresh();
    StandardEvaluationContext evalContext = ExpressionUtils.createStandardEvaluationContext(context);
    assertNotNull(evalContext.getBeanResolver());
    assertNotNull(evalContext.getTypeConverter());
    IntegrationEvaluationContextFactoryBean factory = context.getBean("&" + IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME, IntegrationEvaluationContextFactoryBean.class);
    assertSame(evalContext.getTypeConverter(), TestUtils.getPropertyValue(factory, "typeConverter"));
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ConversionServiceFactoryBean(org.springframework.context.support.ConversionServiceFactoryBean) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) IntegrationEvaluationContextFactoryBean(org.springframework.integration.config.IntegrationEvaluationContextFactoryBean) Test(org.junit.Test)

Example 42 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-integration by spring-projects.

the class ExpressionUtilsTests method testEvaluationContextDefaultTypeConverter.

@Test
public void testEvaluationContextDefaultTypeConverter() {
    GenericApplicationContext context = new GenericApplicationContext();
    context.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME, new RootBeanDefinition(IntegrationEvaluationContextFactoryBean.class));
    context.refresh();
    StandardEvaluationContext evalContext = ExpressionUtils.createStandardEvaluationContext(context);
    assertNotNull(evalContext.getBeanResolver());
    TypeConverter typeConverter = evalContext.getTypeConverter();
    assertNotNull(typeConverter);
    assertSame(DefaultConversionService.getSharedInstance(), TestUtils.getPropertyValue(typeConverter, "conversionService"));
}
Also used : TypeConverter(org.springframework.expression.TypeConverter) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) IntegrationEvaluationContextFactoryBean(org.springframework.integration.config.IntegrationEvaluationContextFactoryBean) Test(org.junit.Test)

Example 43 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-integration by spring-projects.

the class GatewayParserTests method testFactoryBeanObjectTypeWithNoServiceInterface.

@Test
public void testFactoryBeanObjectTypeWithNoServiceInterface() throws Exception {
    ConfigurableListableBeanFactory beanFactory = ((GenericApplicationContext) context).getBeanFactory();
    Object attribute = beanFactory.getMergedBeanDefinition("&defaultConfig").getAttribute(IntegrationConfigUtils.FACTORY_BEAN_OBJECT_TYPE);
    assertEquals(RequestReplyExchanger.class.getName(), attribute);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) RequestReplyExchanger(org.springframework.integration.gateway.RequestReplyExchanger) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.Test)

Example 44 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-integration by spring-projects.

the class IdempotentReceiverParserTests method bootStrap.

private ApplicationContext bootStrap(String configProperty) throws Exception {
    PropertiesFactoryBean pfb = new PropertiesFactoryBean();
    pfb.setLocation(new ClassPathResource("org/springframework/integration/config/xml/idempotent-receiver-configs.properties"));
    pfb.afterPropertiesSet();
    Properties prop = pfb.getObject();
    ByteArrayInputStream stream = new ByteArrayInputStream((prop.getProperty("xmlheaders") + prop.getProperty(configProperty) + prop.getProperty("xmlfooter")).getBytes());
    GenericApplicationContext ac = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);
    reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
    reader.loadBeanDefinitions(new InputStreamResource(stream));
    ac.refresh();
    return ac;
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) Properties(java.util.Properties) ClassPathResource(org.springframework.core.io.ClassPathResource) InputStreamResource(org.springframework.core.io.InputStreamResource)

Example 45 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-integration by spring-projects.

the class SubscriberOrderTests method directChannelAndFailoverDispatcherWithSingleCallPerMethod.

@Test
public void directChannelAndFailoverDispatcherWithSingleCallPerMethod() {
    GenericApplicationContext context = TestUtils.createTestApplicationContext();
    context.registerBeanDefinition("postProcessor", new RootBeanDefinition(MessagingAnnotationPostProcessor.class));
    RootBeanDefinition channelDefinition = new RootBeanDefinition(DirectChannel.class);
    context.registerBeanDefinition("input", channelDefinition);
    RootBeanDefinition testBeanDefinition = new RootBeanDefinition(TestBean.class);
    testBeanDefinition.getConstructorArgumentValues().addGenericArgumentValue(1);
    context.registerBeanDefinition("testBean", testBeanDefinition);
    context.refresh();
    TestBean testBean = (TestBean) context.getBean("testBean");
    MessageChannel channel = (MessageChannel) context.getBean("input");
    channel.send(new GenericMessage<String>("test-1"));
    channel.send(new GenericMessage<String>("test-2"));
    channel.send(new GenericMessage<String>("test-3"));
    channel.send(new GenericMessage<String>("test-4"));
    channel.send(new GenericMessage<String>("test-5"));
    List<Integer> calls = testBean.calls;
    assertEquals(5, calls.size());
    assertEquals(1, calls.get(0).intValue());
    assertEquals(2, calls.get(1).intValue());
    assertEquals(3, calls.get(2).intValue());
    assertEquals(4, calls.get(3).intValue());
    assertEquals(5, calls.get(4).intValue());
    context.close();
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) MessageChannel(org.springframework.messaging.MessageChannel) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Aggregations

GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)378 Test (org.junit.jupiter.api.Test)193 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)106 Test (org.junit.Test)74 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)72 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)50 ClassPathResource (org.springframework.core.io.ClassPathResource)36 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)16 QueueChannel (org.springframework.integration.channel.QueueChannel)16 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)15 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)15 GenericMessage (org.springframework.messaging.support.GenericMessage)14 Properties (java.util.Properties)13 DefaultAdvisorAutoProxyCreator (org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)13 File (java.io.File)12 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)12 Message (org.springframework.messaging.Message)12 InputStreamResource (org.springframework.core.io.InputStreamResource)11 MBeanExporter (org.springframework.jmx.export.MBeanExporter)11 BeforeEach (org.junit.jupiter.api.BeforeEach)10