DATAMONGO-1824 - Use Rule to verify server version in tests.

Original pull request: #515.
This commit is contained in:
Christoph Strobl
2017-11-17 10:56:46 +01:00
committed by Mark Paluch
parent 4f78aacbf7
commit 0119af1679
2 changed files with 32 additions and 80 deletions

View File

@@ -118,11 +118,6 @@ import com.mongodb.client.result.UpdateResult;
@ContextConfiguration("classpath:infrastructure.xml")
public class MongoTemplateTests {
private static final org.springframework.data.util.Version TWO_DOT_FOUR = org.springframework.data.util.Version
.parse("2.4");
private static final org.springframework.data.util.Version THREE_DOT_FOUR = org.springframework.data.util.Version
.parse("3.4");
@Autowired MongoTemplate template;
@Autowired MongoDbFactory factory;
@@ -2331,10 +2326,9 @@ public class MongoTemplateTests {
}
@Test // DATAMONGO-812
@MongoVersion(asOf = "2.4")
public void updateMultiShouldAddValuesCorrectlyWhenUsingPushEachWithComplexTypes() {
assumeThat(mongoVersion.isGreaterThanOrEqualTo(TWO_DOT_FOUR), is(true));
DocumentWithCollection document = new DocumentWithCollection(Collections.<Model> emptyList());
template.save(document);
Query query = query(where("id").is(document.id));
@@ -2347,10 +2341,9 @@ public class MongoTemplateTests {
}
@Test // DATAMONGO-812
@MongoVersion(asOf = "2.4")
public void updateMultiShouldAddValuesCorrectlyWhenUsingPushEachWithSimpleTypes() {
assumeThat(mongoVersion.isGreaterThanOrEqualTo(TWO_DOT_FOUR), is(true));
DocumentWithCollectionOfSimpleType document = new DocumentWithCollectionOfSimpleType();
document.values = Arrays.asList("spring");
template.save(document);
@@ -3214,14 +3207,11 @@ public class MongoTemplateTests {
assertThat(template.findOne(query, DocumentWithCollection.class), is(equalTo(dwc)));
}
/**
* @see DATAMONGO-1517
*/
@Test
@Test // DATAMONGO-1517
@MongoVersion(asOf = "3.4")
public void decimal128TypeShouldBeSavedAndLoadedCorrectly()
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_FOUR), is(true));
assumeThat(MongoClientVersion.isMongo34Driver(), is(true));
Class<?> decimal128Type = ClassUtils.resolveClassName("org.bson.types.Decimal128", null);

View File

@@ -17,7 +17,6 @@ package org.springframework.data.mongodb.core.aggregation;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import static org.springframework.data.domain.Sort.Direction.*;
import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
import static org.springframework.data.mongodb.core.aggregation.Fields.*;
@@ -66,8 +65,9 @@ import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.NearQuery;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.repository.Person;
import org.springframework.data.mongodb.test.util.MongoVersion;
import org.springframework.data.mongodb.test.util.MongoVersionRule;
import org.springframework.data.util.CloseableIterator;
import org.springframework.data.util.Version;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -92,34 +92,21 @@ public class AggregationTests {
private static final String INPUT_COLLECTION = "aggregation_test_collection";
private static final Logger LOGGER = LoggerFactory.getLogger(AggregationTests.class);
private static final Version TWO_DOT_FOUR = new Version(2, 4);
private static final Version TWO_DOT_SIX = new Version(2, 6);
private static final Version THREE_DOT_TWO = new Version(3, 2);
private static final Version THREE_DOT_FOUR = new Version(3, 4);
private static boolean initialized = false;
@Autowired MongoTemplate mongoTemplate;
@Rule public ExpectedException exception = ExpectedException.none();
private static Version mongoVersion;
@Rule public MongoVersionRule mongoVersion = MongoVersionRule.any();
@Before
public void setUp() {
queryMongoVersionIfNecessary();
cleanDb();
initSampleDataIfNecessary();
}
private void queryMongoVersionIfNecessary() {
if (mongoVersion == null) {
org.bson.Document result = mongoTemplate.executeCommand("{ buildInfo: 1 }");
mongoVersion = Version.parse(result.get("version").toString());
}
}
@After
public void cleanUp() {
cleanDb();
@@ -310,10 +297,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1391
@MongoVersion(asOf = "3.2")
public void shouldUnwindWithIndex() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO));
MongoCollection<Document> coll = mongoTemplate.getCollection(INPUT_COLLECTION);
coll.insertOne(createDocument("Doc1", "spring", "mongodb", "nosql"));
@@ -338,10 +324,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1391
@MongoVersion(asOf = "3.2")
public void shouldUnwindPreserveEmpty() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO));
MongoCollection<Document> coll = mongoTemplate.getCollection(INPUT_COLLECTION);
coll.insertOne(createDocument("Doc1", "spring", "mongodb", "nosql"));
@@ -957,10 +942,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-774
@MongoVersion(asOf = "2.4")
public void stringExpressionsInProjectionExample() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(TWO_DOT_FOUR));
Product product = new Product("P1", "A", 1.99, 3, 0.05, 0.19);
mongoTemplate.insert(product);
@@ -1073,10 +1057,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-774
@MongoVersion(asOf = "2.4")
public void shouldPerformDateProjectionOperatorsCorrectly() throws ParseException {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(TWO_DOT_FOUR));
Data data = new Data();
data.stringValue = "ABC";
mongoTemplate.insert(data);
@@ -1102,10 +1085,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-774
@MongoVersion(asOf = "2.4")
public void shouldPerformStringProjectionOperatorsCorrectly() throws ParseException {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(TWO_DOT_FOUR));
Data data = new Data();
data.dateValue = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSSZ").parse("29.08.1983 12:34:56.789+0000");
mongoTemplate.insert(data);
@@ -1141,10 +1123,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1550
@MongoVersion(asOf = "3.4")
public void shouldPerformReplaceRootOperatorCorrectly() throws ParseException {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_FOUR));
Data data = new Data();
DataItem dataItem = new DataItem();
dataItem.primitiveIntValue = 42;
@@ -1290,10 +1271,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-960
@MongoVersion(asOf = "2.6")
public void returnFiveMostCommonLikesAggregationFrameworkExampleWithSortOnDiskOptionEnabled() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(TWO_DOT_SIX));
createUserWithLikesDocuments();
TypedAggregation<UserWithLikes> agg = createUsersWithCommonLikesAggregation() //
@@ -1315,10 +1295,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1637
@MongoVersion(asOf = "2.6")
public void returnFiveMostCommonLikesAggregationFrameworkExampleWithSortOnDiskOptionEnabledWhileStreaming() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(TWO_DOT_SIX));
createUserWithLikesDocuments();
TypedAggregation<UserWithLikes> agg = createUsersWithCommonLikesAggregation() //
@@ -1343,10 +1322,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-960
@MongoVersion(asOf = "2.6")
public void returnFiveMostCommonLikesShouldReturnStageExecutionInformationWithExplainOptionEnabled() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(TWO_DOT_SIX));
createUserWithLikesDocuments();
TypedAggregation<UserWithLikes> agg = createUsersWithCommonLikesAggregation() //
@@ -1364,10 +1342,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-954
@MongoVersion(asOf = "2.6")
public void shouldSupportReturningCurrentAggregationRoot() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(TWO_DOT_SIX));
mongoTemplate.save(new Person("p1_first", "p1_last", 25));
mongoTemplate.save(new Person("p2_first", "p2_last", 32));
mongoTemplate.save(new Person("p3_first", "p3_last", 25));
@@ -1391,10 +1368,9 @@ public class AggregationTests {
* {@link http://stackoverflow.com/questions/24185987/using-root-inside-spring-data-mongodb-for-retrieving-whole-document}
*/
@Test // DATAMONGO-954
@MongoVersion(asOf = "2.6")
public void shouldSupportReturningCurrentAggregationRootInReference() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(TWO_DOT_SIX));
mongoTemplate.save(new Reservation("0123", "42", 100));
mongoTemplate.save(new Reservation("0360", "43", 200));
mongoTemplate.save(new Reservation("0360", "44", 300));
@@ -1412,10 +1388,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1549
@MongoVersion(asOf = "3.4")
public void shouldApplyCountCorrectly() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_FOUR));
mongoTemplate.save(new Reservation("0123", "42", 100));
mongoTemplate.save(new Reservation("0360", "43", 200));
mongoTemplate.save(new Reservation("0360", "44", 300));
@@ -1526,10 +1501,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1326
@MongoVersion(asOf = "3.2")
public void shouldLookupPeopleCorectly() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO));
createUsersWithReferencedPersons();
TypedAggregation<User> agg = newAggregation(User.class, //
@@ -1547,10 +1521,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1326
@MongoVersion(asOf = "3.2")
public void shouldGroupByAndLookupPeopleCorectly() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO));
createUsersWithReferencedPersons();
TypedAggregation<User> agg = newAggregation(User.class, //
@@ -1569,10 +1542,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1418, DATAMONGO-1824
@MongoVersion(asOf = "2.6")
public void shouldCreateOutputCollection() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(TWO_DOT_SIX));
createPersonDocuments();
String tempOutCollection = "personQueryTemp";
@@ -1595,10 +1567,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1637
@MongoVersion(asOf = "2.6")
public void shouldCreateOutputCollectionWhileStreaming() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(TWO_DOT_SIX));
createPersonDocuments();
String tempOutCollection = "personQueryTemp";
@@ -1619,10 +1590,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1637
@MongoVersion(asOf = "2.6")
public void shouldReturnDocumentsWithOutputCollectionWhileStreaming() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(TWO_DOT_SIX));
createPersonDocuments();
String tempOutCollection = "personQueryTemp";
@@ -1661,10 +1631,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1325
@MongoVersion(asOf = "3.2")
public void shouldApplySampleCorrectly() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO));
createUserWithLikesDocuments();
TypedAggregation<UserWithLikes> agg = newAggregation(UserWithLikes.class, //
@@ -1679,10 +1648,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1457
@MongoVersion(asOf = "3.2")
public void sliceShouldBeAppliedCorrectly() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO));
createUserWithLikesDocuments();
TypedAggregation<UserWithLikes> agg = newAggregation(UserWithLikes.class, match(new Criteria()),
@@ -1697,10 +1665,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1491
@MongoVersion(asOf = "3.2")
public void filterShouldBeAppliedCorrectly() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO));
Item item43 = Item.builder().itemId("43").quantity(2).price(2L).build();
Item item2 = Item.builder().itemId("2").quantity(1).price(240L).build();
Sales sales1 = Sales.builder().id("0")
@@ -1730,10 +1697,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1538
@MongoVersion(asOf = "3.2")
public void letShouldBeAppliedCorrectly() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO));
Sales2 sales1 = Sales2.builder().id("1").price(10).tax(0.5F).applyDiscount(true).build();
Sales2 sales2 = Sales2.builder().id("2").price(10).tax(0.25F).applyDiscount(false).build();
@@ -1756,10 +1722,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1551
@MongoVersion(asOf = "3.4")
public void graphLookupShouldBeAppliedCorrectly() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_FOUR));
Employee em1 = Employee.builder().id(1).name("Dev").build();
Employee em2 = Employee.builder().id(2).name("Eliot").reportsTo("Dev").build();
Employee em4 = Employee.builder().id(4).name("Andrew").reportsTo("Eliot").build();
@@ -1787,10 +1752,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1552
@MongoVersion(asOf = "3.4")
public void bucketShouldCollectDocumentsIntoABucket() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_FOUR));
Art a1 = Art.builder().id(1).title("The Pillars of Society").artist("Grosz").year(1926).price(199.99).build();
Art a2 = Art.builder().id(2).title("Melancholy III").artist("Munch").year(1902).price(280.00).build();
Art a3 = Art.builder().id(3).title("Dancer").artist("Miro").year(1925).price(76.04).build();
@@ -1824,10 +1788,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1552
@MongoVersion(asOf = "3.4")
public void bucketAutoShouldCollectDocumentsIntoABucket() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_FOUR));
Art a1 = Art.builder().id(1).title("The Pillars of Society").artist("Grosz").year(1926).price(199.99).build();
Art a2 = Art.builder().id(2).title("Melancholy III").artist("Munch").year(1902).price(280.00).build();
Art a3 = Art.builder().id(3).title("Dancer").artist("Miro").year(1925).price(76.04).build();
@@ -1858,10 +1821,9 @@ public class AggregationTests {
}
@Test // DATAMONGO-1552
@MongoVersion(asOf = "3.4")
public void facetShouldCreateFacets() {
assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_FOUR));
Art a1 = Art.builder().id(1).title("The Pillars of Society").artist("Grosz").year(1926).price(199.99).build();
Art a2 = Art.builder().id(2).title("Melancholy III").artist("Munch").year(1902).price(280.00).build();
Art a3 = Art.builder().id(3).title("Dancer").artist("Miro").year(1925).price(76.04).build();