use of org.springframework.data.mapping.PersistentEntity in project spring-data-commons by spring-projects.
the class BasicPersistentEntityUnitTests method returnsBeanWrapperForPropertyAccessor.
// DATACMNS-596
@Test
public void returnsBeanWrapperForPropertyAccessor() {
assumeThat(System.getProperty("java.version"), CoreMatchers.startsWith("1.6"));
SampleMappingContext context = new SampleMappingContext();
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
Entity value = new Entity();
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(value);
assertThat(accessor).isInstanceOf(BeanWrapper.class);
assertThat(accessor.getBean()).isEqualTo(value);
}
use of org.springframework.data.mapping.PersistentEntity in project spring-data-commons by spring-projects.
the class ClassGeneratingPropertyAccessorFactory method hasUniquePropertyHashCodes.
private boolean hasUniquePropertyHashCodes(PersistentEntity<?, ?> entity) {
Set<Integer> hashCodes = new HashSet<>();
AtomicInteger propertyCount = new AtomicInteger();
entity.doWithProperties((SimplePropertyHandler) property -> {
hashCodes.add(property.getName().hashCode());
propertyCount.incrementAndGet();
});
entity.doWithAssociations((SimpleAssociationHandler) association -> {
if (association.getInverse() != null) {
hashCodes.add(association.getInverse().getName().hashCode());
propertyCount.incrementAndGet();
}
});
return hashCodes.size() == propertyCount.get();
}
use of org.springframework.data.mapping.PersistentEntity in project spring-data-commons by spring-projects.
the class BasicPersistentEntityUnitTests method returnsGeneratedPropertyAccessorForPropertyAccessor.
// DATACMNS-809
@Test
public void returnsGeneratedPropertyAccessorForPropertyAccessor() {
SampleMappingContext context = new SampleMappingContext();
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
Entity value = new Entity();
PersistentPropertyAccessor accessor = entity.getPropertyAccessor(value);
assertThat(accessor).isNotInstanceOf(BeanWrapper.class);
assertThat(accessor.getClass().getName()).contains("_Accessor_");
assertThat(accessor.getBean()).isEqualTo(value);
}
use of org.springframework.data.mapping.PersistentEntity in project spring-data-commons by spring-projects.
the class MappingContextTypeInformationMapperUnitTests method detectsTypeForUnknownEntity.
@Test
public void detectsTypeForUnknownEntity() {
SampleMappingContext mappingContext = new SampleMappingContext();
mappingContext.initialize();
mapper = new MappingContextTypeInformationMapper(mappingContext);
assertThat(mapper.resolveTypeFrom(Alias.of("foo"))).isNull();
PersistentEntity<?, SamplePersistentProperty> entity = mappingContext.getRequiredPersistentEntity(Entity.class);
assertThat(entity).isNotNull();
assertThat(mapper.resolveTypeFrom(Alias.of("foo"))).isEqualTo(from(Entity.class));
}
Aggregations