use of org.springframework.data.projection.EntityProjectionIntrospector in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method projectShouldReadNestedProjection.
// GH-2860
@Test
void projectShouldReadNestedProjection() {
org.bson.Document source = new org.bson.Document("addresses", Collections.singletonList(new org.bson.Document("s", "hwy")));
EntityProjectionIntrospector introspector = EntityProjectionIntrospector.create(converter.getProjectionFactory(), EntityProjectionIntrospector.ProjectionPredicate.typeHierarchy().and((target, underlyingType) -> !converter.conversions.isSimpleType(target)), mappingContext);
EntityProjection<WithNestedProjection, Person> projection = introspector.introspect(WithNestedProjection.class, Person.class);
WithNestedProjection person = converter.project(projection, source);
assertThat(person.getAddresses()).extracting(AddressProjection::getStreet).hasSize(1).containsOnly("hwy");
}
use of org.springframework.data.projection.EntityProjectionIntrospector in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method projectShouldReadSimpleDtoProjection.
// GH-2860
@Test
void projectShouldReadSimpleDtoProjection() {
org.bson.Document source = new org.bson.Document("birthDate", new LocalDate(1999, 12, 1).toDate()).append("foo", "Walter");
EntityProjectionIntrospector introspector = EntityProjectionIntrospector.create(converter.getProjectionFactory(), EntityProjectionIntrospector.ProjectionPredicate.typeHierarchy().and((target, underlyingType) -> !converter.conversions.isSimpleType(target)), mappingContext);
EntityProjection<PersonDto, Person> projection = introspector.introspect(PersonDto.class, Person.class);
PersonDto person = converter.project(projection, source);
assertThat(person.getBirthDate()).isEqualTo(new LocalDate(1999, 12, 1));
assertThat(person.getFirstname()).isEqualTo("Walter");
}
use of org.springframework.data.projection.EntityProjectionIntrospector in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method projectShouldReadProjectionWithNestedEntity.
// GH-2860
@Test
void projectShouldReadProjectionWithNestedEntity() {
org.bson.Document source = new org.bson.Document("addresses", Collections.singletonList(new org.bson.Document("s", "hwy")));
EntityProjectionIntrospector introspector = EntityProjectionIntrospector.create(converter.getProjectionFactory(), EntityProjectionIntrospector.ProjectionPredicate.typeHierarchy().and((target, underlyingType) -> !converter.conversions.isSimpleType(target)), mappingContext);
EntityProjection<ProjectionWithNestedEntity, Person> projection = introspector.introspect(ProjectionWithNestedEntity.class, Person.class);
ProjectionWithNestedEntity person = converter.project(projection, source);
assertThat(person.getAddresses()).extracting(Address::getStreet).hasSize(1).containsOnly("hwy");
}
use of org.springframework.data.projection.EntityProjectionIntrospector in project spring-data-mongodb by spring-projects.
the class MappingMongoConverterUnitTests method projectShouldReadSimpleInterfaceProjection.
// GH-2860
@Test
void projectShouldReadSimpleInterfaceProjection() {
org.bson.Document source = new org.bson.Document("birthDate", new LocalDate(1999, 12, 1).toDate()).append("foo", "Walter");
EntityProjectionIntrospector discoverer = EntityProjectionIntrospector.create(converter.getProjectionFactory(), EntityProjectionIntrospector.ProjectionPredicate.typeHierarchy().and((target, underlyingType) -> !converter.conversions.isSimpleType(target)), mappingContext);
EntityProjection<PersonProjection, Person> projection = discoverer.introspect(PersonProjection.class, Person.class);
PersonProjection person = converter.project(projection, source);
assertThat(person.getBirthDate()).isEqualTo(new LocalDate(1999, 12, 1));
assertThat(person.getFirstname()).isEqualTo("Walter");
}
Aggregations