Search in sources :

Example 36 with GenericXmlApplicationContext

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

the class MessageIdGenerationTests method testCustomIdGenerationWithParentChildIndependentCreation.

@Test
public void testCustomIdGenerationWithParentChildIndependentCreation() throws Exception {
    ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context-withGenerator.xml", this.getClass());
    GenericXmlApplicationContext child = new GenericXmlApplicationContext();
    child.load("classpath:/org/springframework/integration/core/MessageIdGenerationTests-context.xml");
    child.setParent(parent);
    child.refresh();
    IdGenerator idGenerator = child.getBean("idGenerator", IdGenerator.class);
    MessageChannel inputChannel = child.getBean("input", MessageChannel.class);
    inputChannel.send(new GenericMessage<Integer>(0));
    verify(idGenerator, atLeastOnce()).generateId();
    child.close();
    parent.close();
    this.assertDestroy();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) IdGenerator(org.springframework.util.IdGenerator) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) Test(org.junit.Test)

Example 37 with GenericXmlApplicationContext

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

the class InnerPollerParserTests method testRefExtraAttributeAndDefaultFalse.

@Test
public void testRefExtraAttributeAndDefaultFalse() {
    try {
        // Load context from a String to avoid IDEs reporting the invalid configuration
        String badContext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<beans xmlns=\"http://www.springframework.org/schema/beans\"" + "		xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + "		xmlns:int=\"http://www.springframework.org/schema/integration\"" + "		xmlns:int-jdbc=\"http://www.springframework.org/schema/integration/jdbc\"" + "		xsi:schemaLocation=\"http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd" + "			http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd" + "			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd\">" + "" + "	<int:poller id=\"outer\" fixed-rate=\"5000\"/>" + "" + "	<int:channel id=\"someChannel\"/>" + "" + "	<int-jdbc:inbound-channel-adapter channel=\"someChannel\" jdbc-operations=\"ops\"" + "			query=\"select 1\">" + // <<<<< fixed-rate not allowed here
        "		<int:poller ref=\"outer\" default=\"false\" fixed-rate=\"1000\"/>" + "	</int-jdbc:inbound-channel-adapter>" + "" + "	<bean id=\"ops\" class=\"org.mockito.Mockito\" factory-method=\"mock\">" + "		<constructor-arg value=\"org.springframework.jdbc.core.JdbcOperations\"/>" + "	</bean>" + "</beans>";
        Resource resource = new ByteArrayResource(badContext.getBytes());
        new GenericXmlApplicationContext(resource).close();
        fail("Expected Failure to load ApplicationContext");
    } catch (BeanDefinitionParsingException bdpe) {
        assertTrue(bdpe.getMessage().startsWith("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes."));
    }
}
Also used : BeanDefinitionParsingException(org.springframework.beans.factory.parsing.BeanDefinitionParsingException) ByteArrayResource(org.springframework.core.io.ByteArrayResource) Resource(org.springframework.core.io.Resource) ByteArrayResource(org.springframework.core.io.ByteArrayResource) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) Test(org.junit.Test)

Example 38 with GenericXmlApplicationContext

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

the class MBeanExporterIntegrationTests method testCircularReferenceWithChannelInFactoryBean.

@Test
public void testCircularReferenceWithChannelInFactoryBean() throws Exception {
    context = new GenericXmlApplicationContext(getClass(), "oref-factory-channel.xml");
    messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
    assertNotNull(messageChannelsMonitor);
    assertTrue(Arrays.asList(messageChannelsMonitor.getChannelNames()).contains("anonymous"));
    MBeanServer server = context.getBean(MBeanServer.class);
    assertEquals(1, server.queryNames(ObjectName.getInstance("com.foo:*"), null).size());
    assertEquals(1, server.queryNames(ObjectName.getInstance("org.springframework.integration:name=anonymous,*"), null).size());
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 39 with GenericXmlApplicationContext

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

the class MBeanExporterIntegrationTests method testComponentNames.

@Test
public void testComponentNames() throws Exception {
    context = new GenericXmlApplicationContext(getClass(), "excluded-components.xml");
    messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
    assertNotNull(messageChannelsMonitor);
    MBeanServer server = context.getBean(MBeanServer.class);
    Set<ObjectName> names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=MessageChannel,*"), null);
    // Only one registered (out of >2 available)
    assertEquals(1, names.size());
    names = server.queryNames(ObjectName.getInstance("org.springframework.integration:type=MessageHandler,*"), null);
    assertEquals(0, names.size());
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 40 with GenericXmlApplicationContext

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

the class MBeanExporterIntegrationTests method testCircularReferenceNoChannelInFactoryBean.

@Test
public void testCircularReferenceNoChannelInFactoryBean() throws Exception {
    context = new GenericXmlApplicationContext(getClass(), "oref-factory-nonchannel.xml");
    messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
    assertNotNull(messageChannelsMonitor);
}
Also used : GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) Test(org.junit.Test)

Aggregations

GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)61 Test (org.junit.Test)21 Test (org.junit.jupiter.api.Test)13 MBeanServer (javax.management.MBeanServer)5 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)5 Scanner (java.util.Scanner)4 ObjectName (javax.management.ObjectName)4 Resource (org.springframework.core.io.Resource)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4 MessageChannel (org.springframework.messaging.MessageChannel)4 ApplicationContext (org.springframework.context.ApplicationContext)3 ByteArrayResource (org.springframework.core.io.ByteArrayResource)3 Message (org.springframework.messaging.Message)3 MBeanOperationInfo (javax.management.MBeanOperationInfo)2 Server (org.eclipse.jetty.server.Server)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)2 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)2 BatchStatus (org.springframework.batch.core.BatchStatus)2 BeanDefinitionParsingException (org.springframework.beans.factory.parsing.BeanDefinitionParsingException)2 CacheInterceptor (org.springframework.cache.interceptor.CacheInterceptor)2