@ -1409,18 +1409,21 @@ public class MongoTemplateTests {
assertThat ( result . get ( 0 ) . field ) . isEqualTo ( "Beauford" ) ;
assertThat ( result . get ( 0 ) . field ) . isEqualTo ( "Beauford" ) ;
}
}
@Test // DATAMONGO-447
@Test // DATAMONGO-447, GH-4707
public void storesAndRemovesTypeWithComplexId ( ) {
public void storesAndRemovesTypeWithComplexId ( ) {
MyId id = new MyId ( ) ;
MyId id = new MyId ( ) ;
id . id = Instant . now ( ) . minusSeconds ( 2 ) ;
id . first = "foo" ;
id . first = "foo" ;
id . second = "bar" ;
id . second = "bar" ;
id . time = Instant . now ( ) . minusSeconds ( 3 ) ;
TypeWithMyId source = new TypeWithMyId ( ) ;
TypeWithMyId source = new TypeWithMyId ( ) ;
source . id = id ;
source . id = id ;
template . save ( source ) ;
template . save ( source ) ;
template . remove ( query ( where ( "id" ) . is ( id ) ) , TypeWithMyId . class ) ;
assertThat ( template . remove ( query ( where ( "id" ) . is ( id ) ) , TypeWithMyId . class ) ) . extracting ( DeleteResult : : getDeletedCount )
. isEqualTo ( 1L ) ;
}
}
@Test // DATAMONGO-506
@Test // DATAMONGO-506
@ -2554,6 +2557,29 @@ public class MongoTemplateTests {
assertThat ( projection . getName ( ) ) . isEqualTo ( "Walter" ) ;
assertThat ( projection . getName ( ) ) . isEqualTo ( "Walter" ) ;
}
}
@Test // GH-4707
public void findAndReplaceUpsertsObjectWithComplexId ( ) {
MyId id = new MyId ( ) ;
id . id = Instant . now ( ) . minusSeconds ( 2 ) ;
id . first = "foo" ;
id . second = "bar" ;
id . time = Instant . now ( ) . minusSeconds ( 3 ) ;
TypeWithMyId replacement = new TypeWithMyId ( ) ;
replacement . value = "spring" ;
template . findAndReplace ( query ( where ( "id" ) . is ( id ) ) , replacement , FindAndReplaceOptions . options ( ) . upsert ( ) ) ;
template . doInCollection ( TypeWithMyId . class , collection - > {
org . bson . Document dbValue = collection . find ( new org . bson . Document ( "_id.first" , "foo" ) ) . first ( ) ;
assertThat ( dbValue ) . isNotNull ( ) ;
assertThat ( dbValue . getEmbedded ( List . of ( "_id" , "_id" ) , Object . class ) ) . isInstanceOf ( Date . class ) ;
assertThat ( dbValue . getEmbedded ( List . of ( "_id" , "t" ) , Object . class ) ) . isInstanceOf ( Date . class ) ;
} ) ;
}
@Test // GH-4609
@Test // GH-4609
public void shouldReadNestedProjection ( ) {
public void shouldReadNestedProjection ( ) {
@ -4397,11 +4423,15 @@ public class MongoTemplateTests {
String first ;
String first ;
String second ;
String second ;
Instant time ;
@Field ( "t" ) Instant time ;
}
}
static class TypeWithMyId {
static class TypeWithMyId {
@Id MyId id ;
@Id MyId id ;
String value ;
}
}
static class Sample {
static class Sample {