Search in sources :

Example 36 with MongoDbAvailable

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

the class AbstractMongoDbMessageStoreTests method testInt3076MessageAsPayload.

@Test
@MongoDbAvailable
public void testInt3076MessageAsPayload() throws Exception {
    MessageStore store = this.getMessageStore();
    Person p = new Person();
    p.setFname("John");
    p.setLname("Doe");
    Message<?> messageToStore = new GenericMessage<Message<?>>(MessageBuilder.withPayload(p).build());
    store.addMessage(messageToStore);
    Message<?> retrievedMessage = store.getMessage(messageToStore.getHeaders().getId());
    assertNotNull(retrievedMessage);
    assertTrue(retrievedMessage.getPayload() instanceof GenericMessage);
    assertEquals(messageToStore.getPayload(), retrievedMessage.getPayload());
    assertEquals(messageToStore.getHeaders(), retrievedMessage.getHeaders());
    assertEquals(((Message<?>) messageToStore.getPayload()).getPayload(), p);
    assertEquals(messageToStore, retrievedMessage);
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) GenericMessage(org.springframework.messaging.support.GenericMessage) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 37 with MongoDbAvailable

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

the class AbstractMongoDbMessageStoreTests method testInt3076AdviceMessage.

@Test
@MongoDbAvailable
public void testInt3076AdviceMessage() throws Exception {
    MessageStore store = this.getMessageStore();
    Person p = new Person();
    p.setFname("John");
    p.setLname("Doe");
    Message<Person> inputMessage = MessageBuilder.withPayload(p).build();
    Message<?> messageToStore = new AdviceMessage<String>("foo", inputMessage);
    store.addMessage(messageToStore);
    Message<?> retrievedMessage = store.getMessage(messageToStore.getHeaders().getId());
    assertNotNull(retrievedMessage);
    assertTrue(retrievedMessage instanceof AdviceMessage);
    assertEquals(messageToStore.getPayload(), retrievedMessage.getPayload());
    assertEquals(messageToStore.getHeaders(), retrievedMessage.getHeaders());
    assertEquals(inputMessage, ((AdviceMessage<?>) retrievedMessage).getInputMessage());
    assertEquals(messageToStore, retrievedMessage);
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) AdviceMessage(org.springframework.integration.message.AdviceMessage) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 38 with MongoDbAvailable

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

the class MongoDbMetadataStoreTests method testConfigureFactory.

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

Example 39 with MongoDbAvailable

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

the class AbstractMongoDbMessageGroupStoreTests method testRemoveMessageGroup.

@Test
@MongoDbAvailable
public void testRemoveMessageGroup() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store = this.getMessageGroupStore();
    MessageStore messageStore = this.getMessageStore();
    MessageGroup messageGroup = store.getMessageGroup(1);
    Message<?> message = new GenericMessage<String>("Hello");
    UUID id = message.getHeaders().getId();
    messageGroup = store.addMessageToGroup(1, message);
    assertNotNull(messageGroup);
    assertEquals(1, messageGroup.size());
    message = messageStore.getMessage(id);
    assertNotNull(message);
    store.removeMessageGroup(1);
    MessageGroup messageGroupA = store.getMessageGroup(1);
    assertEquals(0, messageGroupA.size());
    assertFalse(messageGroupA.equals(messageGroup));
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) MongoClient(com.mongodb.MongoClient) GenericMessage(org.springframework.messaging.support.GenericMessage) AbstractBatchingMessageGroupStore(org.springframework.integration.store.AbstractBatchingMessageGroupStore) MessageGroupStore(org.springframework.integration.store.MessageGroupStore) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) MessageGroup(org.springframework.integration.store.MessageGroup) UUID(java.util.UUID) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 40 with MongoDbAvailable

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

the class AbstractMongoDbMessageGroupStoreTests method testMessageGroupIterator.

@Test
@MongoDbAvailable
public void testMessageGroupIterator() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store1 = this.getMessageGroupStore();
    MessageGroupStore store2 = this.getMessageGroupStore();
    Message<?> message = new GenericMessage<String>("1");
    store2.addMessagesToGroup("1", message);
    store1.addMessagesToGroup("2", new GenericMessage<String>("2"));
    store2.addMessagesToGroup("3", new GenericMessage<String>("3"));
    MessageGroupStore store3 = this.getMessageGroupStore();
    Iterator<MessageGroup> iterator = store3.iterator();
    assertNotNull(iterator);
    int counter = 0;
    while (iterator.hasNext()) {
        iterator.next();
        counter++;
    }
    assertEquals(3, counter);
    store2.removeMessagesFromGroup("1", message);
    iterator = store3.iterator();
    counter = 0;
    while (iterator.hasNext()) {
        iterator.next();
        counter++;
    }
    assertEquals(2, counter);
}
Also used : MongoClient(com.mongodb.MongoClient) GenericMessage(org.springframework.messaging.support.GenericMessage) AbstractBatchingMessageGroupStore(org.springframework.integration.store.AbstractBatchingMessageGroupStore) MessageGroupStore(org.springframework.integration.store.MessageGroupStore) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) MessageGroup(org.springframework.integration.store.MessageGroup) Matchers.containsString(org.hamcrest.Matchers.containsString) 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