Search in sources :

Example 26 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class PollingTransactionTests method propagationMandatory.

@Test
public void propagationMandatory() throws Throwable {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("propagationMandatoryTests.xml", this.getClass());
    TestTransactionManager txManager = (TestTransactionManager) context.getBean("txManager");
    PollableChannel input = (PollableChannel) context.getBean("input");
    PollableChannel output = (PollableChannel) context.getBean("output");
    PollableChannel errorChannel = (PollableChannel) context.getBean("errorChannel");
    assertEquals(0, txManager.getCommitCount());
    input.send(new GenericMessage<String>("test"));
    Message<?> errorMessage = errorChannel.receive(3000);
    assertNotNull(errorMessage);
    Object payload = errorMessage.getPayload();
    assertEquals(MessagingException.class, payload.getClass());
    MessagingException messagingException = (MessagingException) payload;
    assertEquals(IllegalTransactionStateException.class, messagingException.getCause().getClass());
    assertNull(output.receive(0));
    assertEquals(0, txManager.getCommitCount());
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MessagingException(org.springframework.messaging.MessagingException) PollableChannel(org.springframework.messaging.PollableChannel) TestTransactionManager(org.springframework.integration.util.TestTransactionManager) Test(org.junit.Test)

Example 27 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class ReturnAddressTests method outputChannelTakesPrecedence.

@Test
public void outputChannelTakesPrecedence() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("returnAddressTests.xml", this.getClass());
    MessageChannel channel4 = (MessageChannel) context.getBean("channel4");
    PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
    context.start();
    Message<String> message = MessageBuilder.withPayload("*").setReplyChannelName("channel5").build();
    channel4.send(message);
    Message<?> response = replyChannel.receive(3000);
    assertNotNull(response);
    assertEquals("**", response.getPayload());
    PollableChannel channel5 = (PollableChannel) context.getBean("channel5");
    assertNull(channel5.receive(0));
    context.close();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 28 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class ReturnAddressTests method outputChannelWithNoReturnAddress.

@Test
public void outputChannelWithNoReturnAddress() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("returnAddressTests.xml", this.getClass());
    MessageChannel channel4 = (MessageChannel) context.getBean("channel4");
    PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
    context.start();
    GenericMessage<String> message = new GenericMessage<String>("*");
    channel4.send(message);
    Message<?> response = replyChannel.receive(3000);
    assertNotNull(response);
    assertEquals("**", response.getPayload());
    context.close();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 29 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class ReturnAddressTests method returnAddressWithChannelReferenceAfterMultipleEndpoints.

@Test
public void returnAddressWithChannelReferenceAfterMultipleEndpoints() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("returnAddressTests.xml", this.getClass());
    MessageChannel channel1 = (MessageChannel) context.getBean("channel1");
    PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
    context.start();
    Message<String> message = MessageBuilder.withPayload("*").setReplyChannel(replyChannel).build();
    channel1.send(message);
    Message<?> response = replyChannel.receive(3000);
    assertNotNull(response);
    assertEquals("********", response.getPayload());
    PollableChannel channel2 = (PollableChannel) context.getBean("channel2");
    assertNull(channel2.receive(0));
    context.close();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 30 with PollableChannel

use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.

the class ReturnAddressTests method returnAddressFallbackWithChannelName.

@Test
public void returnAddressFallbackWithChannelName() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("returnAddressTests.xml", this.getClass());
    MessageChannel channel3 = (MessageChannel) context.getBean("channel3");
    PollableChannel channel5 = (PollableChannel) context.getBean("channel5");
    context.start();
    Message<String> message = MessageBuilder.withPayload("*").setReplyChannelName("channel5").build();
    channel3.send(message);
    Message<?> response = channel5.receive(3000);
    assertNotNull(response);
    assertEquals("**", response.getPayload());
    context.close();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Aggregations

PollableChannel (org.springframework.messaging.PollableChannel)210 Test (org.junit.Test)190 MessageChannel (org.springframework.messaging.MessageChannel)89 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)82 QueueChannel (org.springframework.integration.channel.QueueChannel)52 GenericMessage (org.springframework.messaging.support.GenericMessage)52 Message (org.springframework.messaging.Message)40 BeanFactory (org.springframework.beans.factory.BeanFactory)25 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)20 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)19 MessagingException (org.springframework.messaging.MessagingException)16 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)13 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)12 ErrorMessage (org.springframework.messaging.support.ErrorMessage)12 Document (org.w3c.dom.Document)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 Matchers.containsString (org.hamcrest.Matchers.containsString)11 Date (java.util.Date)10 ArrayList (java.util.ArrayList)9 MessageHistory (org.springframework.integration.history.MessageHistory)9