Search in sources :

Example 86 with PollableChannel

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

the class UnmarshallingTransformerParserTests method testUnmarshallString.

@Test
public void testUnmarshallString() throws Exception {
    MessageChannel input = (MessageChannel) appContext.getBean("input");
    PollableChannel output = (PollableChannel) appContext.getBean("output");
    GenericMessage<Object> message = new GenericMessage<Object>("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><order><orderItem>test</orderItem></order>");
    input.send(message);
    Message<?> result = output.receive(0);
    assertEquals("Wrong payload after unmarshalling", "unmarshalled", result.getPayload());
    assertTrue("Wrong source passed to unmarshaller", unmarshaller.sourcesPassed.poll() instanceof StringSource);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel) StringSource(org.springframework.xml.transform.StringSource) Test(org.junit.Test)

Example 87 with PollableChannel

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

the class UnmarshallingTransformerParserTests method testDefaultUnmarshall.

@Test
public void testDefaultUnmarshall() throws Exception {
    MessageChannel input = (MessageChannel) appContext.getBean("input");
    PollableChannel output = (PollableChannel) appContext.getBean("output");
    GenericMessage<Object> message = new GenericMessage<Object>(new StringSource("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><order><orderItem>test</orderItem></order>"));
    input.send(message);
    Message<?> result = output.receive(0);
    assertEquals("Wrong payload after unmarshalling", "unmarshalled", result.getPayload());
    assertTrue("Wrong source passed to unmarshaller", unmarshaller.sourcesPassed.poll() instanceof StringSource);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel) StringSource(org.springframework.xml.transform.StringSource) Test(org.junit.Test)

Example 88 with PollableChannel

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

the class UnmarshallingTransformerParserTests method testUnmarshallDocument.

@Test
public void testUnmarshallDocument() throws Exception {
    MessageChannel input = (MessageChannel) appContext.getBean("input");
    PollableChannel output = (PollableChannel) appContext.getBean("output");
    GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDocumentForString("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><order><orderItem>test</orderItem></order>"));
    input.send(message);
    Message<?> result = output.receive(0);
    assertEquals("Wrong payload after unmarshalling", "unmarshalled", result.getPayload());
    assertTrue("Wrong source passed to unmarshaller", unmarshaller.sourcesPassed.poll() instanceof DOMSource);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) DOMSource(javax.xml.transform.dom.DOMSource) MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 89 with PollableChannel

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

the class XPathFilterParserTests method stringExpressionWithNamespaceString.

@Test
public void stringExpressionWithNamespaceString() throws Exception {
    MessageChannel inputChannel = context.getBean("stringFilterWithNamespaceInput", MessageChannel.class);
    QueueChannel replyChannel = new QueueChannel();
    PollableChannel discardChannel = context.getBean("stringFilterWithNamespaceRejections", PollableChannel.class);
    Document docToAccept = XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>");
    Document docToReject = XmlTestUtil.getDocumentForString("<name>outputOne</name>");
    Message<?> shouldBeAccepted = MessageBuilder.withPayload(docToAccept).setReplyChannel(replyChannel).build();
    Message<?> shouldBeRejected = MessageBuilder.withPayload(docToReject).setReplyChannel(replyChannel).build();
    inputChannel.send(shouldBeAccepted);
    inputChannel.send(shouldBeRejected);
    assertEquals(shouldBeAccepted, replyChannel.receive(0));
    assertEquals(shouldBeRejected, discardChannel.receive(0));
    assertNull(replyChannel.receive(0));
    assertNull(discardChannel.receive(0));
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) PollableChannel(org.springframework.messaging.PollableChannel) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 90 with PollableChannel

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

the class XPathFilterParserTests method simpleStringExpressionBoolean.

@Test
public void simpleStringExpressionBoolean() throws Exception {
    MessageChannel inputChannel = context.getBean("booleanFilterInput", MessageChannel.class);
    QueueChannel replyChannel = new QueueChannel();
    PollableChannel discardChannel = context.getBean("booleanFilterRejections", PollableChannel.class);
    Message<?> shouldBeAccepted = MessageBuilder.withPayload("<name>outputOne</name>").setReplyChannel(replyChannel).build();
    Message<?> shouldBeRejected = MessageBuilder.withPayload("<other>outputOne</other>").setReplyChannel(replyChannel).build();
    inputChannel.send(shouldBeAccepted);
    inputChannel.send(shouldBeRejected);
    assertEquals(shouldBeAccepted, replyChannel.receive(0));
    assertEquals(shouldBeRejected, discardChannel.receive(0));
    assertNull(replyChannel.receive(0));
    assertNull(discardChannel.receive(0));
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) 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