@ -196,6 +196,7 @@ public class MongoTemplateTests {
@@ -196,6 +196,7 @@ public class MongoTemplateTests {
template . dropCollection ( SomeContent . class ) ;
template . dropCollection ( SomeTemplate . class ) ;
template . dropCollection ( Address . class ) ;
template . dropCollection ( DocumentWithCollectionOfSamples . class ) ;
}
@Test
@ -2210,11 +2211,12 @@ public class MongoTemplateTests {
@@ -2210,11 +2211,12 @@ public class MongoTemplateTests {
assertThat ( retrieved . model . value ( ) , equalTo ( "value2" ) ) ;
}
// Rewrite the whole collection
// Passes in 1.6.0+, but changes order position of type hint _class
/ * *
* @see DATAMONGO - 1210
* /
@Test
public void findAndModifyShouldRetainTypeInformationWithinUpdatedTypeOnDocumentWithNestedCollection ( )
{
public void findAndModifyShouldRetainTypeInformationWithinUpdatedTypeOnDocumentWithNestedCollectionWhenWholeCollectionIsReplaced ( ) {
DocumentWithNestedCollection doc = new DocumentWithNestedCollection ( ) ;
Map < String , Model > entry = new HashMap < String , Model > ( ) ;
@ -2246,12 +2248,12 @@ public class MongoTemplateTests {
@@ -2246,12 +2248,12 @@ public class MongoTemplateTests {
assertThat ( retrieved . models . get ( 0 ) . get ( "key2" ) . value ( ) , equalTo ( "value2" ) ) ;
}
// Update first list element
// Fails in 1.6.2+
/ * *
* @see DATAMONGO - 1210
* /
@Test
public void findAndModifyShouldRetainTypeInformationWithinUpdatedTypeOnDocumentWithNestedCollection2 ( )
{
public void findAndModifyShouldRetainTypeInformationWithinUpdatedTypeOnDocumentWithNestedCollectionWhenFirstElementIsReplaced ( ) {
DocumentWithNestedCollection doc = new DocumentWithNestedCollection ( ) ;
Map < String , Model > entry = new HashMap < String , Model > ( ) ;
@ -2283,11 +2285,12 @@ public class MongoTemplateTests {
@@ -2283,11 +2285,12 @@ public class MongoTemplateTests {
assertThat ( retrieved . models . get ( 0 ) . get ( "key2" ) . value ( ) , equalTo ( "value2" ) ) ;
}
// Add second list element
// Fails in 1.6.2+
/ * *
* @see DATAMONGO - 1210
* /
@Test
public void findAndModifyShouldAddTypeInformationOnDocumentWithNestedCollection2 ( )
{
public void findAndModifyShouldAddTypeInformationOnDocumentWithNestedCollectionObjectInsertedAtSecondIndex ( ) {
DocumentWithNestedCollection doc = new DocumentWithNestedCollection ( ) ;
Map < String , Model > entry = new HashMap < String , Model > ( ) ;
@ -2318,15 +2321,18 @@ public class MongoTemplateTests {
@@ -2318,15 +2321,18 @@ public class MongoTemplateTests {
assertThat ( retrieved . models . get ( 1 ) . get ( "key2" ) . value ( ) , equalTo ( "value2" ) ) ;
}
// Update the collection of the embedded document
// Fails in 1.6.0+
/ * *
* @see DATAMONGO - 1210
* /
@Test
public void findAndModifyShouldRetainTypeInformationWithinUpdatedTypeOnEmbeddedDocumentWithCollection ( ) throws Exception
{
public void findAndModifyShouldRetainTypeInformationWithinUpdatedTypeOnEmbeddedDocumentWithCollectionWhenUpdatingPositionedElement ( )
throws Exception {
List < Model > models = new ArrayList < Model > ( ) ;
models . add ( new ModelA ( "value1" ) ) ;
DocumentWithEmbeddedDocumentWithCollection doc = new DocumentWithEmbeddedDocumentWithCollection ( new DocumentWithCollection ( models ) ) ;
DocumentWithEmbeddedDocumentWithCollection doc = new DocumentWithEmbeddedDocumentWithCollection (
new DocumentWithCollection ( models ) ) ;
template . save ( doc ) ;
@ -2337,22 +2343,26 @@ public class MongoTemplateTests {
@@ -2337,22 +2343,26 @@ public class MongoTemplateTests {
template . findAndModify ( query , update , DocumentWithEmbeddedDocumentWithCollection . class ) ;
DocumentWithEmbeddedDocumentWithCollection retrieved = template . findOne ( query , DocumentWithEmbeddedDocumentWithCollection . class ) ;
DocumentWithEmbeddedDocumentWithCollection retrieved = template . findOne ( query ,
DocumentWithEmbeddedDocumentWithCollection . class ) ;
assertThat ( retrieved , notNullValue ( ) ) ;
assertThat ( retrieved . embeddedDocument . models , hasSize ( 1 ) ) ;
assertThat ( retrieved . embeddedDocument . models . get ( 0 ) . value ( ) , is ( "value2" ) ) ;
}
// Update the collection of the embedded document
// Fails in 1.6.0+
/ * *
* @see DATAMONGO - 1210
* /
@Test
public void findAndModifyShouldAddTypeInformationWithinUpdatedTypeOnEmbeddedDocumentWithCollection2 ( ) throws Exception
{
public void findAndModifyShouldAddTypeInformationWithinUpdatedTypeOnEmbeddedDocumentWithCollectionWhenUpdatingSecondElement ( )
throws Exception {
List < Model > models = new ArrayList < Model > ( ) ;
models . add ( new ModelA ( "value1" ) ) ;
DocumentWithEmbeddedDocumentWithCollection doc = new DocumentWithEmbeddedDocumentWithCollection ( new DocumentWithCollection ( models ) ) ;
DocumentWithEmbeddedDocumentWithCollection doc = new DocumentWithEmbeddedDocumentWithCollection (
new DocumentWithCollection ( models ) ) ;
template . save ( doc ) ;
@ -2363,7 +2373,8 @@ public class MongoTemplateTests {
@@ -2363,7 +2373,8 @@ public class MongoTemplateTests {
template . findAndModify ( query , update , DocumentWithEmbeddedDocumentWithCollection . class ) ;
DocumentWithEmbeddedDocumentWithCollection retrieved = template . findOne ( query , DocumentWithEmbeddedDocumentWithCollection . class ) ;
DocumentWithEmbeddedDocumentWithCollection retrieved = template . findOne ( query ,
DocumentWithEmbeddedDocumentWithCollection . class ) ;
assertThat ( retrieved , notNullValue ( ) ) ;
assertThat ( retrieved . embeddedDocument . models , hasSize ( 2 ) ) ;
@ -2371,35 +2382,42 @@ public class MongoTemplateTests {
@@ -2371,35 +2382,42 @@ public class MongoTemplateTests {
assertThat ( retrieved . embeddedDocument . models . get ( 1 ) . value ( ) , is ( "value2" ) ) ;
}
// Rewrite the embedded document
// Fails in 1.6.0+
/ * *
* @see DATAMONGO - 1210
* /
@Test
public void findAndModifyShouldAddTypeInformationWithinUpdatedTypeOnEmbeddedDocumentWithCollection3 ( ) throws Exception
{
List < Model > models = Arrays . < Model > asList ( new ModelA ( "value1" ) ) ;
public void findAndModifyShouldAddTypeInformationWithinUpdatedTypeOnEmbeddedDocumentWithCollectionWhenRewriting ( )
throws Exception {
List < Model > models = Arrays . < Model > asList ( new ModelA ( "value1" ) ) ;
DocumentWithEmbeddedDocumentWithCollection doc = new DocumentWithEmbeddedDocumentWithCollection ( new DocumentWithCollection ( models ) ) ;
DocumentWithEmbeddedDocumentWithCollection doc = new DocumentWithEmbeddedDocumentWithCollection (
new DocumentWithCollection ( models ) ) ;
template . save ( doc ) ;
Query query = query ( where ( "id" ) . is ( doc . id ) ) ;
Update update = Update . update ( "embeddedDocument" , new DocumentWithCollection ( Arrays . < Model > asList ( new ModelA ( "value2" ) ) ) ) ;
Update update = Update . update ( "embeddedDocument" ,
new DocumentWithCollection ( Arrays . < Model > asList ( new ModelA ( "value2" ) ) ) ) ;
assertThat ( template . findOne ( query , DocumentWithEmbeddedDocumentWithCollection . class ) , notNullValue ( ) ) ;
template . findAndModify ( query , update , DocumentWithEmbeddedDocumentWithCollection . class ) ;
DocumentWithEmbeddedDocumentWithCollection retrieved = template . findOne ( query , DocumentWithEmbeddedDocumentWithCollection . class ) ;
DocumentWithEmbeddedDocumentWithCollection retrieved = template . findOne ( query ,
DocumentWithEmbeddedDocumentWithCollection . class ) ;
assertThat ( retrieved , notNullValue ( ) ) ;
assertThat ( retrieved . embeddedDocument . models , hasSize ( 1 ) ) ;
assertThat ( retrieved . embeddedDocument . models . get ( 0 ) . value ( ) , is ( "value2" ) ) ;
}
// Fails in 1.6.0+
/ * *
* @see DATAMONGO - 1210
* /
@Test
public void findAndModifyShouldAddTypeInformationWithinUpdatedTypeOnDocumentWithNestedLists ( )
{
public void findAndModifyShouldAddTypeInformationWithinUpdatedTypeOnDocumentWithNestedLists ( ) {
DocumentWithNestedList doc = new DocumentWithNestedList ( ) ;
List < Model > entry = new ArrayList < Model > ( ) ;
@ -2835,8 +2853,12 @@ public class MongoTemplateTests {
@@ -2835,8 +2853,12 @@ public class MongoTemplateTests {
assertThat ( template . findOne ( query , DocumentWithCollectionOfSimpleType . class ) . values , hasSize ( 3 ) ) ;
}
/ * *
* @see DATAMONGO - 1210
* /
@Test
public void findAndModifyAddToSetWithEachShouldNotAddDuplicatesNorTypeHintForSimpleDocuments ( ) {
DocumentWithCollectionOfSamples doc = new DocumentWithCollectionOfSamples ( ) ;
doc . samples = Arrays . asList ( new Sample ( null , "sample1" ) ) ;
@ -2846,7 +2868,7 @@ public class MongoTemplateTests {
@@ -2846,7 +2868,7 @@ public class MongoTemplateTests {
assertThat ( template . findOne ( query , DocumentWithCollectionOfSamples . class ) , notNullValue ( ) ) ;
Update update = new Update ( ) . addToSet ( "samples" ) . each ( Arrays . asList ( new Sample ( null , "sample2" ) , new Sample ( null , "sample1" ) ) ) ;
Update update = new Update ( ) . addToSet ( "samples" ) . each ( new Sample ( null , "sample2" ) , new Sample ( null , "sample1" ) ) ;
template . findAndModify ( query , update , DocumentWithCollectionOfSamples . class ) ;
@ -3102,8 +3124,7 @@ public class MongoTemplateTests {
@@ -3102,8 +3124,7 @@ public class MongoTemplateTests {
List < String > values ;
}
static class DocumentWithCollectionOfSamples
{
static class DocumentWithCollectionOfSamples {
@Id String id ;
List < Sample > samples ;
}
@ -3114,25 +3135,21 @@ public class MongoTemplateTests {
@@ -3114,25 +3135,21 @@ public class MongoTemplateTests {
List < String > string2 ;
}
static class DocumentWithNestedCollection
{
static class DocumentWithNestedCollection {
@Id String id ;
List < Map < String , Model > > models = new ArrayList < Map < String , Model > > ( ) ;
}
static class DocumentWithNestedList
{
static class DocumentWithNestedList {
@Id String id ;
List < List < Model > > models = new ArrayList < List < Model > > ( ) ;
}
}
static class DocumentWithEmbeddedDocumentWithCollection
{
static class DocumentWithEmbeddedDocumentWithCollection {
@Id String id ;
DocumentWithCollection embeddedDocument ;
DocumentWithEmbeddedDocumentWithCollection ( DocumentWithCollection embeddedDocument )
{
DocumentWithEmbeddedDocumentWithCollection ( DocumentWithCollection embeddedDocument ) {
this . embeddedDocument = embeddedDocument ;
}
}