Example usage for org.springframework.integration.support MessageBuilder withPayload

List of usage examples for org.springframework.integration.support MessageBuilder withPayload

Introduction

In this page you can find the example usage for org.springframework.integration.support MessageBuilder withPayload.

Prototype

public static <T> MessageBuilder<T> withPayload(T payload) 

Source Link

Document

Create a builder for a new Message instance with the provided payload.

Usage

From source file:siia.channels.ChannelsPriorityTest.java

@Test
public void testChannels() throws Exception {

    Booking booking = new Booking();
    booking.setCustomerEmail("user@example.com");
    booking.setFlightId("AC100");
    Message<Booking> bookingMessage = MessageBuilder.withPayload(booking).build();
    bookingsChannel.send(bookingMessage);

    Assert.assertEquals(1, emailConfirmationService.getEmails().size());
    Assert.assertEquals("user@example.com", emailConfirmationService.getEmails().get(0).getRecipient());
}

From source file:siia.business.EmailHeaderEnricherTests.java

@Test
public void verifyTransformation() {
    Passenger payload = new Passenger();
    Profile profile = new Profile();
    profile.setEmailAddress(EMAIL_ADDRESS);
    payload.addProfile(profile);//from  ww  w  .  j  av a2 s  . c om
    Message<Passenger> passengerToTransform = MessageBuilder.withPayload(payload).build();
    input.send(passengerToTransform);
    Message<Passenger> transformedPassenger = (Message<Passenger>) output.receive(0);
    assertEquals(transformedPassenger.getHeaders().get(MailHeaders.TO), EMAIL_ADDRESS);
}

From source file:org.grails.plugin.platform.events.publisher.SpringIntegrationRepliesAggregator.java

@Aggregator
public Message<?> createSingleMessageFromGroup(List<Message<?>> messages) {
    if (messages.size() == 1
            && !messages.get(0).getPayload().getClass().isAssignableFrom(TrackableNullResult.class))
        return messages.get(0);

    List<Object> payload = new ArrayList<Object>();

    for (Message<?> message : messages) {
        if (!message.getPayload().getClass().isAssignableFrom(TrackableNullResult.class))
            payload.add(message.getPayload());
    }// w w w  .  j  a va2  s  .  c  o  m

    return MessageBuilder.withPayload(payload.size() == 1 ? payload.get(0) : payload)
            .setSequenceSize(payload.size()).build();
}

From source file:biz.c24.io.spring.integration.transformer.IoUnmarshallingTransformerIUTests.java

@Test
public void canUnmarshalTextFromBytearray() throws Exception {

    byte[] valid1 = loadCsvBytes();
    C24UnmarshallingTransformer transformer = new C24UnmarshallingTransformer(model);
    transformer.setSourceFactory(new TextualSourceFactory());

    Message message = MessageBuilder.withPayload(valid1).build();

    Message<?> outputMessage = transformer.transform(message);

    assertThat(outputMessage.getPayload(), notNullValue());
    assertThat(outputMessage.getPayload(), is(Employees.class));

    Employees employees = (Employees) outputMessage.getPayload();

}

From source file:siia.channels.ChannelSelectorTest.java

@Test
public void testSelectorPassing() throws Exception {
    Booking booking = new Booking();
    booking.setCustomerEmail("user@example.com");
    booking.setFlightId("AC100");
    ChargedBooking chargedBooking = new ChargedBooking(booking, 1l);
    Message<ChargedBooking> bookingMessage = MessageBuilder.withPayload(chargedBooking).build();
    chargedBookingsChannel.send(bookingMessage);

    Assert.assertEquals(1, emailConfirmationService.getEmails().size());
    Assert.assertEquals("user@example.com", emailConfirmationService.getEmails().get(0).getRecipient());
}

From source file:biz.c24.io.spring.integration.transformer.IoMarshallingTransformerIUTests.java

@Test
public void canMarshalXmlToBytearray() throws Exception {

    C24MarshallingTransformer ioMarshallingTransformer = new C24MarshallingTransformer();
    ioMarshallingTransformer.setOutputType(OutputType.BYTE_ARRAY);
    XmlSinkFactory xmlSinkFactory = new XmlSinkFactory();
    ioMarshallingTransformer.setSinkFactory(xmlSinkFactory);

    Message<?> message = MessageBuilder.withPayload(loadObject()).build();

    Message<?> outputMessage = ioMarshallingTransformer.transform(message);

    assertThat(outputMessage.getPayload(), notNullValue());
    assertThat(outputMessage.getPayload(), is(byte[].class));

    String xml = new String((byte[]) outputMessage.getPayload(), "UTF-8");

    // TODO: XML equivalence match

}

From source file:com.manning.siia.kitchen.KitchenTest.java

@Test
public void shouldPrepareMealFromRecipe() {
    final TimedPollableChannel timed = new TimedPollableChannel(meals);
    Recipe r = RecipeObjectMother.steak();
    recipes.send(MessageBuilder.withPayload(r).build());

    final Message<Meal> message = timed.receive(2500);
    assertThat("Message was null", message, Matchers.is(notNullValue()));
    final Meal meal = message.getPayload();
    assertThat(meal.getRecipe(), is(r));
    assertThat(meal.isDone(), is(true));
}

From source file:com.consol.citrus.samples.greeting.AbstractMarshallingMessageService.java

/**
 * Unmarshal message payload.//from w  w w.  ja  va  2s.  c om
 * 
 * @param message
 * @return
 */
@SuppressWarnings("unchecked")
private Message<T> unmarshalMessage(Message<?> message) {
    T payload = (T) unmarshallingTransformer.transformPayload(message.getPayload());
    MessageBuilder<T> builder = MessageBuilder.withPayload(payload).copyHeaders(message.getHeaders());

    return builder.build();
}

From source file:com.manning.siia.kitchen.ShoppingTest.java

@Test
public void shouldConvertRecipeIntoIngredients() {
    Recipe recipe = RecipeObjectMother.steak();
    List<Ingredient> needed = RecipeObjectMother.steak().getIngredients();
    recipes.send(MessageBuilder.withPayload(recipe).build());
    receiveAndCheckProductMessage(needed);
    receiveAndCheckProductMessage(needed);
    receiveAndCheckProductMessage(needed);
}

From source file:org.opencredo.couchdb.outbound.CouchDbOutboundChannelAdapterPollerTest.java

@Test
@Repeat(10)//from   www.  j a  v a2 s  .  co m
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public void sendMessage() throws Exception {
    DummyDocument document = new DummyDocument("polling test - " + UUID.randomUUID());
    Message<DummyDocument> message = MessageBuilder.withPayload(document).build();
    messagingTemplate.send(message);

    DummyDocument response = (DummyDocument) messagingTemplate.convertSendAndReceive("testRequestChannel",
            message.getHeaders().getId(), DummyDocument.class);
    assertThat(document.getMessage(), equalTo(response.getMessage()));
}