GH-3839: Migrate MongoDB tests to Testcontainers
Fixes https://github.com/spring-projects/spring-integration/issues/3839 * Create a new base interface for Mongo container-based tests * Migrate all tests to JUnit5 * Remove obsolete classes related to JUnit4 Mongo rule * Fix code style & readability here and there, a few Sonar issues * Fix failing test `validateWithConfiguredPollerFlow` * * This test was failing with Mongo error `$and/$or/$nor must be a nonempty array`. The cause was too small polling ratio of the update query, the consecutive read queries failed as no 'Oleg' document was in collection after ~100 ms. Couple of changes after the pull request review: * Get back the blank lines in test classes * Get back the blank lines for some inner classes * Eliminate bad renaming consequences * Remove a couple of garbage todos * Couple of places with code cleanup
This commit is contained in:
committed by
Artem Bilan
parent
850671698b
commit
50769d0350
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2020-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,14 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.mongodb.rules;
|
||||
package org.springframework.integration.mongodb;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.bson.UuidRepresentation;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.junit.Rule;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
@@ -40,50 +42,64 @@ import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
||||
import org.springframework.integration.mongodb.outbound.MessageCollectionCallback;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
import com.mongodb.ConnectionString;
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.MongoException;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
|
||||
|
||||
/**
|
||||
* Convenience base class that enables unit test methods to rely upon the {@link MongoDbAvailable} annotation.
|
||||
* The base contract for all tests requiring a MongoDb connection.
|
||||
* The Testcontainers 'reuse' option must be disabled, so, Ryuk container is started
|
||||
* and will clean all the containers up from this test suite after JVM exit.
|
||||
* Since the Redis container instance is shared via static property, it is going to be
|
||||
* started only once per JVM, therefore the target Docker container is reused automatically.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Xavier Padro
|
||||
* @author Artem Bilan
|
||||
* @author David Turanski
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
* @since 2.1
|
||||
* @since 6.0
|
||||
*/
|
||||
public abstract class MongoDbAvailableTests {
|
||||
@Testcontainers(disabledWithoutDocker = true)
|
||||
public interface MongoDbContainerTest {
|
||||
|
||||
@Rule
|
||||
public MongoDbAvailableRule mongoDbAvailableRule = new MongoDbAvailableRule();
|
||||
GenericContainer<?> MONGO_CONTAINER = new GenericContainer<>("mongo:5.0.9")
|
||||
.withExposedPorts(27017);
|
||||
|
||||
public static final MongoDatabaseFactory MONGO_DATABASE_FACTORY =
|
||||
new SimpleMongoClientDatabaseFactory(
|
||||
MongoClients.create(
|
||||
MongoClientSettings.builder().uuidRepresentation(UuidRepresentation.STANDARD).build()),
|
||||
"test");
|
||||
|
||||
public static final ReactiveMongoDatabaseFactory REACTIVE_MONGO_DATABASE_FACTORY =
|
||||
new SimpleReactiveMongoDatabaseFactory(
|
||||
com.mongodb.reactivestreams.client.MongoClients.create(
|
||||
MongoClientSettings.builder().uuidRepresentation(UuidRepresentation.STANDARD).build()),
|
||||
"test");
|
||||
|
||||
protected MongoDatabaseFactory prepareMongoFactory(String... additionalCollectionsToDrop) {
|
||||
cleanupCollections(MONGO_DATABASE_FACTORY, additionalCollectionsToDrop);
|
||||
return MONGO_DATABASE_FACTORY;
|
||||
@BeforeAll
|
||||
static void startContainer() {
|
||||
MONGO_CONTAINER.start();
|
||||
}
|
||||
|
||||
protected ReactiveMongoDatabaseFactory prepareReactiveMongoFactory(String... additionalCollectionsToDrop) {
|
||||
cleanupCollections(REACTIVE_MONGO_DATABASE_FACTORY, additionalCollectionsToDrop);
|
||||
return REACTIVE_MONGO_DATABASE_FACTORY;
|
||||
static MongoDatabaseFactory createMongoDbFactory() {
|
||||
return new SimpleMongoClientDatabaseFactory(MongoClients.create(getMongoClientSettings()), "test");
|
||||
}
|
||||
|
||||
protected void cleanupCollections(ReactiveMongoDatabaseFactory mongoDbFactory,
|
||||
static ReactiveMongoDatabaseFactory createReactiveMongoDbFactory() {
|
||||
return new SimpleReactiveMongoDatabaseFactory(
|
||||
com.mongodb.reactivestreams.client.MongoClients.create(getMongoClientSettings()),
|
||||
"test");
|
||||
}
|
||||
|
||||
private static MongoClientSettings getMongoClientSettings() {
|
||||
return MongoClientSettings.builder()
|
||||
.applyConnectionString(new ConnectionString(
|
||||
"mongodb://localhost:" + MONGO_CONTAINER.getFirstMappedPort()))
|
||||
.uuidRepresentation(UuidRepresentation.STANDARD).build();
|
||||
}
|
||||
|
||||
static void prepareMongoData(MongoDatabaseFactory mongoDatabaseFactory, String... additionalCollectionsToDrop) {
|
||||
cleanupCollections(mongoDatabaseFactory, additionalCollectionsToDrop);
|
||||
}
|
||||
|
||||
static void prepareReactiveMongoData(ReactiveMongoDatabaseFactory mongoDatabaseFactory, String... additionalCollectionsToDrop) {
|
||||
cleanupCollections(mongoDatabaseFactory, additionalCollectionsToDrop);
|
||||
}
|
||||
|
||||
static void cleanupCollections(ReactiveMongoDatabaseFactory mongoDbFactory,
|
||||
String... additionalCollectionsToDrop) {
|
||||
|
||||
ReactiveMongoTemplate template = new ReactiveMongoTemplate(mongoDbFactory);
|
||||
@@ -95,7 +111,7 @@ public abstract class MongoDbAvailableTests {
|
||||
}
|
||||
}
|
||||
|
||||
protected void cleanupCollections(MongoDatabaseFactory mongoDbFactory, String... additionalCollectionsToDrop) {
|
||||
static void cleanupCollections(MongoDatabaseFactory mongoDbFactory, String... additionalCollectionsToDrop) {
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
template.dropCollection("messages");
|
||||
template.dropCollection("configurableStoreMessages");
|
||||
@@ -105,7 +121,7 @@ public abstract class MongoDbAvailableTests {
|
||||
}
|
||||
}
|
||||
|
||||
protected Person createPerson() {
|
||||
static Person createPerson() {
|
||||
Address address = new Address();
|
||||
address.setCity("Philadelphia");
|
||||
address.setStreet("2121 Rawn street");
|
||||
@@ -117,7 +133,7 @@ public abstract class MongoDbAvailableTests {
|
||||
return person;
|
||||
}
|
||||
|
||||
protected Person createPerson(String name) {
|
||||
static Person createPerson(String name) {
|
||||
Address address = new Address();
|
||||
address.setCity("Philadelphia");
|
||||
address.setStreet("2121 Rawn street");
|
||||
@@ -129,7 +145,7 @@ public abstract class MongoDbAvailableTests {
|
||||
return person;
|
||||
}
|
||||
|
||||
public static class Person {
|
||||
class Person {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@@ -156,7 +172,7 @@ public abstract class MongoDbAvailableTests {
|
||||
|
||||
}
|
||||
|
||||
public static class Address {
|
||||
class Address {
|
||||
|
||||
private String street;
|
||||
|
||||
@@ -190,7 +206,7 @@ public abstract class MongoDbAvailableTests {
|
||||
|
||||
}
|
||||
|
||||
public static class TestMongoConverter extends MappingMongoConverter {
|
||||
class TestMongoConverter extends MappingMongoConverter {
|
||||
|
||||
public TestMongoConverter(
|
||||
MongoDatabaseFactory mongoDbFactory,
|
||||
@@ -211,7 +227,7 @@ public abstract class MongoDbAvailableTests {
|
||||
|
||||
}
|
||||
|
||||
public static class ReactiveTestMongoConverter extends MappingMongoConverter {
|
||||
class ReactiveTestMongoConverter extends MappingMongoConverter {
|
||||
|
||||
public ReactiveTestMongoConverter(
|
||||
ReactiveMongoDatabaseFactory mongoDbFactory,
|
||||
@@ -232,7 +248,7 @@ public abstract class MongoDbAvailableTests {
|
||||
|
||||
}
|
||||
|
||||
public static class TestCollectionCallback implements MessageCollectionCallback<Long> {
|
||||
class TestCollectionCallback implements MessageCollectionCallback<Long> {
|
||||
|
||||
@Override
|
||||
public Long doInCollection(MongoCollection<Document> collection, Message<?> message)
|
||||
@@ -3,22 +3,21 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
|
||||
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/mongodb https://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd
|
||||
http://www.springframework.org/schema/tx https://www.springframework.org/schema/tx/spring-tx.xsd">
|
||||
|
||||
<mongo:db-factory id="mongoDbFactory" dbname="test" />
|
||||
<bean id="mongoDbFactory" class="org.springframework.integration.mongodb.MongoDbContainerTest"
|
||||
factory-method="createMongoDbFactory"/>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapter"
|
||||
channel="replyChannel"
|
||||
query="{'name' : 'Bob'}"
|
||||
entity-class="java.lang.Object"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-delay="100" />
|
||||
<int:poller fixed-delay="100"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterNamedFactory"
|
||||
@@ -26,7 +25,7 @@
|
||||
channel="replyChannel"
|
||||
query="{'name' : 'Bob'}"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-delay="5000" />
|
||||
<int:poller fixed-delay="5000"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithTemplate"
|
||||
@@ -34,9 +33,9 @@
|
||||
mongo-template="mongoDbTemplate"
|
||||
query="{'name' : 'Bob'}"
|
||||
expect-single-result="true"
|
||||
entity-class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests.Person"
|
||||
entity-class="org.springframework.integration.mongodb.MongoDbContainerTest.Person"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-delay="5000" />
|
||||
<int:poller fixed-delay="5000"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithNamedCollection"
|
||||
@@ -46,7 +45,7 @@
|
||||
query="{'name' : 'Bob'}"
|
||||
entity-class="java.lang.Object"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-delay="5000" />
|
||||
<int:poller fixed-delay="5000"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithStringQueryExpression"
|
||||
channel="replyChannel"
|
||||
@@ -55,7 +54,7 @@
|
||||
query-expression="new String('{''name'' : ''Bob''}')"
|
||||
entity-class="java.lang.Object"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-rate="5000" />
|
||||
<int:poller fixed-rate="5000"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithQueryExpression"
|
||||
@@ -65,7 +64,7 @@
|
||||
query-expression="new BasicQuery('{''name'' : ''Bob''}').limit(1)"
|
||||
entity-class="java.lang.Object"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-rate="5000" />
|
||||
<int:poller fixed-rate="5000"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithNamedCollectionExpression"
|
||||
@@ -75,7 +74,7 @@
|
||||
query="{'name' : 'Bob'}"
|
||||
entity-class="java.lang.Object"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-delay="5000" />
|
||||
<int:poller fixed-delay="5000"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="inboundAdapterWithOnSuccessDisposition"
|
||||
@@ -84,12 +83,12 @@
|
||||
auto-startup="false">
|
||||
|
||||
<int:poller fixed-delay="200" max-messages-per-poll="1">
|
||||
<int:advice-chain synchronization-factory="syncFactory">
|
||||
<int:advice-chain synchronization-factory="syncFactory">
|
||||
<bean
|
||||
class="org.springframework.integration.mongodb.config.MongoDbInboundChannelAdapterIntegrationTests.TestMessageSourceAdvice" />
|
||||
class="org.springframework.integration.mongodb.config.MongoDbInboundChannelAdapterIntegrationTests.TestMessageSourceAdvice"/>
|
||||
<tx:advice>
|
||||
<tx:attributes>
|
||||
<tx:method name="*" />
|
||||
<tx:method name="*"/>
|
||||
</tx:attributes>
|
||||
</tx:advice>
|
||||
</int:advice-chain>
|
||||
@@ -102,7 +101,7 @@
|
||||
</int:transaction-synchronization-factory>
|
||||
|
||||
<int:channel id="afterCommitChannel">
|
||||
<int:queue />
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithConverter"
|
||||
@@ -111,28 +110,28 @@
|
||||
entity-class="java.lang.Object"
|
||||
mongo-converter="mongoConverter"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-delay="100" />
|
||||
<int:poller fixed-delay="100"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<bean id="documentCleaner"
|
||||
class="org.springframework.integration.mongodb.config.MongoDbInboundChannelAdapterIntegrationTests.DocumentCleaner" />
|
||||
class="org.springframework.integration.mongodb.config.MongoDbInboundChannelAdapterIntegrationTests.DocumentCleaner"/>
|
||||
|
||||
<bean id="mongoDbTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
|
||||
<constructor-arg ref="mongoDbFactory" />
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
</bean>
|
||||
|
||||
<bean id="mongoConverter"
|
||||
class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory" />
|
||||
class="org.springframework.integration.mongodb.MongoDbContainerTest.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" />
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<int:channel id="replyChannel">
|
||||
<int:queue />
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.integration.transaction.PseudoTransactionManager" />
|
||||
<bean id="transactionManager" class="org.springframework.integration.transaction.PseudoTransactionManager"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,11 +17,11 @@
|
||||
package org.springframework.integration.mongodb.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -34,11 +34,10 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.integration.aop.ReceiveMessageAdvice;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
|
||||
@@ -46,12 +45,13 @@ import com.mongodb.BasicDBObject;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Artem Bilan
|
||||
* @author Yaron Yamin
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailableTests {
|
||||
class MongoDbInboundChannelAdapterIntegrationTests implements MongoDbContainerTest {
|
||||
|
||||
@Autowired
|
||||
private MongoTemplate mongoTemplate;
|
||||
@@ -99,9 +99,8 @@ public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailab
|
||||
private SourcePollingChannelAdapter mongoInboundAdapterWithConverter;
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithDefaultMongoFactory() {
|
||||
this.mongoTemplate.save(createPerson("Bob"), "data");
|
||||
void testWithDefaultMongoFactory() {
|
||||
this.mongoTemplate.save(MongoDbContainerTest.createPerson("Bob"), "data");
|
||||
|
||||
this.mongoInboundAdapter.start();
|
||||
|
||||
@@ -116,25 +115,23 @@ public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailab
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithNamedMongoFactory() {
|
||||
this.mongoTemplate.save(this.createPerson("Bob"), "data");
|
||||
void testWithNamedMongoFactory() {
|
||||
this.mongoTemplate.save(MongoDbContainerTest.createPerson("Bob"), "data");
|
||||
|
||||
this.mongoInboundAdapterNamedFactory.start();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Message<List<BasicDBObject>> message = (Message<List<BasicDBObject>>) replyChannel.receive(10000);
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().get(0).get("name")).isEqualTo("Bob");
|
||||
assertThat(message.getPayload().get(0)).containsEntry("name", "Bob");
|
||||
|
||||
this.mongoInboundAdapterNamedFactory.stop();
|
||||
this.replyChannel.purge(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithMongoTemplate() {
|
||||
this.mongoTemplate.save(this.createPerson("Bob"), "data");
|
||||
void testWithMongoTemplate() {
|
||||
this.mongoTemplate.save(MongoDbContainerTest.createPerson("Bob"), "data");
|
||||
|
||||
this.mongoInboundAdapterWithTemplate.start();
|
||||
|
||||
@@ -148,9 +145,8 @@ public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailab
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithNamedCollection() {
|
||||
this.mongoTemplate.save(this.createPerson("Bob"), "foo");
|
||||
void testWithNamedCollection() {
|
||||
this.mongoTemplate.save(MongoDbContainerTest.createPerson("Bob"), "foo");
|
||||
|
||||
this.mongoInboundAdapterWithNamedCollection.start();
|
||||
|
||||
@@ -164,23 +160,21 @@ public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailab
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithQueryExpression() {
|
||||
this.mongoTemplate.save(this.createPerson("Bob"), "foo");
|
||||
this.mongoTemplate.save(this.createPerson("Bob"), "foo");
|
||||
void testWithQueryExpression() {
|
||||
this.mongoTemplate.save(MongoDbContainerTest.createPerson("Bob"), "foo");
|
||||
this.mongoTemplate.save(MongoDbContainerTest.createPerson("Bob"), "foo");
|
||||
this.mongoInboundAdapterWithQueryExpression.start();
|
||||
@SuppressWarnings("unchecked")
|
||||
Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000);
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getPayload().size()).isEqualTo(1);
|
||||
assertThat(message.getPayload()).hasSize(1);
|
||||
assertThat(message.getPayload().get(0).getName()).isEqualTo("Bob");
|
||||
this.mongoInboundAdapterWithQueryExpression.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithStringQueryExpression() {
|
||||
this.mongoTemplate.save(this.createPerson("Bob"), "foo");
|
||||
void testWithStringQueryExpression() {
|
||||
this.mongoTemplate.save(MongoDbContainerTest.createPerson("Bob"), "foo");
|
||||
this.mongoInboundAdapterWithStringQueryExpression.start();
|
||||
@SuppressWarnings("unchecked")
|
||||
Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000);
|
||||
@@ -190,9 +184,8 @@ public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailab
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithNamedCollectionExpression() {
|
||||
this.mongoTemplate.save(this.createPerson("Bob"), "foo");
|
||||
void testWithNamedCollectionExpression() {
|
||||
this.mongoTemplate.save(MongoDbContainerTest.createPerson("Bob"), "foo");
|
||||
|
||||
this.mongoInboundAdapterWithNamedCollectionExpression.start();
|
||||
|
||||
@@ -206,9 +199,8 @@ public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailab
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithOnSuccessDisposition() {
|
||||
this.mongoTemplate.save(createPerson("Bob"), "data");
|
||||
void testWithOnSuccessDisposition() {
|
||||
this.mongoTemplate.save(MongoDbContainerTest.createPerson("Bob"), "data");
|
||||
|
||||
this.inboundAdapterWithOnSuccessDisposition.start();
|
||||
|
||||
@@ -224,9 +216,8 @@ public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailab
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithMongoConverter() {
|
||||
this.mongoTemplate.save(this.createPerson("Bob"), "data");
|
||||
void testWithMongoConverter() {
|
||||
this.mongoTemplate.save(MongoDbContainerTest.createPerson("Bob"), "data");
|
||||
|
||||
this.mongoInboundAdapterWithConverter.start();
|
||||
|
||||
@@ -240,28 +231,28 @@ public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailab
|
||||
this.replyChannel.purge(null);
|
||||
}
|
||||
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
@MongoDbAvailable
|
||||
public void testFailureWithQueryAndQueryExpression() {
|
||||
new ClassPathXmlApplicationContext("inbound-fail-q-qex.xml", this.getClass()).close();
|
||||
@Test
|
||||
void testFailureWithQueryAndQueryExpression() {
|
||||
assertThatThrownBy(() -> new ClassPathXmlApplicationContext("inbound-fail-q-qex.xml", MongoDbInboundChannelAdapterIntegrationTests.class))
|
||||
.isInstanceOf(BeanDefinitionParsingException.class);
|
||||
}
|
||||
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
@MongoDbAvailable
|
||||
public void testFailureWithFactoryAndTemplate() {
|
||||
new ClassPathXmlApplicationContext("inbound-fail-factory-template.xml", this.getClass()).close();
|
||||
@Test
|
||||
void testFailureWithFactoryAndTemplate() {
|
||||
assertThatThrownBy(() -> new ClassPathXmlApplicationContext("inbound-fail-factory-template.xml", MongoDbInboundChannelAdapterIntegrationTests.class))
|
||||
.isInstanceOf(BeanDefinitionParsingException.class);
|
||||
}
|
||||
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
@MongoDbAvailable
|
||||
public void testFailureWithCollectionAndCollectionExpression() {
|
||||
new ClassPathXmlApplicationContext("inbound-fail-c-cex.xml", this.getClass()).close();
|
||||
@Test
|
||||
void testFailureWithCollectionAndCollectionExpression() {
|
||||
assertThatThrownBy(() -> new ClassPathXmlApplicationContext("inbound-fail-c-cex.xml", MongoDbInboundChannelAdapterIntegrationTests.class))
|
||||
.isInstanceOf(BeanDefinitionParsingException.class);
|
||||
}
|
||||
|
||||
@Test(expected = BeanDefinitionParsingException.class)
|
||||
@MongoDbAvailable
|
||||
public void testFailureWithTemplateAndConverter() {
|
||||
new ClassPathXmlApplicationContext("inbound-fail-converter-template.xml", this.getClass()).close();
|
||||
@Test
|
||||
void testFailureWithTemplateAndConverter() {
|
||||
assertThatThrownBy(() -> new ClassPathXmlApplicationContext("inbound-fail-converter-template.xml", MongoDbInboundChannelAdapterIntegrationTests.class))
|
||||
.isInstanceOf(BeanDefinitionParsingException.class);
|
||||
}
|
||||
|
||||
public static class DocumentCleaner {
|
||||
|
||||
@@ -13,36 +13,36 @@
|
||||
</bean>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="minimalConfig"
|
||||
query="bar"
|
||||
auto-startup="false">
|
||||
query="bar"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-rate="100"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="fullConfigWithCollectionExpression"
|
||||
collection-name-expression="'foo'"
|
||||
query="bar"
|
||||
mongo-converter="mongoConverter"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
auto-startup="false">
|
||||
collection-name-expression="'foo'"
|
||||
query="bar"
|
||||
mongo-converter="mongoConverter"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-rate="100"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="fullConfigWithQueryExpression"
|
||||
collection-name-expression="'foo'"
|
||||
query-expression="new BasicQuery('{''address.state'' : ''PA''}').limit(2)"
|
||||
update="{ $set: {'address.state' : 'NJ'} }"
|
||||
mongo-converter="mongoConverter"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
auto-startup="false">
|
||||
collection-name-expression="'foo'"
|
||||
query-expression="new BasicQuery('{''address.state'' : ''PA''}').limit(2)"
|
||||
update="{ $set: {'address.state' : 'NJ'} }"
|
||||
mongo-converter="mongoConverter"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-rate="100"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="fullConfigWithSpelQuery"
|
||||
collection-name-expression="'foo'"
|
||||
query="{''address.state'' : ''PA''}"
|
||||
mongo-converter="mongoConverter"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
auto-startup="false">
|
||||
collection-name-expression="'foo'"
|
||||
query="{''address.state'' : ''PA''}"
|
||||
mongo-converter="mongoConverter"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-rate="100"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
@@ -56,23 +56,23 @@
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="fullConfigWithCollectionName"
|
||||
collection-name="foo"
|
||||
query="bar"
|
||||
mongo-converter="mongoConverter"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
auto-startup="false">
|
||||
collection-name="foo"
|
||||
query="bar"
|
||||
mongo-converter="mongoConverter"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-rate="100"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="fullConfigWithMongoTemplate"
|
||||
collection-name="foo"
|
||||
query="bar"
|
||||
mongo-template="mongoDbTemplate"
|
||||
auto-startup="false">
|
||||
collection-name="foo"
|
||||
query="bar"
|
||||
mongo-template="mongoDbTemplate"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-rate="100"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests.TestMongoConverter">
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.MongoDbContainerTest.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,14 +18,14 @@ package org.springframework.integration.mongodb.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.BasicQuery;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -36,71 +36,75 @@ import com.mongodb.BasicDBObject;
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*/
|
||||
public class MongoDbOutboundChannelAdapterIntegrationTests extends MongoDbAvailableTests {
|
||||
class MongoDbOutboundChannelAdapterIntegrationTests implements MongoDbContainerTest {
|
||||
|
||||
static MongoDatabaseFactory MONGO_DATABASE_FACTORY;
|
||||
|
||||
@BeforeAll
|
||||
static void prepareMongoConnection() {
|
||||
MONGO_DATABASE_FACTORY = MongoDbContainerTest.createMongoDbFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithDefaultMongoFactory() throws Exception {
|
||||
void testWithDefaultMongoFactory() throws Exception {
|
||||
ClassPathXmlApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
|
||||
|
||||
MessageChannel channel = context.getBean("simpleAdapter", MessageChannel.class);
|
||||
Message<Person> message = new GenericMessage<MongoDbAvailableTests.Person>(this.createPerson("Bob"));
|
||||
Message<Person> message = new GenericMessage<MongoDbContainerTest.Person>(MongoDbContainerTest.createPerson("Bob"));
|
||||
channel.send(message);
|
||||
|
||||
MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory();
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY);
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
assertThat(template.find(new BasicQuery("{'name' : 'Bob'}"), Person.class, "data")).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithNamedCollection() throws Exception {
|
||||
MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory("foo");
|
||||
void testWithNamedCollection() throws Exception {
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY, "foo");
|
||||
ClassPathXmlApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
|
||||
|
||||
MessageChannel channel = context.getBean("simpleAdapterWithNamedCollection", MessageChannel.class);
|
||||
Message<Person> message =
|
||||
MessageBuilder.withPayload(this.createPerson("Bob"))
|
||||
MessageBuilder.withPayload(MongoDbContainerTest.createPerson("Bob"))
|
||||
.setHeader("collectionName", "foo")
|
||||
.build();
|
||||
channel.send(message);
|
||||
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
assertThat(template.find(new BasicQuery("{'name' : 'Bob'}"), Person.class, "foo")).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithTemplate() throws Exception {
|
||||
MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory("foo");
|
||||
void testWithTemplate() throws Exception {
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY, "foo");
|
||||
ClassPathXmlApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
|
||||
|
||||
MessageChannel channel = context.getBean("simpleAdapterWithTemplate", MessageChannel.class);
|
||||
Message<Person> message =
|
||||
MessageBuilder.withPayload(this.createPerson("Bob"))
|
||||
MessageBuilder.withPayload(MongoDbContainerTest.createPerson("Bob"))
|
||||
.setHeader("collectionName", "foo")
|
||||
.build();
|
||||
|
||||
channel.send(message);
|
||||
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
assertThat(template.find(new BasicQuery("{'name' : 'Bob'}"), Person.class, "foo")).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testSavingDbObject() throws Exception {
|
||||
void testSavingDbObject() throws Exception {
|
||||
|
||||
BasicDBObject dbObject = BasicDBObject.parse("{'foo' : 'bar'}");
|
||||
|
||||
MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory("foo");
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY, "foo");
|
||||
ClassPathXmlApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
|
||||
|
||||
@@ -113,18 +117,17 @@ public class MongoDbOutboundChannelAdapterIntegrationTests extends MongoDbAvaila
|
||||
|
||||
channel.send(message);
|
||||
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
assertThat(template.find(new BasicQuery("{'foo' : 'bar'}"), BasicDBObject.class, "foo")).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testSavingJSONString() throws Exception {
|
||||
void testSavingJSONString() throws Exception {
|
||||
|
||||
String object = "{'foo' : 'bar'}";
|
||||
|
||||
MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory("foo");
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY, "foo");
|
||||
ClassPathXmlApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
|
||||
|
||||
@@ -137,23 +140,22 @@ public class MongoDbOutboundChannelAdapterIntegrationTests extends MongoDbAvaila
|
||||
|
||||
channel.send(message);
|
||||
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
assertThat(template.find(new BasicQuery("{'foo' : 'bar'}"), BasicDBObject.class, "foo")).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithMongoConverter() throws Exception {
|
||||
void testWithMongoConverter() throws Exception {
|
||||
ClassPathXmlApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
|
||||
|
||||
MessageChannel channel = context.getBean("simpleAdapterWithConverter", MessageChannel.class);
|
||||
Message<Person> message = new GenericMessage<MongoDbAvailableTests.Person>(this.createPerson("Bob"));
|
||||
Message<Person> message = new GenericMessage<MongoDbContainerTest.Person>(MongoDbContainerTest.createPerson("Bob"));
|
||||
channel.send(message);
|
||||
|
||||
MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory();
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY);
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
assertThat(template.find(new BasicQuery("{'name' : 'Bob'}"), Person.class, "data")).isNotNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/mongodb https://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd">
|
||||
|
||||
@@ -15,18 +15,18 @@
|
||||
<int-mongodb:outbound-channel-adapter id="minimalConfig"/>
|
||||
|
||||
<int-mongodb:outbound-channel-adapter id="fullConfigWithCollectionExpression"
|
||||
collection-name-expression="headers.collectionName"
|
||||
mongo-converter="mongoConverter"
|
||||
mongodb-factory="mongoDbFactory"/>
|
||||
collection-name-expression="headers.collectionName"
|
||||
mongo-converter="mongoConverter"
|
||||
mongodb-factory="mongoDbFactory"/>
|
||||
|
||||
<int-mongodb:outbound-channel-adapter id="fullConfigWithCollection"
|
||||
collection-name="foo"
|
||||
mongo-converter="mongoConverter"
|
||||
mongodb-factory="mongoDbFactory"/>
|
||||
collection-name="foo"
|
||||
mongo-converter="mongoConverter"
|
||||
mongodb-factory="mongoDbFactory"/>
|
||||
|
||||
<int-mongodb:outbound-channel-adapter id="fullConfigWithMongoTemplate"
|
||||
collection-name="foo"
|
||||
mongo-template="mongoDbTemplate"/>
|
||||
collection-name="foo"
|
||||
mongo-template="mongoDbTemplate"/>
|
||||
|
||||
<int:channel id="input">
|
||||
<int:queue/>
|
||||
@@ -43,7 +43,7 @@
|
||||
</int-mongodb:outbound-channel-adapter>
|
||||
|
||||
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests.TestMongoConverter">
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.MongoDbContainerTest.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/mongodb https://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd">
|
||||
|
||||
<int:channel id="in"/>
|
||||
|
||||
<int:channel id="inQueue">
|
||||
<int:queue />
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int:channel id="out"/>
|
||||
|
||||
<int-mongodb:outbound-gateway id="minimalConfig"
|
||||
query="{'name' : 'foo'}"
|
||||
collection-name="foo"
|
||||
request-channel="inQueue"
|
||||
reply-channel="out">
|
||||
query="{'name' : 'foo'}"
|
||||
collection-name="foo"
|
||||
request-channel="inQueue"
|
||||
reply-channel="out">
|
||||
<int:poller fixed-delay="1000"/>
|
||||
<int-mongodb:request-handler-advice-chain>
|
||||
<bean class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice"/>
|
||||
@@ -27,34 +27,34 @@
|
||||
</int-mongodb:outbound-gateway>
|
||||
|
||||
<int-mongodb:outbound-gateway id="fullConfigWithCollectionExpression"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
collection-name-expression="headers.collectionName"
|
||||
query="{'name' : 'foo'}"
|
||||
request-channel="in"
|
||||
reply-channel="out"/>
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
collection-name-expression="headers.collectionName"
|
||||
query="{'name' : 'foo'}"
|
||||
request-channel="in"
|
||||
reply-channel="out"/>
|
||||
|
||||
<int-mongodb:outbound-gateway id="fullConfigWithCollection"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
query="{'name' : 'foo'}"
|
||||
collection-name="foo"
|
||||
request-channel="in"
|
||||
reply-channel="out"/>
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
query="{'name' : 'foo'}"
|
||||
collection-name="foo"
|
||||
request-channel="in"
|
||||
reply-channel="out"/>
|
||||
|
||||
<int-mongodb:outbound-gateway id="fullConfigWithTemplate"
|
||||
mongo-template="mongoDbTemplate"
|
||||
collection-name="foo"
|
||||
query="{'name' : 'foo'}"
|
||||
request-channel="in"
|
||||
reply-channel="out"/>
|
||||
mongo-template="mongoDbTemplate"
|
||||
collection-name="foo"
|
||||
query="{'name' : 'foo'}"
|
||||
request-channel="in"
|
||||
reply-channel="out"/>
|
||||
|
||||
<int-mongodb:outbound-gateway id="fullConfigWithMongoDbCollectionCallback"
|
||||
mongo-template="mongoDbTemplate"
|
||||
collection-name="foo"
|
||||
collection-callback="mockCollectionCallback"
|
||||
request-channel="in"
|
||||
reply-channel="out"/>
|
||||
mongo-template="mongoDbTemplate"
|
||||
collection-name="foo"
|
||||
collection-callback="mockCollectionCallback"
|
||||
request-channel="in"
|
||||
reply-channel="out"/>
|
||||
|
||||
|
||||
<bean id="mockCollectionCallback" class="org.mockito.Mockito" factory-method="mock">
|
||||
@@ -67,7 +67,7 @@
|
||||
</bean>
|
||||
|
||||
<bean id="mongoConverter"
|
||||
class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests.TestMongoConverter">
|
||||
class="org.springframework.integration.mongodb.MongoDbContainerTest.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
|
||||
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/mongodb https://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd">
|
||||
|
||||
@@ -14,14 +12,14 @@
|
||||
</bean>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="minimalConfig"
|
||||
query="bar"
|
||||
mongo-template="mongoDbTemplate"
|
||||
mongo-converter="mongoConverter"
|
||||
auto-startup="false">
|
||||
query="bar"
|
||||
mongo-template="mongoDbTemplate"
|
||||
mongo-converter="mongoConverter"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-rate="100"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests.TestMongoConverter">
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.MongoDbContainerTest.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
|
||||
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/mongodb https://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd">
|
||||
|
||||
<mongo:db-factory id="mongoDbFactory" dbname="test"/>
|
||||
<bean id="mongoDbFactory" class="org.springframework.integration.mongodb.MongoDbContainerTest"
|
||||
factory-method="createMongoDbFactory"/>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapter"
|
||||
channel="replyChannel"
|
||||
collection-name="bar"
|
||||
collection-name-expression="''"
|
||||
query-expression="''"
|
||||
auto-startup="false">
|
||||
channel="replyChannel"
|
||||
collection-name="bar"
|
||||
collection-name-expression="''"
|
||||
query-expression="''"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-rate="5000"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
|
||||
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/mongodb https://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd">
|
||||
|
||||
<mongo:db-factory id="mongoDbFactory" dbname="test"/>
|
||||
<bean id="mongoDbFactory" class="org.springframework.integration.mongodb.MongoDbContainerTest"
|
||||
factory-method="createMongoDbFactory"/>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapter"
|
||||
channel="replyChannel"
|
||||
query="{'name' : 'Bob'}"
|
||||
mongo-template="mongoDbTemplate"
|
||||
mongo-converter="mongoConverter"
|
||||
auto-startup="false">
|
||||
channel="replyChannel"
|
||||
query="{'name' : 'Bob'}"
|
||||
mongo-template="mongoDbTemplate"
|
||||
mongo-converter="mongoConverter"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-rate="5000"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
@@ -24,7 +23,7 @@
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
</bean>
|
||||
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests.TestMongoConverter">
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.MongoDbContainerTest.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
|
||||
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/mongodb https://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd">
|
||||
|
||||
<mongo:db-factory id="mongoDbFactory" dbname="test"/>
|
||||
<bean id="mongoDbFactory" class="org.springframework.integration.mongodb.MongoDbContainerTest"
|
||||
factory-method="createMongoDbFactory"/>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapter"
|
||||
channel="replyChannel"
|
||||
query="{'name' : 'Bob'}"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-template="mongoDbTemplate"
|
||||
auto-startup="false">
|
||||
channel="replyChannel"
|
||||
query="{'name' : 'Bob'}"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-template="mongoDbTemplate"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-rate="5000"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
|
||||
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/mongodb https://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd">
|
||||
|
||||
<mongo:db-factory id="mongoDbFactory" dbname="test"/>
|
||||
<bean id="mongoDbFactory" class="org.springframework.integration.mongodb.MongoDbContainerTest"
|
||||
factory-method="createMongoDbFactory"/>
|
||||
|
||||
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapter"
|
||||
channel="replyChannel"
|
||||
query="{'name' : 'Bob'}"
|
||||
query-expression="''"
|
||||
auto-startup="false">
|
||||
channel="replyChannel"
|
||||
query="{'name' : 'Bob'}"
|
||||
query-expression="''"
|
||||
auto-startup="false">
|
||||
<int:poller fixed-rate="5000"/>
|
||||
</int-mongodb:inbound-channel-adapter>
|
||||
|
||||
|
||||
@@ -1,29 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
|
||||
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/mongodb https://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd">
|
||||
|
||||
<mongo:db-factory id="mongoDbFactory" dbname="test"/>
|
||||
<bean id="mongoDbFactory" class="org.springframework.integration.mongodb.MongoDbContainerTest"
|
||||
factory-method="createMongoDbFactory"/>
|
||||
|
||||
<int-mongodb:outbound-channel-adapter id="simpleAdapter"/>
|
||||
|
||||
<int-mongodb:outbound-channel-adapter id="simpleAdapterWithNamedCollection"
|
||||
collection-name-expression="headers.collectionName"/>
|
||||
collection-name-expression="headers.collectionName"/>
|
||||
|
||||
<int-mongodb:outbound-channel-adapter id="simpleAdapterWithTemplate"
|
||||
collection-name-expression="headers.collectionName"
|
||||
mongo-template="mongoDbTemplate"/>
|
||||
collection-name-expression="headers.collectionName"
|
||||
mongo-template="mongoDbTemplate"/>
|
||||
|
||||
<int-mongodb:outbound-channel-adapter id="simpleAdapterWithConverter"
|
||||
mongo-converter="mongoConverter"/>
|
||||
mongo-converter="mongoConverter"/>
|
||||
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests.TestMongoConverter">
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.MongoDbContainerTest.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
|
||||
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/mongodb https://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd">
|
||||
|
||||
<bean id="mongoDbFactory" class="org.mockito.Mockito" factory-method="mock">
|
||||
@@ -14,11 +10,11 @@
|
||||
</bean>
|
||||
|
||||
<int-mongodb:outbound-channel-adapter id="fullConfigWithCollectionExpression"
|
||||
collection-name-expression="headers.collectionName"
|
||||
mongo-template="mongoDbTemplate"
|
||||
mongo-converter="mongoConverter"/>
|
||||
collection-name-expression="headers.collectionName"
|
||||
mongo-template="mongoDbTemplate"
|
||||
mongo-converter="mongoConverter"/>
|
||||
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests.TestMongoConverter">
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.MongoDbContainerTest.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
</bean>
|
||||
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests.TestMongoConverter">
|
||||
<bean id="mongoConverter" class="org.springframework.integration.mongodb.MongoDbContainerTest.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2020 the original author or authors.
|
||||
* Copyright 2016-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,22 +17,24 @@
|
||||
package org.springframework.integration.mongodb.dsl;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||
import org.springframework.data.mongodb.ReactiveMongoDatabaseFactory;
|
||||
import org.springframework.data.mongodb.core.BulkOperations;
|
||||
import org.springframework.data.mongodb.core.MongoOperations;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
@@ -46,26 +48,36 @@ import org.springframework.integration.config.EnableIntegration;
|
||||
import org.springframework.integration.dsl.IntegrationFlow;
|
||||
import org.springframework.integration.dsl.MessageChannels;
|
||||
import org.springframework.integration.handler.ReplyRequiredException;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
import org.springframework.integration.mongodb.outbound.MessageCollectionCallback;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
/**
|
||||
* @author Xavier Padro
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class MongoDbTests extends MongoDbAvailableTests {
|
||||
class MongoDbTests implements MongoDbContainerTest {
|
||||
|
||||
static MongoDatabaseFactory MONGO_DATABASE_FACTORY;
|
||||
|
||||
@BeforeAll
|
||||
static void prepareMongoConnection() {
|
||||
MONGO_DATABASE_FACTORY = MongoDbContainerTest.createMongoDbFactory();
|
||||
REACTIVE_MONGO_DATABASE_FACTORY = MongoDbContainerTest.createReactiveMongoDbFactory();
|
||||
}
|
||||
|
||||
static ReactiveMongoDatabaseFactory REACTIVE_MONGO_DATABASE_FACTORY;
|
||||
|
||||
private static final String COLLECTION_NAME = "data";
|
||||
|
||||
@@ -107,19 +119,18 @@ public class MongoDbTests extends MongoDbAvailableTests {
|
||||
@Autowired
|
||||
private MongoOperations mongoTemplate;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
createPersons();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void cleanUp() {
|
||||
mongoTemplate.dropCollection(COLLECTION_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testGatewayWithSingleQuery() {
|
||||
void testGatewayWithSingleQuery() {
|
||||
gatewaySingleQueryFlow.send(MessageBuilder
|
||||
.withPayload("Xavi")
|
||||
.setHeader("collection", "data")
|
||||
@@ -133,8 +144,7 @@ public class MongoDbTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testGatewayWithSingleQueryWithTemplate() {
|
||||
void testGatewayWithSingleQueryWithTemplate() {
|
||||
gatewaySingleQueryWithTemplateFlow.send(MessageBuilder.withPayload("Xavi").build());
|
||||
|
||||
Message<?> result = this.getResultChannel.receive(10_000);
|
||||
@@ -145,8 +155,7 @@ public class MongoDbTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testGatewayWithSingleQueryExpression() {
|
||||
void testGatewayWithSingleQueryExpression() {
|
||||
gatewaySingleQueryExpressionFlow.send(MessageBuilder
|
||||
.withPayload("")
|
||||
.setHeader("query", "{'name' : 'Artem'}")
|
||||
@@ -159,20 +168,17 @@ public class MongoDbTests extends MongoDbAvailableTests {
|
||||
assertThat(retrievedPerson.getName()).isEqualTo("Artem");
|
||||
}
|
||||
|
||||
@Test(expected = ReplyRequiredException.class)
|
||||
@MongoDbAvailable
|
||||
public void testGatewayWithSingleQueryExpressionNoPersonFound() {
|
||||
gatewaySingleQueryExpressionFlow.send(MessageBuilder
|
||||
@Test
|
||||
void testGatewayWithSingleQueryExpressionNoPersonFound() {
|
||||
assertThatThrownBy(() -> gatewaySingleQueryExpressionFlow.send(MessageBuilder
|
||||
.withPayload("")
|
||||
.setHeader("query", "{'name' : 'NonExisting'}")
|
||||
.build());
|
||||
|
||||
this.getResultChannel.receive(10_000);
|
||||
.build()))
|
||||
.isInstanceOf(ReplyRequiredException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testGatewayWithQueryExpression() {
|
||||
void testGatewayWithQueryExpression() {
|
||||
gatewayQueryExpressionFlow.send(MessageBuilder
|
||||
.withPayload("")
|
||||
.setHeader("query", "{}")
|
||||
@@ -182,12 +188,11 @@ public class MongoDbTests extends MongoDbAvailableTests {
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
List<Person> retrievedPersons = getPersons(result);
|
||||
assertThat(retrievedPersons.size()).isEqualTo(4);
|
||||
assertThat(retrievedPersons).hasSize(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testGatewayWithQueryExpressionAndLimit() {
|
||||
void testGatewayWithQueryExpressionAndLimit() {
|
||||
gatewayQueryExpressionLimitFlow.send(MessageBuilder
|
||||
.withPayload("")
|
||||
.setHeader("query", "{}")
|
||||
@@ -197,12 +202,11 @@ public class MongoDbTests extends MongoDbAvailableTests {
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
List<Person> retrievedPersons = getPersons(result);
|
||||
assertThat(retrievedPersons.size()).isEqualTo(2);
|
||||
assertThat(retrievedPersons).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testGatewayWithQueryFunction() {
|
||||
void testGatewayWithQueryFunction() {
|
||||
gatewayQueryFunctionFlow.send(MessageBuilder
|
||||
.withPayload("Gary")
|
||||
.setHeader("collection", "data")
|
||||
@@ -216,8 +220,7 @@ public class MongoDbTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testGatewayWithCollectionNameFunction() {
|
||||
void testGatewayWithCollectionNameFunction() {
|
||||
gatewayCollectionNameFunctionFlow.send(MessageBuilder
|
||||
.withPayload("data")
|
||||
.setHeader("query", "{'name' : 'Gary'}")
|
||||
@@ -231,8 +234,7 @@ public class MongoDbTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testGatewayWithCollectionCallback() {
|
||||
void testGatewayWithCollectionCallback() {
|
||||
gatewayCollectionCallbackFlow.send(MessageBuilder
|
||||
.withPayload("")
|
||||
.build());
|
||||
@@ -252,10 +254,10 @@ public class MongoDbTests extends MongoDbAvailableTests {
|
||||
private void createPersons() {
|
||||
BulkOperations bulkOperations = this.mongoTemplate.bulkOps(BulkOperations.BulkMode.ORDERED, COLLECTION_NAME);
|
||||
bulkOperations.insert(Arrays.asList(
|
||||
this.createPerson("Artem"),
|
||||
this.createPerson("Gary"),
|
||||
this.createPerson("Oleg"),
|
||||
this.createPerson("Xavi")));
|
||||
MongoDbContainerTest.createPerson("Artem"),
|
||||
MongoDbContainerTest.createPerson("Gary"),
|
||||
MongoDbContainerTest.createPerson("Oleg"),
|
||||
MongoDbContainerTest.createPerson("Xavi")));
|
||||
bulkOperations.execute();
|
||||
}
|
||||
|
||||
@@ -264,9 +266,8 @@ public class MongoDbTests extends MongoDbAvailableTests {
|
||||
private MessageChannel reactiveStoreInput;
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testReactiveMongoDbMessageHandler() {
|
||||
this.reactiveStoreInput.send(MessageBuilder.withPayload(createPerson("Bob")).build());
|
||||
void testReactiveMongoDbMessageHandler() {
|
||||
this.reactiveStoreInput.send(MessageBuilder.withPayload(MongoDbContainerTest.createPerson("Bob")).build());
|
||||
|
||||
ReactiveMongoTemplate reactiveMongoTemplate = new ReactiveMongoTemplate(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
|
||||
@@ -425,7 +426,6 @@ public class MongoDbTests extends MongoDbAvailableTests {
|
||||
.handle(MongoDb.reactiveOutboundChannelAdapter(REACTIVE_MONGO_DATABASE_FACTORY));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2021 the original author or authors.
|
||||
* Copyright 2007-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,7 +26,8 @@ import static org.mockito.Mockito.verify;
|
||||
import java.util.List;
|
||||
|
||||
import org.bson.conversions.Bson;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -39,8 +40,7 @@ import org.springframework.data.mongodb.core.query.BasicQuery;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
|
||||
@@ -50,81 +50,86 @@ import com.mongodb.BasicDBObject;
|
||||
* @author Gary Russell
|
||||
* @author Yaron Yamin
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
* @since 2.2
|
||||
*
|
||||
*/
|
||||
public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
class MongoDbMessageSourceTests implements MongoDbContainerTest {
|
||||
|
||||
static MongoDatabaseFactory MONGO_DATABASE_FACTORY;
|
||||
|
||||
@BeforeAll
|
||||
static void prepareMongoConnection() {
|
||||
MONGO_DATABASE_FACTORY = MongoDbContainerTest.createMongoDbFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNullMongoDBFactory() {
|
||||
void withNullMongoDBFactory() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new MongoDbMessageSource((MongoDatabaseFactory) null, mock(Expression.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNullMongoTemplate() {
|
||||
void withNullMongoTemplate() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new MongoDbMessageSource((MongoOperations) null, mock(Expression.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNullQueryExpression() {
|
||||
void withNullQueryExpression() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new MongoDbMessageSource(mock(MongoDatabaseFactory.class), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateSuccessfulQueryWithSingleElementIfOneInListAsDbObject() {
|
||||
MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory();
|
||||
void validateSuccessfulQueryWithSingleElementIfOneInListAsDbObject() {
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY);
|
||||
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
template.save(this.createPerson(), "data");
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
template.save(MongoDbContainerTest.createPerson(), "data");
|
||||
|
||||
Expression queryExpression = new LiteralExpression("{'name' : 'Oleg'}");
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(MONGO_DATABASE_FACTORY, queryExpression);
|
||||
messageSource.setBeanFactory(mock(BeanFactory.class));
|
||||
messageSource.afterPropertiesSet();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<BasicDBObject> results = ((List<BasicDBObject>) messageSource.receive().getPayload());
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
assertThat(results).hasSize(1);
|
||||
BasicDBObject resultObject = results.get(0);
|
||||
|
||||
assertThat(resultObject.get("name")).isEqualTo("Oleg");
|
||||
assertThat(resultObject).containsEntry("name", "Oleg");
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateSuccessfulQueryWithSingleElementIfOneInList() {
|
||||
MongoDatabaseFactory mongoDbFactory = prepareMongoFactory();
|
||||
void validateSuccessfulQueryWithSingleElementIfOneInList() {
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY);
|
||||
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
template.save(this.createPerson(), "data");
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
template.save(MongoDbContainerTest.createPerson(), "data");
|
||||
|
||||
Expression queryExpression = new LiteralExpression("{'name' : 'Oleg'}");
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(MONGO_DATABASE_FACTORY, queryExpression);
|
||||
messageSource.setEntityClass(Object.class);
|
||||
messageSource.setBeanFactory(mock(BeanFactory.class));
|
||||
messageSource.afterPropertiesSet();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Person> results = ((List<Person>) messageSource.receive().getPayload());
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
assertThat(results).hasSize(1);
|
||||
Person person = results.get(0);
|
||||
assertThat(person.getName()).isEqualTo("Oleg");
|
||||
assertThat(person.getAddress().getState()).isEqualTo("PA");
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateSuccessfulQueryWithSingleElementIfOneInListAndSingleResult() {
|
||||
MongoDatabaseFactory mongoDbFactory = prepareMongoFactory();
|
||||
void validateSuccessfulQueryWithSingleElementIfOneInListAndSingleResult() {
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY);
|
||||
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
template.save(this.createPerson(), "data");
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
template.save(MongoDbContainerTest.createPerson(), "data");
|
||||
|
||||
Expression queryExpression = new LiteralExpression("{'name' : 'Oleg'}");
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(MONGO_DATABASE_FACTORY, queryExpression);
|
||||
messageSource.setEntityClass(Object.class);
|
||||
messageSource.setExpectSingleResult(true);
|
||||
messageSource.setBeanFactory(mock(BeanFactory.class));
|
||||
@@ -135,17 +140,15 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
assertThat(person.getAddress().getState()).isEqualTo("PA");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateSuccessfulSubObjectQueryWithSingleElementIfOneInList() {
|
||||
MongoDatabaseFactory mongoDbFactory = prepareMongoFactory();
|
||||
void validateSuccessfulSubObjectQueryWithSingleElementIfOneInList() {
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY);
|
||||
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
template.save(this.createPerson(), "data");
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
template.save(MongoDbContainerTest.createPerson(), "data");
|
||||
|
||||
Expression queryExpression = new LiteralExpression("{'address.state' : 'PA'}");
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(MONGO_DATABASE_FACTORY, queryExpression);
|
||||
messageSource.setEntityClass(Object.class);
|
||||
messageSource.setBeanFactory(mock(BeanFactory.class));
|
||||
messageSource.afterPropertiesSet();
|
||||
@@ -157,38 +160,35 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateSuccessfulQueryWithMultipleElements() {
|
||||
void validateSuccessfulQueryWithMultipleElements() {
|
||||
List<Person> persons = queryMultipleElements(new LiteralExpression("{'address.state' : 'PA'}"));
|
||||
assertThat(persons.size()).isEqualTo(3);
|
||||
assertThat(persons).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateSuccessfulStringQueryExpressionWithMultipleElements() {
|
||||
void validateSuccessfulStringQueryExpressionWithMultipleElements() {
|
||||
List<Person> persons = queryMultipleElements(new SpelExpressionParser()
|
||||
.parseExpression("\"{'address.state' : 'PA'}\""));
|
||||
assertThat(persons.size()).isEqualTo(3);
|
||||
assertThat(persons).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateSuccessfulBasicQueryExpressionWithMultipleElements() {
|
||||
void validateSuccessfulBasicQueryExpressionWithMultipleElements() {
|
||||
List<Person> persons = queryMultipleElements(new SpelExpressionParser()
|
||||
.parseExpression("new BasicQuery(\"{'address.state' : 'PA'}\").limit(2)"));
|
||||
assertThat(persons.size()).isEqualTo(2);
|
||||
assertThat(persons).hasSize(2);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Person> queryMultipleElements(Expression queryExpression) {
|
||||
MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory();
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY);
|
||||
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
template.save(this.createPerson("Manny"), "data");
|
||||
template.save(this.createPerson("Moe"), "data");
|
||||
template.save(this.createPerson("Jack"), "data");
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
template.save(MongoDbContainerTest.createPerson("Manny"), "data");
|
||||
template.save(MongoDbContainerTest.createPerson("Moe"), "data");
|
||||
template.save(MongoDbContainerTest.createPerson("Jack"), "data");
|
||||
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(MONGO_DATABASE_FACTORY, queryExpression);
|
||||
messageSource.setBeanFactory(mock(BeanFactory.class));
|
||||
messageSource.afterPropertiesSet();
|
||||
|
||||
@@ -196,18 +196,17 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateSuccessfulQueryWithNullReturn() {
|
||||
void validateSuccessfulQueryWithNullReturn() {
|
||||
|
||||
MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory();
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY);
|
||||
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
template.save(this.createPerson("Manny"), "data");
|
||||
template.save(this.createPerson("Moe"), "data");
|
||||
template.save(this.createPerson("Jack"), "data");
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
template.save(MongoDbContainerTest.createPerson("Manny"), "data");
|
||||
template.save(MongoDbContainerTest.createPerson("Moe"), "data");
|
||||
template.save(MongoDbContainerTest.createPerson("Jack"), "data");
|
||||
|
||||
Expression queryExpression = new LiteralExpression("{'address.state' : 'NJ'}");
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(MONGO_DATABASE_FACTORY, queryExpression);
|
||||
messageSource.setBeanFactory(mock(BeanFactory.class));
|
||||
messageSource.afterPropertiesSet();
|
||||
assertThat(messageSource.receive()).isNull();
|
||||
@@ -215,19 +214,18 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateSuccessfulQueryWithCustomConverter() {
|
||||
void validateSuccessfulQueryWithCustomConverter() {
|
||||
|
||||
MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory();
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY);
|
||||
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
template.save(this.createPerson("Manny"), "data");
|
||||
template.save(this.createPerson("Moe"), "data");
|
||||
template.save(this.createPerson("Jack"), "data");
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
template.save(MongoDbContainerTest.createPerson("Manny"), "data");
|
||||
template.save(MongoDbContainerTest.createPerson("Moe"), "data");
|
||||
template.save(MongoDbContainerTest.createPerson("Jack"), "data");
|
||||
|
||||
Expression queryExpression = new LiteralExpression("{'address.state' : 'PA'}");
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
|
||||
MappingMongoConverter converter = new TestMongoConverter(mongoDbFactory, new MongoMappingContext());
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(MONGO_DATABASE_FACTORY, queryExpression);
|
||||
MappingMongoConverter converter = new TestMongoConverter(MONGO_DATABASE_FACTORY, new MongoMappingContext());
|
||||
messageSource.setBeanFactory(mock(BeanFactory.class));
|
||||
converter.afterPropertiesSet();
|
||||
converter = spy(converter);
|
||||
@@ -235,30 +233,29 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
messageSource.afterPropertiesSet();
|
||||
|
||||
List<Person> persons = (List<Person>) messageSource.receive().getPayload();
|
||||
assertThat(persons.size()).isEqualTo(3);
|
||||
assertThat(persons).hasSize(3);
|
||||
verify(converter, times(3)).read((Class<Person>) Mockito.any(), Mockito.any(Bson.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateSuccessfulQueryWithMongoTemplateAndUpdate() {
|
||||
MongoDatabaseFactory mongoDbFactory = prepareMongoFactory();
|
||||
MappingMongoConverter converter = new TestMongoConverter(mongoDbFactory, new MongoMappingContext());
|
||||
void validateSuccessfulQueryWithMongoTemplateAndUpdate() {
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY);
|
||||
MappingMongoConverter converter = new TestMongoConverter(MONGO_DATABASE_FACTORY, new MongoMappingContext());
|
||||
converter.afterPropertiesSet();
|
||||
converter = spy(converter);
|
||||
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory, converter);
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY, converter);
|
||||
Expression queryExpression = new LiteralExpression("{'address.state' : 'PA'}");
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(template, queryExpression);
|
||||
messageSource.setBeanFactory(mock(BeanFactory.class));
|
||||
messageSource.setUpdateExpression(new LiteralExpression("{ $set: {'address.state' : 'NJ'} }"));
|
||||
messageSource.afterPropertiesSet();
|
||||
|
||||
MongoTemplate writingTemplate = new MongoTemplate(mongoDbFactory, converter);
|
||||
writingTemplate.save(createPerson("Manny"), "data");
|
||||
writingTemplate.save(createPerson("Moe"), "data");
|
||||
writingTemplate.save(createPerson("Jack"), "data");
|
||||
MongoTemplate writingTemplate = new MongoTemplate(MONGO_DATABASE_FACTORY, converter);
|
||||
writingTemplate.save(MongoDbContainerTest.createPerson("Manny"), "data");
|
||||
writingTemplate.save(MongoDbContainerTest.createPerson("Moe"), "data");
|
||||
writingTemplate.save(MongoDbContainerTest.createPerson("Jack"), "data");
|
||||
|
||||
List<Person> persons = (List<Person>) messageSource.receive().getPayload();
|
||||
assertThat(persons).hasSize(3);
|
||||
@@ -271,17 +268,16 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validatePipelineInModifyOut() {
|
||||
void validatePipelineInModifyOut() {
|
||||
|
||||
MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory();
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY);
|
||||
|
||||
MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
|
||||
template.save(BasicDBObject.parse("{'name' : 'Manny', 'id' : 1}"), "data");
|
||||
|
||||
Expression queryExpression = new LiteralExpression("{'name' : 'Manny'}");
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
|
||||
MongoDbMessageSource messageSource = new MongoDbMessageSource(MONGO_DATABASE_FACTORY, queryExpression);
|
||||
messageSource.setExpectSingleResult(true);
|
||||
messageSource.setBeanFactory(mock(BeanFactory.class));
|
||||
messageSource.afterPropertiesSet();
|
||||
@@ -290,7 +286,7 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
result.put("company", "PepBoys");
|
||||
template.save(result, "data");
|
||||
result = (BasicDBObject) messageSource.receive().getPayload();
|
||||
assertThat(result.get("_id")).isEqualTo(id);
|
||||
assertThat(result).containsEntry("_id", id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,9 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bson.conversions.Bson;
|
||||
import org.junit.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -48,10 +50,10 @@ import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.integration.channel.FluxMessageChannel;
|
||||
import org.springframework.integration.config.EnableIntegration;
|
||||
import org.springframework.integration.dsl.IntegrationFlow;
|
||||
import org.springframework.integration.dsl.PollerSpec;
|
||||
import org.springframework.integration.dsl.Pollers;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
import org.springframework.integration.mongodb.dsl.MongoDb;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -61,63 +63,70 @@ import reactor.test.StepVerifier;
|
||||
/**
|
||||
* @author David Turanski
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
* @since 5.3
|
||||
*/
|
||||
public class ReactiveMongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
class ReactiveMongoDbMessageSourceTests implements MongoDbContainerTest {
|
||||
|
||||
static ReactiveMongoDatabaseFactory REACTIVE_MONGO_DATABASE_FACTORY;
|
||||
|
||||
@BeforeAll
|
||||
static void prepareMongoConnection() {
|
||||
REACTIVE_MONGO_DATABASE_FACTORY = MongoDbContainerTest.createReactiveMongoDbFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNullMongoDBFactory() {
|
||||
void withNullMongoDBFactory() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReactiveMongoDbMessageSource((ReactiveMongoDatabaseFactory) null,
|
||||
mock(Expression.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNullMongoTemplate() {
|
||||
void withNullMongoTemplate() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReactiveMongoDbMessageSource((ReactiveMongoTemplate) null,
|
||||
mock(Expression.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withNullQueryExpression() {
|
||||
void withNullQueryExpression() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReactiveMongoDbMessageSource(mock(ReactiveMongoDatabaseFactory.class),
|
||||
null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
@SuppressWarnings("unchecked")
|
||||
public void validateSuccessfulQueryWithSingleElementFluxOfDbObject() {
|
||||
ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory = prepareReactiveMongoFactory();
|
||||
void validateSuccessfulQueryWithSingleElementFluxOfDbObject() {
|
||||
MongoDbContainerTest.prepareReactiveMongoData(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
|
||||
ReactiveMongoTemplate template = new ReactiveMongoTemplate(reactiveMongoDatabaseFactory);
|
||||
waitFor(template.save(createPerson(), "data"));
|
||||
ReactiveMongoTemplate template = new ReactiveMongoTemplate(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
waitFor(template.save(MongoDbContainerTest.createPerson(), "data"));
|
||||
|
||||
Expression queryExpression = new LiteralExpression("{'name' : 'Oleg'}");
|
||||
ReactiveMongoDbMessageSource messageSource = new ReactiveMongoDbMessageSource(reactiveMongoDatabaseFactory,
|
||||
ReactiveMongoDbMessageSource messageSource = new ReactiveMongoDbMessageSource(REACTIVE_MONGO_DATABASE_FACTORY,
|
||||
queryExpression);
|
||||
messageSource.setBeanFactory(mock(BeanFactory.class));
|
||||
messageSource.afterPropertiesSet();
|
||||
|
||||
StepVerifier.create((Flux<BasicDBObject>) messageSource.receive().getPayload())
|
||||
.assertNext(basicDBObject -> assertThat(basicDBObject.get("name")).isEqualTo("Oleg"))
|
||||
.assertNext(basicDBObject -> assertThat(basicDBObject).containsEntry("name", "Oleg"))
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
@SuppressWarnings("unchecked")
|
||||
public void validateSuccessfulQueryWithSingleElementFluxOfPerson() {
|
||||
ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory = prepareReactiveMongoFactory();
|
||||
void validateSuccessfulQueryWithSingleElementFluxOfPerson() {
|
||||
|
||||
ReactiveMongoTemplate template = new ReactiveMongoTemplate(reactiveMongoDatabaseFactory);
|
||||
waitFor(template.save(createPerson(), "data"));
|
||||
MongoDbContainerTest.prepareReactiveMongoData(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
|
||||
ReactiveMongoTemplate template = new ReactiveMongoTemplate(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
waitFor(template.save(MongoDbContainerTest.createPerson(), "data"));
|
||||
|
||||
Expression queryExpression = new LiteralExpression("{'name' : 'Oleg'}");
|
||||
ReactiveMongoDbMessageSource messageSource = new ReactiveMongoDbMessageSource(reactiveMongoDatabaseFactory,
|
||||
ReactiveMongoDbMessageSource messageSource = new ReactiveMongoDbMessageSource(REACTIVE_MONGO_DATABASE_FACTORY,
|
||||
queryExpression);
|
||||
messageSource.setBeanFactory(mock(BeanFactory.class));
|
||||
messageSource.afterPropertiesSet();
|
||||
@@ -129,8 +138,7 @@ public class ReactiveMongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateSuccessfulQueryWithMultipleElements() {
|
||||
void validateSuccessfulQueryWithMultipleElements() {
|
||||
final List<String> names = new ArrayList<>(Arrays.asList("Manny", "Moe", "Jack"));
|
||||
StepVerifier.create(queryMultipleElements(new LiteralExpression("{'address.state' : 'PA'}")))
|
||||
.expectNextMatches(person -> {
|
||||
@@ -149,34 +157,33 @@ public class ReactiveMongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateSuccessfulQueryWithEmptyReturn() {
|
||||
void validateSuccessfulQueryWithEmptyReturn() {
|
||||
StepVerifier.create(queryMultipleElements(new LiteralExpression("{'address.state' : 'NJ'}")))
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
@SuppressWarnings("unchecked")
|
||||
public void validateSuccessfulQueryWithCustomConverter() {
|
||||
MappingMongoConverter converter = new ReactiveTestMongoConverter(prepareReactiveMongoFactory(),
|
||||
void validateSuccessfulQueryWithCustomConverter() {
|
||||
MongoDbContainerTest.prepareReactiveMongoData(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
MappingMongoConverter converter = new ReactiveTestMongoConverter(
|
||||
REACTIVE_MONGO_DATABASE_FACTORY,
|
||||
new MongoMappingContext());
|
||||
converter.afterPropertiesSet();
|
||||
converter = spy(converter);
|
||||
StepVerifier.create(queryMultipleElements(new LiteralExpression("{'address.state' : 'PA'}"),
|
||||
Optional.of(converter))).expectNextCount(3)
|
||||
Optional.of(converter))).expectNextCount(3)
|
||||
.verifyComplete();
|
||||
|
||||
verify(converter, times(3)).read((Class<Person>) Mockito.any(), Mockito.any(Bson.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateWithConfiguredPollerFlow() {
|
||||
ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory = prepareReactiveMongoFactory();
|
||||
ReactiveMongoTemplate template = new ReactiveMongoTemplate(reactiveMongoDatabaseFactory);
|
||||
void validateWithConfiguredPollerFlow() {
|
||||
MongoDbContainerTest.prepareReactiveMongoData(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
ReactiveMongoTemplate template = new ReactiveMongoTemplate(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
|
||||
waitFor(template.save(createPerson(), "data"));
|
||||
waitFor(template.save(MongoDbContainerTest.createPerson(), "data"));
|
||||
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(TestContext.class);
|
||||
FluxMessageChannel output = context.getBean(FluxMessageChannel.class);
|
||||
@@ -191,16 +198,15 @@ public class ReactiveMongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
@SuppressWarnings("unchecked")
|
||||
public void validatePipelineInModifyOut() {
|
||||
ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory = prepareReactiveMongoFactory();
|
||||
ReactiveMongoTemplate template = new ReactiveMongoTemplate(reactiveMongoDatabaseFactory);
|
||||
void validatePipelineInModifyOut() {
|
||||
MongoDbContainerTest.prepareReactiveMongoData(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
ReactiveMongoTemplate template = new ReactiveMongoTemplate(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
|
||||
waitFor(template.save(BasicDBObject.parse("{'name' : 'Manny', 'id' : 1}"), "data"));
|
||||
|
||||
Expression queryExpression = new LiteralExpression("{'name' : 'Manny'}");
|
||||
ReactiveMongoDbMessageSource messageSource = new ReactiveMongoDbMessageSource(reactiveMongoDatabaseFactory,
|
||||
ReactiveMongoDbMessageSource messageSource = new ReactiveMongoDbMessageSource(REACTIVE_MONGO_DATABASE_FACTORY,
|
||||
queryExpression);
|
||||
messageSource.setExpectSingleResult(true);
|
||||
messageSource.setBeanFactory(mock(BeanFactory.class));
|
||||
@@ -210,7 +216,7 @@ public class ReactiveMongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
result.put("company", "PepBoys");
|
||||
waitFor(template.save(result, "data"));
|
||||
result = waitFor((Mono<BasicDBObject>) messageSource.receive().getPayload());
|
||||
assertThat(result.get("_id")).isEqualTo(id);
|
||||
assertThat(result).containsEntry("_id", id);
|
||||
}
|
||||
|
||||
private Flux<Person> queryMultipleElements(Expression queryExpression) {
|
||||
@@ -219,14 +225,14 @@ public class ReactiveMongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Flux<Person> queryMultipleElements(Expression queryExpression, Optional<MappingMongoConverter> converter) {
|
||||
ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory = this.prepareReactiveMongoFactory();
|
||||
MongoDbContainerTest.prepareReactiveMongoData(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
|
||||
ReactiveMongoTemplate template = new ReactiveMongoTemplate(reactiveMongoDatabaseFactory);
|
||||
waitFor(template.save(createPerson("Manny"), "data"));
|
||||
waitFor(template.save(createPerson("Moe"), "data"));
|
||||
waitFor(template.save(createPerson("Jack"), "data"));
|
||||
ReactiveMongoTemplate template = new ReactiveMongoTemplate(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
waitFor(template.save(MongoDbContainerTest.createPerson("Manny"), "data"));
|
||||
waitFor(template.save(MongoDbContainerTest.createPerson("Moe"), "data"));
|
||||
waitFor(template.save(MongoDbContainerTest.createPerson("Jack"), "data"));
|
||||
|
||||
ReactiveMongoDbMessageSource messageSource = new ReactiveMongoDbMessageSource(reactiveMongoDatabaseFactory,
|
||||
ReactiveMongoDbMessageSource messageSource = new ReactiveMongoDbMessageSource(REACTIVE_MONGO_DATABASE_FACTORY,
|
||||
queryExpression);
|
||||
messageSource.setBeanFactory(mock(BeanFactory.class));
|
||||
messageSource.setEntityClass(Person.class);
|
||||
@@ -248,15 +254,20 @@ public class ReactiveMongoDbMessageSourceTests extends MongoDbAvailableTests {
|
||||
public IntegrationFlow pollingFlow() {
|
||||
return IntegrationFlow
|
||||
.from(MongoDb.reactiveInboundChannelAdapter(
|
||||
REACTIVE_MONGO_DATABASE_FACTORY, "{'name' : 'Oleg'}")
|
||||
REACTIVE_MONGO_DATABASE_FACTORY, "{'name' : 'Oleg'}")
|
||||
.update(Update.update("name", "DONE"))
|
||||
.entityClass(Person.class),
|
||||
c -> c.poller(Pollers.fixedDelay(100)))
|
||||
c -> c.poller(pollOnceAfter100ms()))
|
||||
.split()
|
||||
.channel(c -> c.flux("output"))
|
||||
.get();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PollerSpec pollOnceAfter100ms() {
|
||||
return Pollers.fixedDelay(Duration.ofMinutes(5), Duration.ofMillis(100));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
* Copyright 2015-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,22 +18,30 @@ package org.springframework.integration.mongodb.metadata;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
|
||||
/**
|
||||
* @author Senthil Arumugam, Samiraj Panneer Selvam
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
* @since 4.2
|
||||
*
|
||||
*/
|
||||
public class MongoDbMetadataStoreTests extends MongoDbAvailableTests {
|
||||
class MongoDbMetadataStoreTests implements MongoDbContainerTest {
|
||||
|
||||
static MongoDatabaseFactory MONGO_DATABASE_FACTORY;
|
||||
|
||||
@BeforeAll
|
||||
static void prepareMongoConnection() {
|
||||
MONGO_DATABASE_FACTORY = MongoDbContainerTest.createMongoDbFactory();
|
||||
}
|
||||
|
||||
private static final String DEFAULT_COLLECTION_NAME = "metadataStore";
|
||||
|
||||
@@ -43,36 +51,33 @@ public class MongoDbMetadataStoreTests extends MongoDbAvailableTests {
|
||||
|
||||
private MongoDbMetadataStore store = null;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void configure() {
|
||||
final MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory(DEFAULT_COLLECTION_NAME);
|
||||
this.store = new MongoDbMetadataStore(mongoDbFactory);
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY, DEFAULT_COLLECTION_NAME);
|
||||
this.store = new MongoDbMetadataStore(MONGO_DATABASE_FACTORY);
|
||||
}
|
||||
|
||||
@MongoDbAvailable
|
||||
@Test
|
||||
public void testConfigureCustomCollection() {
|
||||
void testConfigureCustomCollection() {
|
||||
final String collectionName = "testMetadataStore";
|
||||
final MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory(collectionName);
|
||||
final MongoTemplate template = new MongoTemplate(mongoDbFactory);
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY, collectionName);
|
||||
final MongoTemplate template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
store = new MongoDbMetadataStore(template, collectionName);
|
||||
testBasics();
|
||||
}
|
||||
|
||||
@MongoDbAvailable
|
||||
@Test
|
||||
public void testConfigureFactory() {
|
||||
final MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory(DEFAULT_COLLECTION_NAME);
|
||||
store = new MongoDbMetadataStore(mongoDbFactory);
|
||||
void testConfigureFactory() {
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY, DEFAULT_COLLECTION_NAME);
|
||||
store = new MongoDbMetadataStore(MONGO_DATABASE_FACTORY);
|
||||
testBasics();
|
||||
}
|
||||
|
||||
@MongoDbAvailable
|
||||
@Test
|
||||
public void testConfigureFactorCustomCollection() {
|
||||
void testConfigureFactorCustomCollection() {
|
||||
final String collectionName = "testMetadataStore";
|
||||
final MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory(collectionName);
|
||||
store = new MongoDbMetadataStore(mongoDbFactory, collectionName);
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY, collectionName);
|
||||
store = new MongoDbMetadataStore(MONGO_DATABASE_FACTORY, collectionName);
|
||||
testBasics();
|
||||
}
|
||||
|
||||
@@ -88,14 +93,12 @@ public class MongoDbMetadataStoreTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testGetFromStore() {
|
||||
void testGetFromStore() {
|
||||
testBasics();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testPutIfAbsent() {
|
||||
void testPutIfAbsent() {
|
||||
String fileID = store.get(file1);
|
||||
assertThat(fileID).as("Get First time, Value must not exist").isNull();
|
||||
|
||||
@@ -103,16 +106,16 @@ public class MongoDbMetadataStoreTests extends MongoDbAvailableTests {
|
||||
assertThat(fileID).as("Insert First time, Value must return null").isNull();
|
||||
|
||||
fileID = store.putIfAbsent(file1, "56789");
|
||||
assertThat(fileID).as("Key Already Exists - Insertion Failed, ol value must be returned").isNotNull();
|
||||
assertThat(fileID).as("The Old Value must be equal to returned").isEqualTo(file1Id);
|
||||
assertThat(fileID)
|
||||
.as("Key Already Exists - Insertion Failed, ol value must be returned").isNotNull()
|
||||
.as("The Old Value must be equal to returned").isEqualTo(file1Id);
|
||||
|
||||
assertThat(store.get(file1)).as("The Old Value must return").isEqualTo(file1Id);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testRemove() {
|
||||
void testRemove() {
|
||||
String fileID = store.remove(file1);
|
||||
assertThat(fileID).isNull();
|
||||
|
||||
@@ -120,16 +123,16 @@ public class MongoDbMetadataStoreTests extends MongoDbAvailableTests {
|
||||
assertThat(fileID).isNull();
|
||||
|
||||
fileID = store.remove(file1);
|
||||
assertThat(fileID).isNotNull();
|
||||
assertThat(fileID).isEqualTo(file1Id);
|
||||
assertThat(fileID)
|
||||
.isNotNull()
|
||||
.isEqualTo(file1Id);
|
||||
|
||||
fileID = store.get(file1);
|
||||
assertThat(fileID).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testReplace() {
|
||||
void testReplace() {
|
||||
boolean removedValue = store.replace(file1, file1Id, "4567");
|
||||
assertThat(removedValue).isFalse();
|
||||
String fileID = store.get(file1);
|
||||
@@ -142,8 +145,9 @@ public class MongoDbMetadataStoreTests extends MongoDbAvailableTests {
|
||||
assertThat(removedValue).isTrue();
|
||||
|
||||
fileID = store.get(file1);
|
||||
assertThat(fileID).isNotNull();
|
||||
assertThat(fileID).isEqualTo("4567");
|
||||
assertThat(fileID)
|
||||
.isNotNull()
|
||||
.isEqualTo("4567");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<mongo:db-factory id="mongoDbFactory" dbname="test" />
|
||||
<bean id="mongoDbFactory" class="org.springframework.integration.mongodb.MongoDbContainerTest"
|
||||
factory-method="createMongoDbFactory"/>
|
||||
|
||||
<bean id="mongoDbTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
|
||||
<constructor-arg ref="mongoDbFactory" />
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
</bean>
|
||||
|
||||
<bean id="mongoConverter"
|
||||
class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory" />
|
||||
class="org.springframework.integration.mongodb.MongoDbContainerTest.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" />
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
|
||||
@@ -25,10 +25,9 @@ import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -42,24 +41,24 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.integration.expression.FunctionExpression;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
/**
|
||||
* @author Xavier Padro
|
||||
* @author Gary Rssell
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
class MongoDbOutboundGatewayTests implements MongoDbContainerTest {
|
||||
|
||||
private static final String COLLECTION_NAME = "data";
|
||||
|
||||
@@ -75,35 +74,33 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
private MongoConverter mongoConverter;
|
||||
|
||||
@Autowired
|
||||
private MongoDatabaseFactory mongoDbFactory;
|
||||
private MongoDatabaseFactory MONGO_DATABASE_FACTORY;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
BulkOperations bulkOperations = this.mongoTemplate.bulkOps(BulkOperations.BulkMode.ORDERED, COLLECTION_NAME);
|
||||
bulkOperations.insert(Arrays.asList(
|
||||
this.createPerson("Artem"),
|
||||
this.createPerson("Gary"),
|
||||
this.createPerson("Oleg"),
|
||||
this.createPerson("Xavi")));
|
||||
MongoDbContainerTest.createPerson("Artem"),
|
||||
MongoDbContainerTest.createPerson("Gary"),
|
||||
MongoDbContainerTest.createPerson("Oleg"),
|
||||
MongoDbContainerTest.createPerson("Xavi")));
|
||||
bulkOperations.execute();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void cleanUp() {
|
||||
mongoTemplate.dropCollection(COLLECTION_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testNoFactorySpecified() {
|
||||
void testNoFactorySpecified() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new MongoDbOutboundGateway((MongoDatabaseFactory) null))
|
||||
.withStackTraceContaining("MongoDbFactory translator must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testNoTemplateSpecified() {
|
||||
void testNoTemplateSpecified() {
|
||||
try {
|
||||
new MongoDbOutboundGateway((MongoTemplate) null);
|
||||
fail("Expected the test case to throw an IllegalArgumentException");
|
||||
@@ -114,8 +111,7 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testNoQuerySpecified() {
|
||||
void testNoQuerySpecified() {
|
||||
Message<String> message = MessageBuilder.withPayload("test").build();
|
||||
MongoDbOutboundGateway gateway = createGateway();
|
||||
|
||||
@@ -130,8 +126,7 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testListOfResultsWithQueryExpressionAndLimit() {
|
||||
void testListOfResultsWithQueryExpressionAndLimit() {
|
||||
Message<String> message = MessageBuilder.withPayload("").build();
|
||||
MongoDbOutboundGateway gateway = createGateway();
|
||||
gateway.setQueryExpression(
|
||||
@@ -141,12 +136,11 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
Object result = gateway.handleRequestMessage(message);
|
||||
|
||||
List<Person> persons = getPersonsFromResult(result);
|
||||
assertThat(persons.size()).isEqualTo(2);
|
||||
assertThat(persons).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testListOfResultsWithQueryFunction() {
|
||||
void testListOfResultsWithQueryFunction() {
|
||||
Message<String> message = MessageBuilder.withPayload("Xavi").build();
|
||||
MongoDbOutboundGateway gateway = createGateway();
|
||||
Function<Message<String>, Query> queryFunction =
|
||||
@@ -165,9 +159,8 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testListOfResultsWithQueryExpressionNotInitialized() {
|
||||
MongoDbOutboundGateway gateway = new MongoDbOutboundGateway(mongoDbFactory);
|
||||
void testListOfResultsWithQueryExpressionNotInitialized() {
|
||||
MongoDbOutboundGateway gateway = new MongoDbOutboundGateway(MONGO_DATABASE_FACTORY);
|
||||
gateway.setBeanFactory(beanFactory);
|
||||
gateway.setMongoConverter(mongoConverter);
|
||||
try {
|
||||
@@ -180,8 +173,7 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testListOfResultsWithQueryExpression() {
|
||||
void testListOfResultsWithQueryExpression() {
|
||||
Message<String> message = MessageBuilder.withPayload("{}").build();
|
||||
MongoDbOutboundGateway gateway = createGateway();
|
||||
gateway.setEntityClass(Person.class);
|
||||
@@ -191,12 +183,11 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
Object result = gateway.handleRequestMessage(message);
|
||||
|
||||
List<Person> persons = getPersonsFromResult(result);
|
||||
assertThat(persons.size()).isEqualTo(4);
|
||||
assertThat(persons).hasSize(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testListOfResultsWithQueryExpressionReturningOneResult() {
|
||||
void testListOfResultsWithQueryExpressionReturningOneResult() {
|
||||
Message<String> message = MessageBuilder.withPayload("{name : 'Xavi'}").build();
|
||||
MongoDbOutboundGateway gateway = createGateway();
|
||||
gateway.setEntityClass(Person.class);
|
||||
@@ -206,13 +197,12 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
Object result = gateway.handleRequestMessage(message);
|
||||
|
||||
List<Person> persons = getPersonsFromResult(result);
|
||||
assertThat(persons.size()).isEqualTo(1);
|
||||
assertThat(persons).hasSize(1);
|
||||
assertThat(persons.get(0).getName()).isEqualTo("Xavi");
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testSingleResultWithQueryExpressionAsString() {
|
||||
void testSingleResultWithQueryExpressionAsString() {
|
||||
Message<String> message = MessageBuilder.withPayload("{name : 'Artem'}").build();
|
||||
MongoDbOutboundGateway gateway = createGateway();
|
||||
gateway.setQueryExpression(PARSER.parseExpression("payload"));
|
||||
@@ -227,8 +217,7 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testSingleResultWithQueryExpressionAsQuery() {
|
||||
void testSingleResultWithQueryExpressionAsQuery() {
|
||||
Message<String> message = MessageBuilder.withPayload("").build();
|
||||
MongoDbOutboundGateway gateway = createGateway();
|
||||
gateway.setQueryExpression(PARSER.parseExpression("new BasicQuery('{''name'' : ''Gary''}')"));
|
||||
@@ -243,8 +232,7 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testSingleResultWithQueryExpressionAndNoEntityClass() {
|
||||
void testSingleResultWithQueryExpressionAndNoEntityClass() {
|
||||
Message<String> message = MessageBuilder.withPayload("").build();
|
||||
MongoDbOutboundGateway gateway = createGateway();
|
||||
gateway.setQueryExpression(new LiteralExpression("{name : 'Xavi'}"));
|
||||
@@ -254,13 +242,12 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
Object result = gateway.handleRequestMessage(message);
|
||||
|
||||
Document person = (Document) result;
|
||||
assertThat(person.get("name")).isEqualTo("Xavi");
|
||||
assertThat(person).containsEntry("name", "Xavi");
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithNullCollectionNameExpression() {
|
||||
MongoDbOutboundGateway gateway = new MongoDbOutboundGateway(mongoDbFactory);
|
||||
void testWithNullCollectionNameExpression() {
|
||||
MongoDbOutboundGateway gateway = new MongoDbOutboundGateway(MONGO_DATABASE_FACTORY);
|
||||
gateway.setBeanFactory(beanFactory);
|
||||
gateway.setQueryExpression(new LiteralExpression("{name : 'Xavi'}"));
|
||||
gateway.setExpectSingleResult(true);
|
||||
@@ -275,8 +262,7 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithCollectionNameExpressionSpecified() {
|
||||
void testWithCollectionNameExpressionSpecified() {
|
||||
Message<String> message = MessageBuilder.withPayload("").build();
|
||||
MongoDbOutboundGateway gateway = createGateway();
|
||||
gateway.setQueryExpression(new LiteralExpression("{name : 'Xavi'}"));
|
||||
@@ -294,8 +280,7 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithCollectionCallbackCount() {
|
||||
void testWithCollectionCallbackCount() {
|
||||
Message<String> message = MessageBuilder.withPayload("").build();
|
||||
MongoDbOutboundGateway gateway = createGateway();
|
||||
gateway.setEntityClass(Person.class);
|
||||
@@ -310,8 +295,7 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithCollectionCallbackFindOne() {
|
||||
void testWithCollectionCallbackFindOne() {
|
||||
Message<String> message = MessageBuilder.withPayload("Mike").build();
|
||||
MongoDbOutboundGateway gateway = createGateway();
|
||||
gateway.setEntityClass(Person.class);
|
||||
@@ -327,7 +311,7 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
gateway.handleRequestMessage(message);
|
||||
|
||||
List<Person> persons = this.mongoTemplate.find(new Query(), Person.class, COLLECTION_NAME);
|
||||
assertThat(persons.size()).isEqualTo(5);
|
||||
assertThat(persons).hasSize(5);
|
||||
assertThat(persons.stream().anyMatch(p -> p.getName().equals("Mike"))).isTrue();
|
||||
}
|
||||
|
||||
@@ -337,7 +321,7 @@ public class MongoDbOutboundGatewayTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
private MongoDbOutboundGateway createGateway() {
|
||||
MongoDbOutboundGateway gateway = new MongoDbOutboundGateway(mongoDbFactory);
|
||||
MongoDbOutboundGateway gateway = new MongoDbOutboundGateway(MONGO_DATABASE_FACTORY);
|
||||
gateway.setBeanFactory(beanFactory);
|
||||
gateway.setCollectionNameExpression(new LiteralExpression("data"));
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
|
||||
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/mongodb https://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd">
|
||||
|
||||
@@ -16,79 +14,80 @@
|
||||
</int:channel>
|
||||
|
||||
<int-mongodb:outbound-gateway id="gatewaySingleQuery"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
query="{name: 'Xavi'}"
|
||||
collection-name="data"
|
||||
expect-single-result="true"
|
||||
request-channel="in"
|
||||
reply-channel="out"
|
||||
entity-class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests$Person"/>
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
query="{name: 'Xavi'}"
|
||||
collection-name="data"
|
||||
expect-single-result="true"
|
||||
request-channel="in"
|
||||
reply-channel="out"
|
||||
entity-class="org.springframework.integration.mongodb.MongoDbContainerTest$Person"/>
|
||||
|
||||
<int-mongodb:outbound-gateway id="gatewayWithTemplate"
|
||||
mongo-template="mongoDbTemplate"
|
||||
query="{name: 'Xavi'}"
|
||||
collection-name="data"
|
||||
expect-single-result="true"
|
||||
request-channel="in"
|
||||
reply-channel="out"
|
||||
entity-class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests$Person"/>
|
||||
mongo-template="mongoDbTemplate"
|
||||
query="{name: 'Xavi'}"
|
||||
collection-name="data"
|
||||
expect-single-result="true"
|
||||
request-channel="in"
|
||||
reply-channel="out"
|
||||
entity-class="org.springframework.integration.mongodb.MongoDbContainerTest$Person"/>
|
||||
|
||||
<int-mongodb:outbound-gateway id="gatewaySingleQueryExpression"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
query-expression="headers.query"
|
||||
collection-name-expression="headers.collectionName"
|
||||
expect-single-result="true"
|
||||
request-channel="in"
|
||||
reply-channel="out"
|
||||
entity-class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests$Person"/>
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
query-expression="headers.query"
|
||||
collection-name-expression="headers.collectionName"
|
||||
expect-single-result="true"
|
||||
request-channel="in"
|
||||
reply-channel="out"
|
||||
entity-class="org.springframework.integration.mongodb.MongoDbContainerTest$Person"/>
|
||||
|
||||
<int-mongodb:outbound-gateway id="gatewayQueryExpression"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
query-expression="headers.query"
|
||||
collection-name-expression="headers.collectionName"
|
||||
expect-single-result="false"
|
||||
request-channel="in"
|
||||
reply-channel="out"
|
||||
entity-class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests$Person"/>
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
query-expression="headers.query"
|
||||
collection-name-expression="headers.collectionName"
|
||||
expect-single-result="false"
|
||||
request-channel="in"
|
||||
reply-channel="out"
|
||||
entity-class="org.springframework.integration.mongodb.MongoDbContainerTest$Person"/>
|
||||
|
||||
<int-mongodb:outbound-gateway id="gatewayQueryExpressionLimit"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
query-expression="new BasicQuery('{''address.state'' : ''PA''}').limit(2)"
|
||||
collection-name-expression="headers.collectionName"
|
||||
expect-single-result="false"
|
||||
request-channel="in"
|
||||
reply-channel="out"
|
||||
entity-class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests$Person"/>
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
query-expression="new BasicQuery('{''address.state'' : ''PA''}').limit(2)"
|
||||
collection-name-expression="headers.collectionName"
|
||||
expect-single-result="false"
|
||||
request-channel="in"
|
||||
reply-channel="out"
|
||||
entity-class="org.springframework.integration.mongodb.MongoDbContainerTest$Person"/>
|
||||
|
||||
<int-mongodb:outbound-gateway id="gatewayCollectionCallback"
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
collection-callback="countCollectionCallback"
|
||||
collection-name-expression="headers.collectionName"
|
||||
request-channel="in"
|
||||
reply-channel="out"
|
||||
entity-class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests$Person"/>
|
||||
mongodb-factory="mongoDbFactory"
|
||||
mongo-converter="mongoConverter"
|
||||
collection-callback="countCollectionCallback"
|
||||
collection-name-expression="headers.collectionName"
|
||||
request-channel="in"
|
||||
reply-channel="out"
|
||||
entity-class="org.springframework.integration.mongodb.MongoDbContainerTest$Person"/>
|
||||
|
||||
|
||||
<mongo:db-factory id="mongoDbFactory" dbname="test" />
|
||||
<bean id="mongoDbFactory" class="org.springframework.integration.mongodb.MongoDbContainerTest"
|
||||
factory-method="createMongoDbFactory"/>
|
||||
|
||||
<bean id="mongoDbTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
|
||||
<constructor-arg ref="mongoDbFactory" />
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
</bean>
|
||||
|
||||
<bean id="mongoConverter"
|
||||
class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory" />
|
||||
class="org.springframework.integration.mongodb.MongoDbContainerTest.TestMongoConverter">
|
||||
<constructor-arg ref="mongoDbFactory"/>
|
||||
<constructor-arg>
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" />
|
||||
<bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext"/>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="countCollectionCallback"
|
||||
class="org.springframework.integration.mongodb.rules.MongoDbAvailableTests$TestCollectionCallback" />
|
||||
class="org.springframework.integration.mongodb.MongoDbContainerTest$TestCollectionCallback"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2020 the original author or authors.
|
||||
* Copyright 2016-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,62 +20,67 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
/**
|
||||
* @author Xavier Padro
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class MongoDbOutboundGatewayXmlTests extends MongoDbAvailableTests {
|
||||
class MongoDbOutboundGatewayXmlTests implements MongoDbContainerTest {
|
||||
|
||||
static MongoDatabaseFactory MONGO_DATABASE_FACTORY;
|
||||
|
||||
@BeforeAll
|
||||
static void prepareMongoConnection() {
|
||||
MONGO_DATABASE_FACTORY = MongoDbContainerTest.createMongoDbFactory();
|
||||
}
|
||||
|
||||
private static final String COLLECTION_NAME = "data";
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory();
|
||||
MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory);
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY);
|
||||
MongoTemplate mongoTemplate = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
|
||||
mongoTemplate.save(this.createPerson("Artem"), COLLECTION_NAME);
|
||||
mongoTemplate.save(this.createPerson("Gary"), COLLECTION_NAME);
|
||||
mongoTemplate.save(this.createPerson("Oleg"), COLLECTION_NAME);
|
||||
mongoTemplate.save(this.createPerson("Xavi"), COLLECTION_NAME);
|
||||
mongoTemplate.save(MongoDbContainerTest.createPerson("Artem"), COLLECTION_NAME);
|
||||
mongoTemplate.save(MongoDbContainerTest.createPerson("Gary"), COLLECTION_NAME);
|
||||
mongoTemplate.save(MongoDbContainerTest.createPerson("Oleg"), COLLECTION_NAME);
|
||||
mongoTemplate.save(MongoDbContainerTest.createPerson("Xavi"), COLLECTION_NAME);
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void cleanUp() {
|
||||
MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory();
|
||||
MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory);
|
||||
MongoDbContainerTest.prepareMongoData(MONGO_DATABASE_FACTORY);
|
||||
MongoTemplate mongoTemplate = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
|
||||
mongoTemplate.dropCollection(COLLECTION_NAME);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testSingleQuery() {
|
||||
void testSingleQuery() {
|
||||
EventDrivenConsumer consumer = context.getBean("gatewaySingleQuery", EventDrivenConsumer.class);
|
||||
PollableChannel outChannel = context.getBean("out", PollableChannel.class);
|
||||
|
||||
@@ -88,8 +93,7 @@ public class MongoDbOutboundGatewayXmlTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testSingleQueryWithTemplate() {
|
||||
void testSingleQueryWithTemplate() {
|
||||
EventDrivenConsumer consumer = context.getBean("gatewayWithTemplate", EventDrivenConsumer.class);
|
||||
PollableChannel outChannel = context.getBean("out", PollableChannel.class);
|
||||
|
||||
@@ -102,8 +106,7 @@ public class MongoDbOutboundGatewayXmlTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testSingleQueryExpression() {
|
||||
void testSingleQueryExpression() {
|
||||
EventDrivenConsumer consumer = context.getBean("gatewaySingleQueryExpression", EventDrivenConsumer.class);
|
||||
PollableChannel outChannel = context.getBean("out", PollableChannel.class);
|
||||
|
||||
@@ -121,8 +124,7 @@ public class MongoDbOutboundGatewayXmlTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testQueryExpression() {
|
||||
void testQueryExpression() {
|
||||
EventDrivenConsumer consumer = context.getBean("gatewayQueryExpression", EventDrivenConsumer.class);
|
||||
PollableChannel outChannel = context.getBean("out", PollableChannel.class);
|
||||
|
||||
@@ -136,12 +138,11 @@ public class MongoDbOutboundGatewayXmlTests extends MongoDbAvailableTests {
|
||||
|
||||
Message<?> result = outChannel.receive(10000);
|
||||
List<Person> persons = getPersons(result);
|
||||
assertThat(persons.size()).isEqualTo(4);
|
||||
assertThat(persons).hasSize(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testQueryExpressionWithLimit() {
|
||||
void testQueryExpressionWithLimit() {
|
||||
EventDrivenConsumer consumer = context.getBean("gatewayQueryExpressionLimit", EventDrivenConsumer.class);
|
||||
PollableChannel outChannel = context.getBean("out", PollableChannel.class);
|
||||
|
||||
@@ -154,12 +155,11 @@ public class MongoDbOutboundGatewayXmlTests extends MongoDbAvailableTests {
|
||||
|
||||
Message<?> result = outChannel.receive(10000);
|
||||
List<Person> persons = getPersons(result);
|
||||
assertThat(persons.size()).isEqualTo(2);
|
||||
assertThat(persons).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testCollectionCallback() {
|
||||
void testCollectionCallback() {
|
||||
EventDrivenConsumer consumer = context.getBean("gatewayCollectionCallback", EventDrivenConsumer.class);
|
||||
PollableChannel outChannel = context.getBean("out", PollableChannel.class);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2020 the original author or authors.
|
||||
* Copyright 2007-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,8 +24,9 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.bson.conversions.Bson;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -37,8 +38,7 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||
import org.springframework.data.mongodb.core.query.BasicQuery;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
@@ -46,44 +46,45 @@ import org.springframework.messaging.Message;
|
||||
* @author Amol Nayak
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
public class MongoDbStoringMessageHandlerTests extends MongoDbAvailableTests {
|
||||
class MongoDbStoringMessageHandlerTests implements MongoDbContainerTest {
|
||||
|
||||
static MongoDatabaseFactory MONGO_DATABASE_FACTORY;
|
||||
|
||||
@BeforeAll
|
||||
static void prepareMongoConnection() {
|
||||
MONGO_DATABASE_FACTORY = MongoDbContainerTest.createMongoDbFactory();
|
||||
}
|
||||
|
||||
private MongoTemplate template;
|
||||
|
||||
private MongoDatabaseFactory mongoDbFactory;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
mongoDbFactory = prepareMongoFactory("foo");
|
||||
template = new MongoTemplate(mongoDbFactory);
|
||||
template = new MongoTemplate(MONGO_DATABASE_FACTORY);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void withNullMongoDBFactory() {
|
||||
void withNullMongoDBFactory() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new MongoDbStoringMessageHandler((MongoDatabaseFactory) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void withNullMongoTemplate() {
|
||||
void withNullMongoTemplate() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new MongoDbStoringMessageHandler((MongoOperations) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateMessageHandlingWithDefaultCollection() {
|
||||
void validateMessageHandlingWithDefaultCollection() {
|
||||
|
||||
MongoDbStoringMessageHandler handler = new MongoDbStoringMessageHandler(this.mongoDbFactory);
|
||||
MongoDbStoringMessageHandler handler = new MongoDbStoringMessageHandler(MONGO_DATABASE_FACTORY);
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).build();
|
||||
Message<Person> message = MessageBuilder.withPayload(MongoDbContainerTest.createPerson("Bob")).build();
|
||||
handler.handleMessage(message);
|
||||
|
||||
Query query = new BasicQuery("{'name' : 'Bob'}");
|
||||
@@ -94,14 +95,13 @@ public class MongoDbStoringMessageHandlerTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateMessageHandlingWithNamedCollection() {
|
||||
void validateMessageHandlingWithNamedCollection() {
|
||||
|
||||
MongoDbStoringMessageHandler handler = new MongoDbStoringMessageHandler(this.mongoDbFactory);
|
||||
MongoDbStoringMessageHandler handler = new MongoDbStoringMessageHandler(MONGO_DATABASE_FACTORY);
|
||||
handler.setCollectionNameExpression(new LiteralExpression("foo"));
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).build();
|
||||
Message<Person> message = MessageBuilder.withPayload(MongoDbContainerTest.createPerson("Bob")).build();
|
||||
handler.handleMessage(message);
|
||||
|
||||
Query query = new BasicQuery("{'name' : 'Bob'}");
|
||||
@@ -112,18 +112,17 @@ public class MongoDbStoringMessageHandlerTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateMessageHandlingWithMongoConverter() {
|
||||
void validateMessageHandlingWithMongoConverter() {
|
||||
|
||||
MongoDbStoringMessageHandler handler = new MongoDbStoringMessageHandler(this.mongoDbFactory);
|
||||
MongoDbStoringMessageHandler handler = new MongoDbStoringMessageHandler(MONGO_DATABASE_FACTORY);
|
||||
handler.setCollectionNameExpression(new LiteralExpression("foo"));
|
||||
MappingMongoConverter converter = new TestMongoConverter(mongoDbFactory, new MongoMappingContext());
|
||||
MappingMongoConverter converter = new TestMongoConverter(MONGO_DATABASE_FACTORY, new MongoMappingContext());
|
||||
converter.afterPropertiesSet();
|
||||
converter = spy(converter);
|
||||
handler.setMongoConverter(converter);
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).build();
|
||||
Message<Person> message = MessageBuilder.withPayload(MongoDbContainerTest.createPerson("Bob")).build();
|
||||
handler.handleMessage(message);
|
||||
|
||||
Query query = new BasicQuery("{'name' : 'Bob'}");
|
||||
@@ -135,19 +134,18 @@ public class MongoDbStoringMessageHandlerTests extends MongoDbAvailableTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateMessageHandlingWithMongoTemplate() {
|
||||
MappingMongoConverter converter = new TestMongoConverter(this.mongoDbFactory, new MongoMappingContext());
|
||||
void validateMessageHandlingWithMongoTemplate() {
|
||||
MappingMongoConverter converter = new TestMongoConverter(MONGO_DATABASE_FACTORY, new MongoMappingContext());
|
||||
converter.afterPropertiesSet();
|
||||
converter = spy(converter);
|
||||
MongoTemplate writingTemplate = new MongoTemplate(this.mongoDbFactory, converter);
|
||||
MongoTemplate writingTemplate = new MongoTemplate(MONGO_DATABASE_FACTORY, converter);
|
||||
|
||||
|
||||
MongoDbStoringMessageHandler handler = new MongoDbStoringMessageHandler(writingTemplate);
|
||||
handler.setCollectionNameExpression(new LiteralExpression("foo"));
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).build();
|
||||
Message<Person> message = MessageBuilder.withPayload(MongoDbContainerTest.createPerson("Bob")).build();
|
||||
handler.handleMessage(message);
|
||||
|
||||
Query query = new BasicQuery("{'name' : 'Bob'}");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2020 the original author or authors.
|
||||
* Copyright 2019-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,9 +25,9 @@ import static org.mockito.Mockito.spy;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Answers;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -41,13 +41,12 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||
import org.springframework.data.mongodb.core.query.BasicQuery;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -57,48 +56,51 @@ import reactor.core.publisher.Mono;
|
||||
* @author Gary Russell
|
||||
* @author David Turanski
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
* @since 5.3
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class ReactiveMongoDbStoringMessageHandlerTests extends MongoDbAvailableTests {
|
||||
class ReactiveMongoDbStoringMessageHandlerTests implements MongoDbContainerTest {
|
||||
|
||||
public static ReactiveMongoDatabaseFactory REACTIVE_MONGO_DATABASE_FACTORY;
|
||||
|
||||
@BeforeAll
|
||||
static void prepareMongoConnection() {
|
||||
REACTIVE_MONGO_DATABASE_FACTORY = MongoDbContainerTest.createReactiveMongoDbFactory();
|
||||
}
|
||||
|
||||
private ReactiveMongoTemplate template;
|
||||
|
||||
private ReactiveMongoDatabaseFactory mongoDbFactory;
|
||||
|
||||
@Autowired
|
||||
private MessageChannel input;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
this.mongoDbFactory = prepareReactiveMongoFactory("foo");
|
||||
this.template = new ReactiveMongoTemplate(this.mongoDbFactory);
|
||||
MongoDbContainerTest.prepareReactiveMongoData(REACTIVE_MONGO_DATABASE_FACTORY, "foo");
|
||||
this.template = new ReactiveMongoTemplate(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void withNullMongoDBFactory() {
|
||||
void withNullMongoDBFactory() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReactiveMongoDbStoringMessageHandler((ReactiveMongoDatabaseFactory) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void withNullMongoTemplate() {
|
||||
void withNullMongoTemplate() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReactiveMongoDbStoringMessageHandler((ReactiveMongoOperations) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateMessageHandlingWithDefaultCollection() {
|
||||
ReactiveMongoDbStoringMessageHandler handler = new ReactiveMongoDbStoringMessageHandler(this.mongoDbFactory);
|
||||
void validateMessageHandlingWithDefaultCollection() {
|
||||
ReactiveMongoDbStoringMessageHandler handler = new ReactiveMongoDbStoringMessageHandler(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.setApplicationContext(mock(ApplicationContext.class, Answers.RETURNS_MOCKS));
|
||||
handler.afterPropertiesSet();
|
||||
Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).build();
|
||||
Message<Person> message = MessageBuilder.withPayload(MongoDbContainerTest.createPerson("Bob")).build();
|
||||
waitFor(handler.handleMessage(message));
|
||||
|
||||
Query query = new BasicQuery("{'name' : 'Bob'}");
|
||||
@@ -109,15 +111,14 @@ public class ReactiveMongoDbStoringMessageHandlerTests extends MongoDbAvailableT
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateMessageHandlingWithNamedCollection() {
|
||||
ReactiveMongoDbStoringMessageHandler handler = new ReactiveMongoDbStoringMessageHandler(this.mongoDbFactory);
|
||||
void validateMessageHandlingWithNamedCollection() {
|
||||
ReactiveMongoDbStoringMessageHandler handler = new ReactiveMongoDbStoringMessageHandler(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
handler.setCollectionNameExpression(new LiteralExpression("foo"));
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.setApplicationContext(mock(ApplicationContext.class, Answers.RETURNS_MOCKS));
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).build();
|
||||
Message<Person> message = MessageBuilder.withPayload(MongoDbContainerTest.createPerson("Bob")).build();
|
||||
waitFor(handler.handleMessage(message));
|
||||
|
||||
Query query = new BasicQuery("{'name' : 'Bob'}");
|
||||
@@ -129,16 +130,15 @@ public class ReactiveMongoDbStoringMessageHandlerTests extends MongoDbAvailableT
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void errorOnMessageHandlingWithNullValuedExpression() {
|
||||
void errorOnMessageHandlingWithNullValuedExpression() {
|
||||
|
||||
ReactiveMongoDbStoringMessageHandler handler = new ReactiveMongoDbStoringMessageHandler(this.mongoDbFactory);
|
||||
ReactiveMongoDbStoringMessageHandler handler = new ReactiveMongoDbStoringMessageHandler(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
handler.setCollectionNameExpression(new LiteralExpression(null));
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.setApplicationContext(mock(ApplicationContext.class, Answers.RETURNS_MOCKS));
|
||||
handler.afterPropertiesSet();
|
||||
|
||||
Message<Person> message = MessageBuilder.withPayload(createPerson("Bob")).build();
|
||||
Message<Person> message = MessageBuilder.withPayload(MongoDbContainerTest.createPerson("Bob")).build();
|
||||
AtomicBoolean errorOccurred = new AtomicBoolean();
|
||||
handler.handleMessage(message)
|
||||
.doOnError(e -> errorOccurred.set(true))
|
||||
@@ -146,19 +146,18 @@ public class ReactiveMongoDbStoringMessageHandlerTests extends MongoDbAvailableT
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateMessageHandlingWithMongoConverter() {
|
||||
ReactiveMongoDbStoringMessageHandler handler = new ReactiveMongoDbStoringMessageHandler(this.mongoDbFactory);
|
||||
void validateMessageHandlingWithMongoConverter() {
|
||||
ReactiveMongoDbStoringMessageHandler handler = new ReactiveMongoDbStoringMessageHandler(REACTIVE_MONGO_DATABASE_FACTORY);
|
||||
handler.setCollectionNameExpression(new LiteralExpression("foo"));
|
||||
MappingMongoConverter converter =
|
||||
new ReactiveTestMongoConverter(this.mongoDbFactory, new MongoMappingContext());
|
||||
new ReactiveTestMongoConverter(REACTIVE_MONGO_DATABASE_FACTORY, new MongoMappingContext());
|
||||
converter.afterPropertiesSet();
|
||||
converter = spy(converter);
|
||||
handler.setMongoConverter(converter);
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.setApplicationContext(mock(ApplicationContext.class, Answers.RETURNS_MOCKS));
|
||||
handler.afterPropertiesSet();
|
||||
Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).build();
|
||||
Message<Person> message = MessageBuilder.withPayload(MongoDbContainerTest.createPerson("Bob")).build();
|
||||
waitFor(handler.handleMessage(message));
|
||||
|
||||
Query query = new BasicQuery("{'name' : 'Bob'}");
|
||||
@@ -169,19 +168,18 @@ public class ReactiveMongoDbStoringMessageHandlerTests extends MongoDbAvailableT
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void validateMessageHandlingWithMongoTemplate() {
|
||||
void validateMessageHandlingWithMongoTemplate() {
|
||||
MappingMongoConverter converter =
|
||||
new ReactiveTestMongoConverter(this.mongoDbFactory, new MongoMappingContext());
|
||||
new ReactiveTestMongoConverter(REACTIVE_MONGO_DATABASE_FACTORY, new MongoMappingContext());
|
||||
converter.afterPropertiesSet();
|
||||
converter = spy(converter);
|
||||
ReactiveMongoTemplate writingTemplate = new ReactiveMongoTemplate(this.mongoDbFactory, converter);
|
||||
ReactiveMongoTemplate writingTemplate = new ReactiveMongoTemplate(REACTIVE_MONGO_DATABASE_FACTORY, converter);
|
||||
ReactiveMongoDbStoringMessageHandler handler = new ReactiveMongoDbStoringMessageHandler(writingTemplate);
|
||||
handler.setCollectionNameExpression(new LiteralExpression("foo"));
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.setApplicationContext(mock(ApplicationContext.class, Answers.RETURNS_MOCKS));
|
||||
handler.afterPropertiesSet();
|
||||
Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).build();
|
||||
Message<Person> message = MessageBuilder.withPayload(MongoDbContainerTest.createPerson("Bob")).build();
|
||||
waitFor(handler.handleMessage(message));
|
||||
|
||||
Query query = new BasicQuery("{'name' : 'Bob'}");
|
||||
@@ -192,9 +190,8 @@ public class ReactiveMongoDbStoringMessageHandlerTests extends MongoDbAvailableT
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testReactiveMongoMessageHandlerFromApplicationContext() {
|
||||
Message<Person> message = MessageBuilder.withPayload(createPerson("Bob")).build();
|
||||
void testReactiveMongoMessageHandlerFromApplicationContext() {
|
||||
Message<Person> message = MessageBuilder.withPayload(MongoDbContainerTest.createPerson("Bob")).build();
|
||||
this.input.send(message);
|
||||
|
||||
Query query = new BasicQuery("{'name' : 'Bob'}");
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.mongodb.rules;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation used for any test method that requires a running MongoDb process.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.1
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
public @interface MongoDbAvailable {
|
||||
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.mongodb.rules;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Assume;
|
||||
import org.junit.rules.MethodRule;
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.internal.MongoClientImpl;
|
||||
|
||||
/**
|
||||
* A {@link MethodRule} implementation that checks for a running MongoDB process.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public final class MongoDbAvailableRule implements MethodRule {
|
||||
|
||||
@Override
|
||||
public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
|
||||
return new Statement() {
|
||||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
MongoDbAvailable mongoAvailable = method.getAnnotation(MongoDbAvailable.class);
|
||||
if (mongoAvailable != null) {
|
||||
MongoClientSettings settings = MongoClientSettings.builder()
|
||||
.applyToSocketSettings(ss -> ss.connectTimeout(100, TimeUnit.MILLISECONDS))
|
||||
.applyToClusterSettings(cs -> cs.serverSelectionTimeout(100, TimeUnit.MILLISECONDS))
|
||||
.build();
|
||||
try (MongoClient mongo = new MongoClientImpl(settings, null)) {
|
||||
mongo.listDatabaseNames()
|
||||
.first();
|
||||
}
|
||||
catch (Exception e) {
|
||||
Assume.assumeTrue(
|
||||
"Skipping test due to MongoDb not being available on hosts: " +
|
||||
settings.getClusterSettings().getHosts() + ":\n" + e,
|
||||
false);
|
||||
}
|
||||
}
|
||||
base.evaluate();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,18 +26,19 @@ import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||
import org.springframework.integration.aggregator.ReleaseStrategy;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
import org.springframework.integration.store.AbstractBatchingMessageGroupStore;
|
||||
import org.springframework.integration.store.MessageGroup;
|
||||
import org.springframework.integration.store.MessageGroupStore;
|
||||
@@ -53,8 +54,16 @@ import org.springframework.messaging.support.GenericMessage;
|
||||
* @author Gary Russell
|
||||
* @author Amol Nayak
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*/
|
||||
public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvailableTests {
|
||||
public abstract class AbstractMongoDbMessageGroupStoreTests implements MongoDbContainerTest {
|
||||
|
||||
public static MongoDatabaseFactory MONGO_DATABASE_FACTORY;
|
||||
|
||||
@BeforeAll
|
||||
static void prepareMongoConnection() {
|
||||
MONGO_DATABASE_FACTORY = MongoDbContainerTest.createMongoDbFactory();
|
||||
}
|
||||
|
||||
public static final BiFunction<Message<?>, String, String> CONDITION_SUPPLIER = (m, c) -> "10";
|
||||
|
||||
@@ -63,20 +72,19 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
|
||||
protected final GenericApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.testApplicationContext.refresh();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
this.testApplicationContext.close();
|
||||
cleanupCollections(MONGO_DATABASE_FACTORY);
|
||||
MongoDbContainerTest.cleanupCollections(MONGO_DATABASE_FACTORY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testNonExistingEmptyMessageGroup() {
|
||||
void testNonExistingEmptyMessageGroup() {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
store.addMessagesToGroup(1, new GenericMessage<Object>("foo"));
|
||||
MessageGroup messageGroup = store.getMessageGroup(1);
|
||||
@@ -86,8 +94,7 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testMessageGroupWithAddedMessagePrimitiveGroupId() {
|
||||
void testMessageGroupWithAddedMessagePrimitiveGroupId() {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
MessageStore messageStore = getMessageStore();
|
||||
MessageGroup messageGroup = store.getMessageGroup(1);
|
||||
@@ -106,8 +113,7 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testMessageGroupWithAddedMessageUUIDGroupIdAndUUIDHeader() {
|
||||
void testMessageGroupWithAddedMessageUUIDGroupIdAndUUIDHeader() {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
MessageStore messageStore = getMessageStore();
|
||||
Object id = UUID.randomUUID();
|
||||
@@ -126,13 +132,13 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
// ensure that 'message_group' header that is only used internally is not propagated
|
||||
assertThat(retrievedMessage.getHeaders().get("message_group")).isNull();
|
||||
Object fooHeader = retrievedMessage.getHeaders().get("foo");
|
||||
assertThat(fooHeader instanceof UUID).isTrue();
|
||||
assertThat(fooHeader).isEqualTo(uuidA);
|
||||
assertThat(fooHeader)
|
||||
.isInstanceOf(UUID.class)
|
||||
.isEqualTo(uuidA);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testCountMessagesInGroup() {
|
||||
void testCountMessagesInGroup() {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
Message<?> messageA = new GenericMessage<>("A");
|
||||
Message<?> messageB = new GenericMessage<>("B");
|
||||
@@ -141,8 +147,7 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testPollMessages() throws InterruptedException {
|
||||
void testPollMessages() throws InterruptedException {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
Message<?> messageA = new GenericMessage<>("A");
|
||||
Message<?> messageB = new GenericMessage<>("B");
|
||||
@@ -156,12 +161,11 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
assertThat(store.messageGroupSize(1)).isEqualTo(1);
|
||||
out = store.pollMessageFromGroup(1);
|
||||
assertThat(out.getPayload()).isEqualTo("B");
|
||||
assertThat(store.messageGroupSize(1)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(1)).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testSameMessageMultipleGroupsPoll() {
|
||||
void testSameMessageMultipleGroupsPoll() {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
Message<?> messageA = new GenericMessage<>("A");
|
||||
store.addMessagesToGroup(1, messageA);
|
||||
@@ -175,28 +179,27 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
store.pollMessageFromGroup(3);
|
||||
assertThat(store.messageGroupSize(1)).isEqualTo(1);
|
||||
assertThat(store.messageGroupSize(2)).isEqualTo(1);
|
||||
assertThat(store.messageGroupSize(3)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(3)).isZero();
|
||||
assertThat(store.messageGroupSize(4)).isEqualTo(1);
|
||||
store.pollMessageFromGroup(4);
|
||||
assertThat(store.messageGroupSize(1)).isEqualTo(1);
|
||||
assertThat(store.messageGroupSize(2)).isEqualTo(1);
|
||||
assertThat(store.messageGroupSize(3)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(4)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(3)).isZero();
|
||||
assertThat(store.messageGroupSize(4)).isZero();
|
||||
store.pollMessageFromGroup(2);
|
||||
assertThat(store.messageGroupSize(1)).isEqualTo(1);
|
||||
assertThat(store.messageGroupSize(2)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(3)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(4)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(2)).isZero();
|
||||
assertThat(store.messageGroupSize(3)).isZero();
|
||||
assertThat(store.messageGroupSize(4)).isZero();
|
||||
store.pollMessageFromGroup(1);
|
||||
assertThat(store.messageGroupSize(1)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(2)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(3)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(4)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(1)).isZero();
|
||||
assertThat(store.messageGroupSize(2)).isZero();
|
||||
assertThat(store.messageGroupSize(3)).isZero();
|
||||
assertThat(store.messageGroupSize(4)).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testSameMessageMultipleGroupsRemove() {
|
||||
void testSameMessageMultipleGroupsRemove() {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
Message<?> messageA = new GenericMessage<>("A");
|
||||
store.addMessagesToGroup(1, messageA);
|
||||
@@ -210,28 +213,27 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
store.removeMessagesFromGroup(3, messageA);
|
||||
assertThat(store.messageGroupSize(1)).isEqualTo(1);
|
||||
assertThat(store.messageGroupSize(2)).isEqualTo(1);
|
||||
assertThat(store.messageGroupSize(3)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(3)).isZero();
|
||||
assertThat(store.messageGroupSize(4)).isEqualTo(1);
|
||||
store.removeMessagesFromGroup(4, messageA);
|
||||
assertThat(store.messageGroupSize(1)).isEqualTo(1);
|
||||
assertThat(store.messageGroupSize(2)).isEqualTo(1);
|
||||
assertThat(store.messageGroupSize(3)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(4)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(3)).isZero();
|
||||
assertThat(store.messageGroupSize(4)).isZero();
|
||||
store.removeMessagesFromGroup(2, messageA);
|
||||
assertThat(store.messageGroupSize(1)).isEqualTo(1);
|
||||
assertThat(store.messageGroupSize(2)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(3)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(4)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(2)).isZero();
|
||||
assertThat(store.messageGroupSize(3)).isZero();
|
||||
assertThat(store.messageGroupSize(4)).isZero();
|
||||
store.removeMessagesFromGroup(1, messageA);
|
||||
assertThat(store.messageGroupSize(1)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(2)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(3)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(4)).isEqualTo(0);
|
||||
assertThat(store.messageGroupSize(1)).isZero();
|
||||
assertThat(store.messageGroupSize(2)).isZero();
|
||||
assertThat(store.messageGroupSize(3)).isZero();
|
||||
assertThat(store.messageGroupSize(4)).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testMessageGroupUpdatedDateChangesWithEachAddedMessage() throws InterruptedException {
|
||||
void testMessageGroupUpdatedDateChangesWithEachAddedMessage() throws InterruptedException {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
|
||||
MessageGroup messageGroup = store.getMessageGroup(1);
|
||||
@@ -258,8 +260,7 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testMessageGroupMarkingMessage() {
|
||||
void testMessageGroupMarkingMessage() {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
|
||||
MessageGroup messageGroup = store.getMessageGroup(1);
|
||||
@@ -282,8 +283,7 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testRemoveMessageGroup() {
|
||||
void testRemoveMessageGroup() {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
MessageStore messageStore = getMessageStore();
|
||||
|
||||
@@ -298,14 +298,13 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
|
||||
store.removeMessageGroup(1);
|
||||
MessageGroup messageGroupA = store.getMessageGroup(1);
|
||||
assertThat(messageGroupA.size()).isEqualTo(0);
|
||||
assertThat(messageGroupA.size()).isZero();
|
||||
assertThat(messageGroupA.equals(messageGroup)).isFalse();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testCompleteMessageGroup() {
|
||||
void testCompleteMessageGroup() {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
|
||||
MessageGroup messageGroup = store.getMessageGroup(1);
|
||||
@@ -318,8 +317,7 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testLastReleasedSequenceNumber() {
|
||||
void testLastReleasedSequenceNumber() {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
|
||||
MessageGroup messageGroup = store.getMessageGroup(1);
|
||||
@@ -332,8 +330,7 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testRemoveMessageFromTheGroup() {
|
||||
void testRemoveMessageFromTheGroup() {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
|
||||
MessageGroup messageGroup = store.getMessageGroup(1);
|
||||
@@ -349,8 +346,7 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testMultipleMessageStores() {
|
||||
void testMultipleMessageStores() {
|
||||
MessageGroupStore store1 = getMessageGroupStore();
|
||||
MessageGroupStore store2 = getMessageGroupStore();
|
||||
|
||||
@@ -371,8 +367,7 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testMessageGroupIterator() {
|
||||
void testMessageGroupIterator() {
|
||||
MessageGroupStore store1 = getMessageGroupStore();
|
||||
MessageGroupStore store2 = getMessageGroupStore();
|
||||
|
||||
@@ -403,8 +398,7 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testAddAndRemoveMessagesFromMessageGroup() {
|
||||
void testAddAndRemoveMessagesFromMessageGroup() {
|
||||
MessageGroupStore messageStore = (MessageGroupStore) getMessageStore();
|
||||
String groupId = "X";
|
||||
messageStore.removeMessageGroup("X");
|
||||
@@ -419,15 +413,15 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
assertThat(group.size()).isEqualTo(25);
|
||||
messageStore.removeMessagesFromGroup(groupId, messages);
|
||||
group = messageStore.getMessageGroup(groupId);
|
||||
assertThat(group.size()).isEqualTo(0);
|
||||
assertThat(group.size()).isZero();
|
||||
}
|
||||
|
||||
// @Test
|
||||
// @MongoDbAvailable
|
||||
// public void testConcurrentModifications() throws Exception{
|
||||
// MongoDatabaseFactory mongoDbFactory = this.prepareMongoFactory();
|
||||
// final MongoDbMessageStore store1 = new MongoDbMessageStore(mongoDbFactory);
|
||||
// final MongoDbMessageStore store2 = new MongoDbMessageStore(mongoDbFactory);
|
||||
// MongoDbContainerTest.prepareMongoFactory(MONGO_DATABASE_FACTORY);
|
||||
// final MongoDbMessageStore store1 = new MongoDbMessageStore(MONGO_DATABASE_FACTORY);
|
||||
// final MongoDbMessageStore store2 = new MongoDbMessageStore(MONGO_DATABASE_FACTORY);
|
||||
//
|
||||
// final Message<?> message = new GenericMessage<String>("1");
|
||||
//
|
||||
@@ -513,8 +507,7 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithMessageHistory() {
|
||||
void testWithMessageHistory() {
|
||||
MessageGroupStore store = getMessageGroupStore();
|
||||
|
||||
store.getMessageGroup(1);
|
||||
@@ -536,10 +529,11 @@ public abstract class AbstractMongoDbMessageGroupStoreTests extends MongoDbAvail
|
||||
|
||||
MessageHistory messageHistory = MessageHistory.read(message);
|
||||
assertThat(messageHistory).isNotNull();
|
||||
assertThat(messageHistory.size()).isEqualTo(2);
|
||||
assertThat(messageHistory).hasSize(2);
|
||||
Properties fooChannelHistory = messageHistory.get(0);
|
||||
assertThat(fooChannelHistory.get("name")).isEqualTo("fooChannel");
|
||||
assertThat(fooChannelHistory.get("type")).isEqualTo("channel");
|
||||
assertThat(fooChannelHistory)
|
||||
.containsEntry("name", "fooChannel")
|
||||
.containsEntry("type", "channel");
|
||||
}
|
||||
|
||||
protected abstract MessageGroupStore getMessageGroupStore();
|
||||
|
||||
@@ -22,17 +22,18 @@ import java.io.Serializable;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.data.annotation.PersistenceCreator;
|
||||
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.message.AdviceMessage;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
import org.springframework.integration.store.MessageStore;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.MutableMessage;
|
||||
@@ -49,26 +50,33 @@ import org.springframework.messaging.support.GenericMessage;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Artem Bilan
|
||||
* @author Amol Nayak
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableTests {
|
||||
public abstract class AbstractMongoDbMessageStoreTests implements MongoDbContainerTest {
|
||||
|
||||
static MongoDatabaseFactory MONGO_DATABASE_FACTORY;
|
||||
|
||||
@BeforeAll
|
||||
static void prepareMongoConnection() {
|
||||
MONGO_DATABASE_FACTORY = MongoDbContainerTest.createMongoDbFactory();
|
||||
}
|
||||
|
||||
protected final GenericApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.testApplicationContext.refresh();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
this.testApplicationContext.close();
|
||||
cleanupCollections(MONGO_DATABASE_FACTORY);
|
||||
MongoDbContainerTest.cleanupCollections(MONGO_DATABASE_FACTORY);
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testAddGetWithStringPayload() {
|
||||
void testAddGetWithStringPayload() {
|
||||
MessageStore store = getMessageStore();
|
||||
Message<?> messageToStore = MessageBuilder.withPayload("Hello").build();
|
||||
store.addMessage(messageToStore);
|
||||
@@ -79,10 +87,8 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
assertThat(retrievedMessage).isEqualTo(messageToStore);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testAddThenRemoveWithStringPayload() {
|
||||
void testAddThenRemoveWithStringPayload() {
|
||||
MessageStore store = getMessageStore();
|
||||
Message<?> messageToStore = MessageBuilder.withPayload("Hello").build();
|
||||
store.addMessage(messageToStore);
|
||||
@@ -93,10 +99,8 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
assertThat(retrievedMessage).isNull();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testAddGetWithObjectDefaultConstructorPayload() {
|
||||
void testAddGetWithObjectDefaultConstructorPayload() {
|
||||
MessageStore store = getMessageStore();
|
||||
Person p = new Person();
|
||||
p.setFname("John");
|
||||
@@ -110,10 +114,8 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
assertThat(retrievedMessage).isEqualTo(messageToStore);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithMessageHistory() {
|
||||
void testWithMessageHistory() {
|
||||
MessageStore store = getMessageStore();
|
||||
Foo foo = new Foo();
|
||||
foo.setName("foo");
|
||||
@@ -134,23 +136,22 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
store.addMessage(message);
|
||||
message = store.getMessage(message.getHeaders().getId());
|
||||
assertThat(message).isNotNull();
|
||||
assertThat(message.getHeaders().get("foo") instanceof Foo).isTrue();
|
||||
assertThat(message.getHeaders().get("bar") instanceof Bar).isTrue();
|
||||
assertThat(message.getHeaders().get("baz") instanceof Baz).isTrue();
|
||||
assertThat(message.getHeaders().get("abc") instanceof Abc).isTrue();
|
||||
assertThat(message.getHeaders().get("xyz") instanceof Xyz).isTrue();
|
||||
assertThat(message.getHeaders().get("foo")).isInstanceOf(Foo.class);
|
||||
assertThat(message.getHeaders().get("bar")).isInstanceOf(Bar.class);
|
||||
assertThat(message.getHeaders().get("baz")).isInstanceOf(Baz.class);
|
||||
assertThat(message.getHeaders().get("abc")).isInstanceOf(Abc.class);
|
||||
assertThat(message.getHeaders().get("xyz")).isInstanceOf(Xyz.class);
|
||||
MessageHistory messageHistory = MessageHistory.read(message);
|
||||
assertThat(messageHistory).isNotNull();
|
||||
assertThat(messageHistory.size()).isEqualTo(2);
|
||||
assertThat(messageHistory).hasSize(2);
|
||||
Properties fooChannelHistory = messageHistory.get(0);
|
||||
assertThat(fooChannelHistory.get("name")).isEqualTo("fooChannel");
|
||||
assertThat(fooChannelHistory.get("type")).isEqualTo("channel");
|
||||
assertThat(fooChannelHistory)
|
||||
.containsEntry("name", "fooChannel")
|
||||
.containsEntry("type", "channel");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testInt3153SequenceDetails() {
|
||||
void testInt3153SequenceDetails() {
|
||||
MessageStore store = getMessageStore();
|
||||
Message<?> messageToStore = MessageBuilder.withPayload("test")
|
||||
.pushSequenceDetails(UUID.randomUUID(), 1, 1)
|
||||
@@ -165,8 +166,7 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testInt3076MessageAsPayload() {
|
||||
void testInt3076MessageAsPayload() {
|
||||
MessageStore store = getMessageStore();
|
||||
Person p = new Person();
|
||||
p.setFname("John");
|
||||
@@ -175,7 +175,7 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
store.addMessage(messageToStore);
|
||||
Message<?> retrievedMessage = store.getMessage(messageToStore.getHeaders().getId());
|
||||
assertThat(retrievedMessage).isNotNull();
|
||||
assertThat(retrievedMessage.getPayload() instanceof GenericMessage).isTrue();
|
||||
assertThat(retrievedMessage.getPayload()).isInstanceOf(GenericMessage.class);
|
||||
assertThat(retrievedMessage.getPayload()).isEqualTo(messageToStore.getPayload());
|
||||
assertThat(retrievedMessage.getHeaders()).isEqualTo(messageToStore.getHeaders());
|
||||
assertThat(p).isEqualTo(((Message<?>) messageToStore.getPayload()).getPayload());
|
||||
@@ -183,8 +183,7 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testInt3076AdviceMessage() {
|
||||
void testInt3076AdviceMessage() {
|
||||
MessageStore store = getMessageStore();
|
||||
Person p = new Person();
|
||||
p.setFname("John");
|
||||
@@ -193,8 +192,9 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
Message<?> messageToStore = new AdviceMessage<>("foo", inputMessage);
|
||||
store.addMessage(messageToStore);
|
||||
Message<?> retrievedMessage = store.getMessage(messageToStore.getHeaders().getId());
|
||||
assertThat(retrievedMessage).isNotNull();
|
||||
assertThat(retrievedMessage instanceof AdviceMessage).isTrue();
|
||||
assertThat(retrievedMessage)
|
||||
.isNotNull()
|
||||
.isInstanceOf(AdviceMessage.class);
|
||||
assertThat(retrievedMessage.getPayload()).isEqualTo(messageToStore.getPayload());
|
||||
assertThat(retrievedMessage.getHeaders()).isEqualTo(messageToStore.getHeaders());
|
||||
assertThat(((AdviceMessage<?>) retrievedMessage).getInputMessage()).isEqualTo(inputMessage);
|
||||
@@ -202,8 +202,7 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testAdviceMessageAsPayload() {
|
||||
void testAdviceMessageAsPayload() {
|
||||
MessageStore store = getMessageStore();
|
||||
Person p = new Person();
|
||||
p.setFname("John");
|
||||
@@ -213,7 +212,7 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
store.addMessage(messageToStore);
|
||||
Message<?> retrievedMessage = store.getMessage(messageToStore.getHeaders().getId());
|
||||
assertThat(retrievedMessage).isNotNull();
|
||||
assertThat(retrievedMessage.getPayload() instanceof AdviceMessage).isTrue();
|
||||
assertThat(retrievedMessage.getPayload()).isInstanceOf(AdviceMessage.class);
|
||||
AdviceMessage<?> adviceMessage = (AdviceMessage<?>) retrievedMessage.getPayload();
|
||||
assertThat(adviceMessage.getPayload()).isEqualTo("foo");
|
||||
assertThat(retrievedMessage.getHeaders()).isEqualTo(messageToStore.getHeaders());
|
||||
@@ -222,8 +221,7 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testMutableMessageAsPayload() {
|
||||
void testMutableMessageAsPayload() {
|
||||
MessageStore store = getMessageStore();
|
||||
Person p = new Person();
|
||||
p.setFname("John");
|
||||
@@ -240,8 +238,7 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testInt3076ErrorMessage() {
|
||||
void testInt3076ErrorMessage() {
|
||||
MessageStore store = getMessageStore();
|
||||
Person p = new Person();
|
||||
p.setFname("John");
|
||||
@@ -257,8 +254,9 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
Message<?> messageToStore = new ErrorMessage(messagingException);
|
||||
store.addMessage(messageToStore);
|
||||
Message<?> retrievedMessage = store.getMessage(messageToStore.getHeaders().getId());
|
||||
assertThat(retrievedMessage).isNotNull();
|
||||
assertThat(retrievedMessage instanceof ErrorMessage).isTrue();
|
||||
assertThat(retrievedMessage)
|
||||
.isNotNull()
|
||||
.isInstanceOf(ErrorMessage.class);
|
||||
assertThat(retrievedMessage.getPayload()).isInstanceOf(MessagingException.class);
|
||||
assertThat(((MessagingException) retrievedMessage.getPayload()).getMessage())
|
||||
.contains("intentional MessagingException");
|
||||
@@ -267,8 +265,7 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testAddAndUpdateAlreadySaved() {
|
||||
void testAddAndUpdateAlreadySaved() {
|
||||
MessageStore messageStore = getMessageStore();
|
||||
Message<String> message = MessageBuilder.withPayload("foo").build();
|
||||
message = messageStore.addMessage(message);
|
||||
@@ -324,7 +321,8 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
this("baz");
|
||||
}
|
||||
|
||||
@PersistenceCreator Baz(String name) {
|
||||
@PersistenceCreator
|
||||
Baz(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -344,7 +342,8 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
this("abx");
|
||||
}
|
||||
|
||||
@PersistenceCreator Abc(String name) {
|
||||
@PersistenceCreator
|
||||
Abc(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -366,7 +365,8 @@ public abstract class AbstractMongoDbMessageStoreTests extends MongoDbAvailableT
|
||||
this("xyz");
|
||||
}
|
||||
|
||||
@PersistenceCreator Xyz(String name) {
|
||||
@PersistenceCreator
|
||||
Xyz(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,8 +21,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
@@ -30,7 +30,6 @@ import org.springframework.data.convert.ReadingConverter;
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.integration.channel.PriorityChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.store.AbstractMessageGroupStore;
|
||||
import org.springframework.integration.store.MessageStore;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
@@ -42,9 +41,10 @@ import org.springframework.util.StopWatch;
|
||||
/**
|
||||
* @author Amol Nayak
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
*/
|
||||
public class ConfigurableMongoDbMessageGroupStoreTests extends AbstractMongoDbMessageGroupStoreTests {
|
||||
class ConfigurableMongoDbMessageGroupStoreTests extends AbstractMongoDbMessageGroupStoreTests {
|
||||
|
||||
@Override
|
||||
protected ConfigurableMongoDbMessageStore getMessageGroupStore() {
|
||||
@@ -61,15 +61,13 @@ public class ConfigurableMongoDbMessageGroupStoreTests extends AbstractMongoDbMe
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithAggregatorWithShutdown() {
|
||||
void testWithAggregatorWithShutdown() {
|
||||
super.testWithAggregatorWithShutdown("mongo-aggregator-configurable-config.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("The performance test. Enough slow. Also needs the release strategy changed to size() == 1000")
|
||||
@MongoDbAvailable
|
||||
public void messageGroupStoreLazyLoadPerformance() {
|
||||
@Disabled("The performance test. Enough slow. Also needs the release strategy changed to size() == 1000")
|
||||
void messageGroupStoreLazyLoadPerformance() {
|
||||
StopWatch watch = new StopWatch("Lazy-Load Performance");
|
||||
|
||||
int sequenceSize = 1000;
|
||||
@@ -107,8 +105,7 @@ public class ConfigurableMongoDbMessageGroupStoreTests extends AbstractMongoDbMe
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithCustomConverter() {
|
||||
void testWithCustomConverter() {
|
||||
ClassPathXmlApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("ConfigurableMongoDbMessageStore-CustomConverter.xml", this
|
||||
.getClass());
|
||||
@@ -121,8 +118,7 @@ public class ConfigurableMongoDbMessageGroupStoreTests extends AbstractMongoDbMe
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testPriorityChannel() {
|
||||
void testPriorityChannel() {
|
||||
ClassPathXmlApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("ConfigurableMongoDbMessageStore-CustomConverter.xml", this
|
||||
.getClass());
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd">
|
||||
|
||||
<mongo:auditing />
|
||||
<mongo:auditing/>
|
||||
|
||||
<beans:bean id="messageStore"
|
||||
class="org.springframework.integration.mongodb.store.ConfigurableMongoDbMessageStore">
|
||||
class="org.springframework.integration.mongodb.store.ConfigurableMongoDbMessageStore">
|
||||
<beans:constructor-arg
|
||||
value="#{T (org.springframework.integration.mongodb.store.DelayerHandlerRescheduleIntegrationTests).MONGO_DATABASE_FACTORY}"/>
|
||||
value="#{T (org.springframework.integration.mongodb.MongoDbContainerTest).createMongoDbFactory()}"/>
|
||||
</beans:bean>
|
||||
|
||||
<channel id="output">
|
||||
<queue />
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<delayer
|
||||
id="#{T (org.springframework.integration.mongodb.store.DelayerHandlerRescheduleIntegrationTests).DELAYER_ID}"
|
||||
input-channel="input" output-channel="output" default-delay="10000"
|
||||
message-store="messageStore" />
|
||||
id="#{T (org.springframework.integration.mongodb.store.DelayerHandlerRescheduleIntegrationTests).DELAYER_ID}"
|
||||
input-channel="input" output-channel="output" default-delay="10000"
|
||||
message-store="messageStore"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd">
|
||||
|
||||
<mongo:auditing />
|
||||
<mongo:auditing/>
|
||||
|
||||
<beans:bean id="messageStore"
|
||||
class="org.springframework.integration.mongodb.store.MongoDbMessageStore">
|
||||
class="org.springframework.integration.mongodb.store.MongoDbMessageStore">
|
||||
<beans:constructor-arg
|
||||
value="#{T (org.springframework.integration.mongodb.store.DelayerHandlerRescheduleIntegrationTests).MONGO_DATABASE_FACTORY}"/>
|
||||
value="#{T (org.springframework.integration.mongodb.MongoDbContainerTest).createMongoDbFactory()}"/>
|
||||
</beans:bean>
|
||||
|
||||
<channel id="output">
|
||||
<queue />
|
||||
<queue/>
|
||||
</channel>
|
||||
|
||||
<delayer
|
||||
id="#{T (org.springframework.integration.mongodb.store.DelayerHandlerRescheduleIntegrationTests).DELAYER_ID}"
|
||||
input-channel="input" output-channel="output" default-delay="10000"
|
||||
message-store="messageStore" />
|
||||
id="#{T (org.springframework.integration.mongodb.store.DelayerHandlerRescheduleIntegrationTests).DELAYER_ID}"
|
||||
input-channel="input" output-channel="output" default-delay="10000"
|
||||
message-store="messageStore"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,19 +21,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.handler.DelayHandler;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
import org.springframework.integration.store.MessageGroup;
|
||||
import org.springframework.integration.store.MessageGroupStore;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.support.LongRunningIntegrationTest;
|
||||
import org.springframework.integration.test.condition.LongRunningTest;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
@@ -41,25 +39,22 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public class DelayerHandlerRescheduleIntegrationTests extends MongoDbAvailableTests {
|
||||
@LongRunningTest
|
||||
class DelayerHandlerRescheduleIntegrationTests implements MongoDbContainerTest {
|
||||
|
||||
public static final String DELAYER_ID = "delayerWithMongoMS";
|
||||
|
||||
@Rule
|
||||
public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithMongoDbMessageStore() throws Exception {
|
||||
void testWithMongoDbMessageStore() throws Exception {
|
||||
testDelayerHandlerRescheduleWithMongoDbMessageStore("DelayerHandlerRescheduleIntegrationTests-context.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithConfigurableMongoDbMessageStore() throws Exception {
|
||||
void testWithConfigurableMongoDbMessageStore() throws Exception {
|
||||
testDelayerHandlerRescheduleWithMongoDbMessageStore("DelayerHandlerRescheduleIntegrationConfigurableTests-context.xml");
|
||||
}
|
||||
|
||||
@@ -92,7 +87,7 @@ public class DelayerHandlerRescheduleIntegrationTests extends MongoDbAvailableTe
|
||||
Object payload = messageInStore.getPayload();
|
||||
|
||||
// INT-3049
|
||||
assertThat(payload instanceof DelayHandler.DelayedMessageWrapper).isTrue();
|
||||
assertThat(payload).isInstanceOf(DelayHandler.DelayedMessageWrapper.class);
|
||||
|
||||
Message<String> original1 = (Message<String>) ((DelayHandler.DelayedMessageWrapper) payload).getOriginal();
|
||||
messageInStore = iterator.next();
|
||||
@@ -118,7 +113,7 @@ public class DelayerHandlerRescheduleIntegrationTests extends MongoDbAvailableTe
|
||||
|
||||
messageStore = context.getBean("messageStore", MessageGroupStore.class);
|
||||
|
||||
assertThat(messageStore.messageGroupSize(delayerMessageGroupId)).isEqualTo(0);
|
||||
assertThat(messageStore.messageGroupSize(delayerMessageGroupId)).isZero();
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2019 the original author or authors.
|
||||
* Copyright 2007-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,18 +16,18 @@
|
||||
|
||||
package org.springframework.integration.mongodb.store;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.store.MessageStore;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
*/
|
||||
public class MongoDbMessageGroupStoreTests extends AbstractMongoDbMessageGroupStoreTests {
|
||||
class MongoDbMessageGroupStoreTests extends AbstractMongoDbMessageGroupStoreTests {
|
||||
|
||||
@Override
|
||||
protected MongoDbMessageStore getMessageGroupStore() {
|
||||
@@ -43,8 +43,7 @@ public class MongoDbMessageGroupStoreTests extends AbstractMongoDbMessageGroupSt
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testWithAggregatorWithShutdown() {
|
||||
void testWithAggregatorWithShutdown() {
|
||||
super.testWithAggregatorWithShutdown("mongo-aggregator-config.xml");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,13 +20,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
|
||||
import org.springframework.data.mongodb.MongoDatabaseFactory;
|
||||
import org.springframework.integration.mongodb.MongoDbContainerTest;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.transformer.ClaimCheckInTransformer;
|
||||
@@ -36,24 +37,31 @@ import org.springframework.messaging.Message;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*/
|
||||
public class MongoDbMessageStoreClaimCheckIntegrationTests extends MongoDbAvailableTests {
|
||||
class MongoDbMessageStoreClaimCheckIntegrationTests implements MongoDbContainerTest {
|
||||
|
||||
static MongoDatabaseFactory MONGO_DATABASE_FACTORY;
|
||||
|
||||
@BeforeAll
|
||||
static void prepareMongoConnection() {
|
||||
MONGO_DATABASE_FACTORY = MongoDbContainerTest.createMongoDbFactory();
|
||||
}
|
||||
|
||||
private final GenericApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.testApplicationContext.refresh();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
this.testApplicationContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void stringPayload() {
|
||||
void stringPayload() {
|
||||
MongoDbMessageStore messageStore = new MongoDbMessageStore(MONGO_DATABASE_FACTORY);
|
||||
messageStore.afterPropertiesSet();
|
||||
ClaimCheckInTransformer checkin = new ClaimCheckInTransformer(messageStore);
|
||||
@@ -68,8 +76,7 @@ public class MongoDbMessageStoreClaimCheckIntegrationTests extends MongoDbAvaila
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void objectPayload() {
|
||||
void objectPayload() {
|
||||
MongoDbMessageStore messageStore = new MongoDbMessageStore(MONGO_DATABASE_FACTORY);
|
||||
messageStore.afterPropertiesSet();
|
||||
ClaimCheckInTransformer checkin = new ClaimCheckInTransformer(messageStore);
|
||||
@@ -88,8 +95,7 @@ public class MongoDbMessageStoreClaimCheckIntegrationTests extends MongoDbAvaila
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void stringPayloadConfigurable() {
|
||||
void stringPayloadConfigurable() {
|
||||
ConfigurableMongoDbMessageStore messageStore = new ConfigurableMongoDbMessageStore(MONGO_DATABASE_FACTORY);
|
||||
messageStore.setApplicationContext(this.testApplicationContext);
|
||||
messageStore.afterPropertiesSet();
|
||||
@@ -105,8 +111,7 @@ public class MongoDbMessageStoreClaimCheckIntegrationTests extends MongoDbAvaila
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void objectPayloadConfigurable() {
|
||||
void objectPayloadConfigurable() {
|
||||
ConfigurableMongoDbMessageStore messageStore = new ConfigurableMongoDbMessageStore(MONGO_DATABASE_FACTORY);
|
||||
messageStore.setApplicationContext(this.testApplicationContext);
|
||||
messageStore.afterPropertiesSet();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,11 +21,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.WritingConverter;
|
||||
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
|
||||
import org.springframework.integration.store.MessageStore;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
@@ -33,9 +32,10 @@ import org.springframework.messaging.support.GenericMessage;
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Artem Bilan
|
||||
* @author Artem Vozhdayenko
|
||||
*
|
||||
*/
|
||||
public class MongoDbMessageStoreTests extends AbstractMongoDbMessageStoreTests {
|
||||
class MongoDbMessageStoreTests extends AbstractMongoDbMessageStoreTests {
|
||||
|
||||
@Override
|
||||
protected MessageStore getMessageStore() {
|
||||
@@ -45,8 +45,7 @@ public class MongoDbMessageStoreTests extends AbstractMongoDbMessageStoreTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@MongoDbAvailable
|
||||
public void testCustomConverter() throws InterruptedException {
|
||||
void testCustomConverter() throws InterruptedException {
|
||||
MongoDbMessageStore mongoDbMessageStore = new MongoDbMessageStore(MONGO_DATABASE_FACTORY);
|
||||
FooToBytesConverter fooToBytesConverter = new FooToBytesConverter();
|
||||
mongoDbMessageStore.setCustomConverters(fooToBytesConverter);
|
||||
|
||||
Reference in New Issue
Block a user