Search in sources :

Example 46 with SimpleMongoDbFactory

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-integration by spring-projects.

the class MongoDbMessageStoreClaimCheckIntegrationTests method stringPayloadConfigurable.

@Test
@MongoDbAvailable
public void stringPayloadConfigurable() throws Exception {
    MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new MongoClient(), "test");
    ConfigurableMongoDbMessageStore messageStore = new ConfigurableMongoDbMessageStore(mongoDbFactory);
    GenericApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
    testApplicationContext.refresh();
    messageStore.setApplicationContext(testApplicationContext);
    messageStore.afterPropertiesSet();
    ClaimCheckInTransformer checkin = new ClaimCheckInTransformer(messageStore);
    ClaimCheckOutTransformer checkout = new ClaimCheckOutTransformer(messageStore);
    Message<?> originalMessage = MessageBuilder.withPayload("test1").build();
    Message<?> claimCheckMessage = checkin.transform(originalMessage);
    assertEquals(originalMessage.getHeaders().getId(), claimCheckMessage.getPayload());
    Message<?> checkedOutMessage = checkout.transform(claimCheckMessage);
    assertEquals(claimCheckMessage.getPayload(), checkedOutMessage.getHeaders().getId());
    assertEquals(originalMessage.getPayload(), checkedOutMessage.getPayload());
    assertEquals(originalMessage, checkedOutMessage);
}
Also used : MongoClient(com.mongodb.MongoClient) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) ClaimCheckInTransformer(org.springframework.integration.transformer.ClaimCheckInTransformer) ClaimCheckOutTransformer(org.springframework.integration.transformer.ClaimCheckOutTransformer) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 47 with SimpleMongoDbFactory

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-integration by spring-projects.

the class MongoDbAvailableTests method prepareMongoFactory.

protected MongoDbFactory prepareMongoFactory(String... additionalCollectionsToDrop) throws Exception {
    MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new MongoClient(), "test");
    cleanupCollections(mongoDbFactory, additionalCollectionsToDrop);
    return mongoDbFactory;
}
Also used : MongoClient(com.mongodb.MongoClient) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory)

Example 48 with SimpleMongoDbFactory

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project spring-integration by spring-projects.

the class AbstractMongoDbMessageStoreTests method testAddGetWithObjectDefaultConstructorPayload.

@Test
@MongoDbAvailable
public void testAddGetWithObjectDefaultConstructorPayload() throws Exception {
    cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageStore store = getMessageStore();
    Person p = new Person();
    p.setFname("John");
    p.setLname("Doe");
    Message<?> messageToStore = MessageBuilder.withPayload(p).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 49 with SimpleMongoDbFactory

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory 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 50 with SimpleMongoDbFactory

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory 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

SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)51 MongoClient (com.mongodb.MongoClient)38 Test (org.junit.Test)28 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)28 AbstractBatchingMessageGroupStore (org.springframework.integration.store.AbstractBatchingMessageGroupStore)16 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)16 GenericMessage (org.springframework.messaging.support.GenericMessage)14 MessageGroup (org.springframework.integration.store.MessageGroup)12 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)10 Bean (org.springframework.context.annotation.Bean)9 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)8 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)8 MessageStore (org.springframework.integration.store.MessageStore)8 MongoClientURI (com.mongodb.MongoClientURI)6 Net (de.flapdoodle.embed.mongo.config.Net)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)4 ClaimCheckInTransformer (org.springframework.integration.transformer.ClaimCheckInTransformer)4 ClaimCheckOutTransformer (org.springframework.integration.transformer.ClaimCheckOutTransformer)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3