Search in sources :

Example 21 with MessageStore

use of org.springframework.integration.store.MessageStore in project spring-integration by spring-projects.

the class AbstractMongoDbMessageStoreTests method testInt3076ErrorMessage.

@Test
@MongoDbAvailable
public void testInt3076ErrorMessage() throws Exception {
    MessageStore store = this.getMessageStore();
    Person p = new Person();
    p.setFname("John");
    p.setLname("Doe");
    Message<Person> failedMessage = MessageBuilder.withPayload(p).build();
    MessagingException messagingException;
    try {
        throw new RuntimeException("intentional");
    } catch (Exception e) {
        messagingException = new MessagingException(failedMessage, "intentional MessagingException", e);
    }
    Message<?> messageToStore = new ErrorMessage(messagingException);
    store.addMessage(messageToStore);
    Message<?> retrievedMessage = store.getMessage(messageToStore.getHeaders().getId());
    assertNotNull(retrievedMessage);
    assertTrue(retrievedMessage instanceof ErrorMessage);
    assertThat(retrievedMessage.getPayload(), Matchers.instanceOf(MessagingException.class));
    assertThat(((MessagingException) retrievedMessage.getPayload()).getMessage(), containsString("intentional MessagingException"));
    assertEquals(failedMessage, ((MessagingException) retrievedMessage.getPayload()).getFailedMessage());
    assertEquals(messageToStore.getHeaders(), retrievedMessage.getHeaders());
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) MessagingException(org.springframework.messaging.MessagingException) ErrorMessage(org.springframework.messaging.support.ErrorMessage) MessagingException(org.springframework.messaging.MessagingException) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 22 with MessageStore

use of org.springframework.integration.store.MessageStore in project spring-integration by spring-projects.

the class AbstractMongoDbMessageStoreTests method testAddAndUpdateAlreadySaved.

@Test
@MongoDbAvailable
public void testAddAndUpdateAlreadySaved() throws Exception {
    MessageStore messageStore = getMessageStore();
    Message<String> message = MessageBuilder.withPayload("foo").build();
    message = messageStore.addMessage(message);
    Message<String> result = messageStore.addMessage(message);
    assertEquals(message, result);
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 23 with MessageStore

use of org.springframework.integration.store.MessageStore in project spring-integration by spring-projects.

the class AbstractMongoDbMessageStoreTests method testAddGetWithStringPayload.

@Test
@MongoDbAvailable
public void testAddGetWithStringPayload() throws Exception {
    cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageStore store = getMessageStore();
    Message<?> messageToStore = MessageBuilder.withPayload("Hello").build();
    store.addMessage(messageToStore);
    Message<?> retrievedMessage = store.getMessage(messageToStore.getHeaders().getId());
    assertNotNull(retrievedMessage);
    assertEquals(messageToStore.getPayload(), retrievedMessage.getPayload());
    assertEquals(messageToStore.getHeaders(), retrievedMessage.getHeaders());
    assertEquals(messageToStore, retrievedMessage);
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) MongoClient(com.mongodb.MongoClient) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Aggregations

Test (org.junit.Test)23 MessageStore (org.springframework.integration.store.MessageStore)23 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)14 MongoClient (com.mongodb.MongoClient)8 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)8 GenericMessage (org.springframework.messaging.support.GenericMessage)5 JdbcMessageStore (org.springframework.integration.jdbc.store.JdbcMessageStore)4 UUID (java.util.UUID)3 AbstractBatchingMessageGroupStore (org.springframework.integration.store.AbstractBatchingMessageGroupStore)3 MessageGroup (org.springframework.integration.store.MessageGroup)3 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)3 SimpleMessageStore (org.springframework.integration.store.SimpleMessageStore)3 Matchers.containsString (org.hamcrest.Matchers.containsString)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 AdviceMessage (org.springframework.integration.message.AdviceMessage)2 Properties (java.util.Properties)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 MessageHistory (org.springframework.integration.history.MessageHistory)1 MutableMessage (org.springframework.integration.support.MutableMessage)1 ClaimCheckInTransformer (org.springframework.integration.transformer.ClaimCheckInTransformer)1