Browse Source

DATAMONGO-485 - Added test case to show complex id's are working.

1.0.x
Oliver Gierke 14 years ago
parent
commit
c7995eb462
  1. 46
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java

46
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java

@ -1059,6 +1059,42 @@ public class MappingMongoConverterUnitTests { @@ -1059,6 +1059,42 @@ public class MappingMongoConverterUnitTests {
assertThat(sink.get("url"), is((Object) "http://springsource.org"));
}
/**
* @see DATAMONGO-485
*/
@Test
public void writesComplexIdCorrectly() {
ComplexId id = new ComplexId();
id.innerId = 4711L;
ClassWithComplexId entity = new ClassWithComplexId();
entity.complexId = id;
DBObject dbObject = new BasicDBObject();
converter.write(entity, dbObject);
Object idField = dbObject.get("_id");
assertThat(idField, is(notNullValue()));
assertThat(idField, is(instanceOf(DBObject.class)));
assertThat(((DBObject) idField).get("innerId"), is((Object) 4711L));
}
/**
* @see DATAMONGO-485
*/
@Test
public void readsComplexIdCorrectly() {
DBObject innerId = new BasicDBObject("innerId", 4711L);
DBObject entity = new BasicDBObject("_id", innerId);
ClassWithComplexId result = converter.read(ClassWithComplexId.class, entity);
assertThat(result.complexId, is(notNullValue()));
assertThat(result.complexId.innerId, is(4711L));
}
static class GenericType<T> {
T content;
}
@ -1194,6 +1230,16 @@ public class MappingMongoConverterUnitTests { @@ -1194,6 +1230,16 @@ public class MappingMongoConverterUnitTests {
URL url;
}
static class ClassWithComplexId {
@Id
ComplexId complexId;
}
static class ComplexId {
Long innerId;
}
private class LocalDateToDateConverter implements Converter<LocalDate, Date> {
public Date convert(LocalDate source) {

Loading…
Cancel
Save