Search in sources :

Example 6 with SimpleMongoDbFactory

use of org.springframework.data.mongodb.core.SimpleMongoDbFactory in project ocvn by devgateway.

the class MongoTemplateTestConfig method mongoTemplate.

@Bean(name = "mongoTemplate")
public MongoTemplate mongoTemplate(MongodProcess mongodProcess) throws Exception {
    Net net = mongodProcess.getConfig().net();
    properties.setHost(net.getServerAddress().getHostName());
    properties.setPort(net.getPort());
    properties.setDatabase(originalUri);
    properties.setUri(null);
    MongoTemplate template = new MongoTemplate(new SimpleMongoDbFactory(properties.createMongoClient(this.options, environment), properties.getDatabase()));
    ((MappingMongoConverter) template.getConverter()).setCustomConversions(customConversions);
    return template;
}
Also used : SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Net(de.flapdoodle.embed.mongo.config.Net) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Bean(org.springframework.context.annotation.Bean)

Example 7 with SimpleMongoDbFactory

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

the class AbstractMongoDbMessageGroupStoreTests method testNonExistingEmptyMessageGroup.

@Test
@MongoDbAvailable
public void testNonExistingEmptyMessageGroup() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store = getMessageGroupStore();
    store.addMessagesToGroup(1, new GenericMessage<Object>("foo"));
    MessageGroup messageGroup = store.getMessageGroup(1);
    assertNotNull(messageGroup);
    assertThat(messageGroup.getClass().getName(), containsString("PersistentMessageGroup"));
    assertEquals(1, messageGroup.size());
}
Also used : MongoClient(com.mongodb.MongoClient) 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) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 8 with SimpleMongoDbFactory

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

the class AbstractMongoDbMessageGroupStoreTests method testMessageGroupWithAddedMessageUUIDGroupIdAndUUIDHeader.

@Test
@MongoDbAvailable
public void testMessageGroupWithAddedMessageUUIDGroupIdAndUUIDHeader() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store = this.getMessageGroupStore();
    MessageStore messageStore = this.getMessageStore();
    Object id = UUID.randomUUID();
    MessageGroup messageGroup = store.getMessageGroup(id);
    UUID uuidA = UUID.randomUUID();
    Message<?> messageA = MessageBuilder.withPayload("A").setHeader("foo", uuidA).build();
    UUID uuidB = UUID.randomUUID();
    Message<?> messageB = MessageBuilder.withPayload("B").setHeader("foo", uuidB).build();
    store.addMessagesToGroup(id, messageA);
    messageGroup = store.addMessageToGroup(id, messageB);
    assertNotNull(messageGroup);
    assertEquals(2, messageGroup.size());
    Message<?> retrievedMessage = messageStore.getMessage(messageA.getHeaders().getId());
    assertNotNull(retrievedMessage);
    assertEquals(retrievedMessage.getHeaders().getId(), messageA.getHeaders().getId());
    // ensure that 'message_group' header that is only used internally is not propagated
    assertNull(retrievedMessage.getHeaders().get("message_group"));
    Object fooHeader = retrievedMessage.getHeaders().get("foo");
    assertTrue(fooHeader instanceof UUID);
    assertEquals(uuidA, fooHeader);
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) MongoClient(com.mongodb.MongoClient) 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 9 with SimpleMongoDbFactory

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

the class AbstractMongoDbMessageGroupStoreTests method testWithMessageHistory.

@Test
@MongoDbAvailable
public void testWithMessageHistory() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store = this.getMessageGroupStore();
    store.getMessageGroup(1);
    Message<?> message = new GenericMessage<String>("Hello");
    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.addMessagesToGroup(1, message);
    MessageGroup group = store.getMessageGroup(1);
    assertNotNull(group);
    Collection<Message<?>> messages = group.getMessages();
    assertTrue(!messages.isEmpty());
    message = messages.iterator().next();
    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 : MongoClient(com.mongodb.MongoClient) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHistory(org.springframework.integration.history.MessageHistory) AbstractBatchingMessageGroupStore(org.springframework.integration.store.AbstractBatchingMessageGroupStore) MessageGroupStore(org.springframework.integration.store.MessageGroupStore) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) DirectChannel(org.springframework.integration.channel.DirectChannel) MessageGroup(org.springframework.integration.store.MessageGroup) Properties(java.util.Properties) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 10 with SimpleMongoDbFactory

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

the class AbstractMongoDbMessageGroupStoreTests method testSameMessageMultipleGroupsPoll.

@Test
@MongoDbAvailable
public void testSameMessageMultipleGroupsPoll() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store = this.getMessageGroupStore();
    Message<?> messageA = new GenericMessage<String>("A");
    store.addMessagesToGroup(1, messageA);
    store.addMessagesToGroup(2, messageA);
    store.addMessagesToGroup(3, messageA);
    store.addMessagesToGroup(4, messageA);
    assertEquals(1, store.messageGroupSize(1));
    assertEquals(1, store.messageGroupSize(2));
    assertEquals(1, store.messageGroupSize(3));
    assertEquals(1, store.messageGroupSize(4));
    store.pollMessageFromGroup(3);
    assertEquals(1, store.messageGroupSize(1));
    assertEquals(1, store.messageGroupSize(2));
    assertEquals(0, store.messageGroupSize(3));
    assertEquals(1, store.messageGroupSize(4));
    store.pollMessageFromGroup(4);
    assertEquals(1, store.messageGroupSize(1));
    assertEquals(1, store.messageGroupSize(2));
    assertEquals(0, store.messageGroupSize(3));
    assertEquals(0, store.messageGroupSize(4));
    store.pollMessageFromGroup(2);
    assertEquals(1, store.messageGroupSize(1));
    assertEquals(0, store.messageGroupSize(2));
    assertEquals(0, store.messageGroupSize(3));
    assertEquals(0, store.messageGroupSize(4));
    store.pollMessageFromGroup(1);
    assertEquals(0, store.messageGroupSize(1));
    assertEquals(0, store.messageGroupSize(2));
    assertEquals(0, store.messageGroupSize(3));
    assertEquals(0, store.messageGroupSize(4));
}
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) 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