Search in sources :

Example 46 with MongoDbAvailable

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

the class ConfigurableMongoDbMessageGroupStoreTests method testPriorityChannel.

@Test
@MongoDbAvailable
public void testPriorityChannel() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ConfigurableMongoDbMessageStore-CustomConverter.xml", this.getClass());
    context.refresh();
    Object priorityChannel = context.getBean("priorityChannel");
    assertThat(priorityChannel, Matchers.instanceOf(PriorityChannel.class));
    QueueChannel channel = (QueueChannel) priorityChannel;
    Message<String> message = MessageBuilder.withPayload("1").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 1).build();
    channel.send(message);
    message = MessageBuilder.withPayload("-1").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, -1).build();
    channel.send(message);
    message = MessageBuilder.withPayload("3").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 3).build();
    channel.send(message);
    message = MessageBuilder.withPayload("0").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 0).build();
    channel.send(message);
    message = MessageBuilder.withPayload("2").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 2).build();
    channel.send(message);
    message = MessageBuilder.withPayload("none").build();
    channel.send(message);
    message = MessageBuilder.withPayload("31").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 3).build();
    channel.send(message);
    Message<?> receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("3", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("31", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("2", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("1", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("0", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("-1", receive.getPayload());
    receive = channel.receive(1000);
    assertNotNull(receive);
    assertEquals("none", receive.getPayload());
    context.close();
}
Also used : MongoClient(com.mongodb.MongoClient) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) QueueChannel(org.springframework.integration.channel.QueueChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PriorityChannel(org.springframework.integration.channel.PriorityChannel) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 47 with MongoDbAvailable

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

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

the class MongoDbOutboundGatewayXmlTests method testSingleQuery.

@Test
@MongoDbAvailable
public void testSingleQuery() throws Exception {
    EventDrivenConsumer consumer = context.getBean("gatewaySingleQuery", EventDrivenConsumer.class);
    PollableChannel outChannel = context.getBean("out", PollableChannel.class);
    Message<String> message = MessageBuilder.withPayload("").build();
    consumer.getHandler().handleMessage(message);
    Message<?> result = outChannel.receive(10000);
    Person person = getPerson(result);
    assertEquals("Xavi", person.getName());
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 49 with MongoDbAvailable

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

the class MongoDbOutboundGatewayXmlTests method testSingleQueryWithTemplate.

@Test
@MongoDbAvailable
public void testSingleQueryWithTemplate() throws Exception {
    EventDrivenConsumer consumer = context.getBean("gatewayWithTemplate", EventDrivenConsumer.class);
    PollableChannel outChannel = context.getBean("out", PollableChannel.class);
    Message<String> message = MessageBuilder.withPayload("").build();
    consumer.getHandler().handleMessage(message);
    Message<?> result = outChannel.receive(10000);
    Person person = getPerson(result);
    assertEquals("Xavi", person.getName());
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 50 with MongoDbAvailable

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

the class MongoDbOutboundChannelAdapterIntegrationTests method testSavingJSONString.

@Test
@MongoDbAvailable
public void testSavingJSONString() throws Exception {
    String object = "{'foo' : 'bar'}";
    MongoDbFactory mongoDbFactory = this.prepareMongoFactory("foo");
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
    MessageChannel channel = context.getBean("simpleAdapterWithTemplate", MessageChannel.class);
    Message<String> message = MessageBuilder.withPayload(object).setHeader("collectionName", "foo").build();
    channel.send(message);
    MongoTemplate template = new MongoTemplate(mongoDbFactory);
    assertNotNull(template.find(new BasicQuery("{'foo' : 'bar'}"), BasicDBObject.class, "foo"));
    context.close();
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) MessageChannel(org.springframework.messaging.MessageChannel) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) 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