Search in sources :

Example 11 with SamplePersistentProperty

use of org.springframework.data.mapping.context.SamplePersistentProperty in project spring-data-commons by spring-projects.

the class PersistentEntityInformationUnitTests method returnsNullIfNoIdPropertyPresent.

// DATACMNS-596
@Test
public void returnsNullIfNoIdPropertyPresent() {
    SampleMappingContext context = new SampleMappingContext();
    PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(EntityWithoutId.class);
    PersistentEntityInformation<Object, Serializable> information = new PersistentEntityInformation<>(entity);
    assertThat(information.getId(new EntityWithoutId())).isNull();
}
Also used : Serializable(java.io.Serializable) SamplePersistentProperty(org.springframework.data.mapping.context.SamplePersistentProperty) SampleMappingContext(org.springframework.data.mapping.context.SampleMappingContext) Test(org.junit.Test)

Example 12 with SamplePersistentProperty

use of org.springframework.data.mapping.context.SamplePersistentProperty 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));
}
Also used : PersistentEntity(org.springframework.data.mapping.PersistentEntity) SamplePersistentProperty(org.springframework.data.mapping.context.SamplePersistentProperty) SampleMappingContext(org.springframework.data.mapping.context.SampleMappingContext) Test(org.junit.Test)

Aggregations

SamplePersistentProperty (org.springframework.data.mapping.context.SamplePersistentProperty)12 Test (org.junit.Test)11 SampleMappingContext (org.springframework.data.mapping.context.SampleMappingContext)11 PersistentEntity (org.springframework.data.mapping.PersistentEntity)3 PersistentPropertyAccessor (org.springframework.data.mapping.PersistentPropertyAccessor)2 Serializable (java.io.Serializable)1 Map (java.util.Map)1 CreatedBy (org.springframework.data.annotation.CreatedBy)1