Search in sources :

Example 61 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.

the class AbstractMongoDbMessageStoreTests method testWithMessageHistory.

@Test
@MongoDbAvailable
public void testWithMessageHistory() throws Exception {
    cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageStore store = getMessageStore();
    Foo foo = new Foo();
    foo.setName("foo");
    Message<?> message = MessageBuilder.withPayload(foo).setHeader("foo", foo).setHeader("bar", new Bar("bar")).setHeader("baz", new Baz()).setHeader("abc", new Abc()).setHeader("xyz", new Xyz()).build();
    DirectChannel fooChannel = new DirectChannel();
    fooChannel.setBeanName("fooChannel");
    DirectChannel barChannel = new DirectChannel();
    barChannel.setBeanName("barChannel");
    message = MessageHistory.write(message, fooChannel);
    message = MessageHistory.write(message, barChannel);
    store.addMessage(message);
    message = store.getMessage(message.getHeaders().getId());
    assertNotNull(message);
    assertTrue(message.getHeaders().get("foo") instanceof Foo);
    assertTrue(message.getHeaders().get("bar") instanceof Bar);
    assertTrue(message.getHeaders().get("baz") instanceof Baz);
    assertTrue(message.getHeaders().get("abc") instanceof Abc);
    assertTrue(message.getHeaders().get("xyz") instanceof Xyz);
    MessageHistory messageHistory = MessageHistory.read(message);
    assertNotNull(messageHistory);
    assertEquals(2, messageHistory.size());
    Properties fooChannelHistory = messageHistory.get(0);
    assertEquals("fooChannel", fooChannelHistory.get("name"));
    assertEquals("channel", fooChannelHistory.get("type"));
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) MongoClient(com.mongodb.MongoClient) MessageHistory(org.springframework.integration.history.MessageHistory) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) DirectChannel(org.springframework.integration.channel.DirectChannel) Properties(java.util.Properties) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 62 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable 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 63 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable 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 64 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable 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)

Example 65 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.

the class MongoDbMetadataStoreTests method testConfigureFactorCustomCollection.

@MongoDbAvailable
@Test
public void testConfigureFactorCustomCollection() throws Exception {
    final String collectionName = "testMetadataStore";
    final MongoDbFactory mongoDbFactory = this.prepareMongoFactory(collectionName);
    store = new MongoDbMetadataStore(mongoDbFactory, collectionName);
    testBasics();
}
Also used : MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Aggregations

Test (org.junit.Test)70 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)70 MongoClient (com.mongodb.MongoClient)28 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)28 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)27 GenericMessage (org.springframework.messaging.support.GenericMessage)20 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)19 LiteralExpression (org.springframework.expression.common.LiteralExpression)17 AbstractBatchingMessageGroupStore (org.springframework.integration.store.AbstractBatchingMessageGroupStore)17 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)17 MessageStore (org.springframework.integration.store.MessageStore)14 BeanFactory (org.springframework.beans.factory.BeanFactory)13 MessageGroup (org.springframework.integration.store.MessageGroup)13 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)11 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 Expression (org.springframework.expression.Expression)8 Matchers.containsString (org.hamcrest.Matchers.containsString)7 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)6 MessageChannel (org.springframework.messaging.MessageChannel)6 PollableChannel (org.springframework.messaging.PollableChannel)6