Search in sources :

Example 11 with SampleMappingContext

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

the class BasicPersistentEntityUnitTests method rejectsNonMatchingBeanForPropertyAccessor.

// DATACMNS-596
@Test(expected = IllegalArgumentException.class)
public void rejectsNonMatchingBeanForPropertyAccessor() {
    SampleMappingContext context = new SampleMappingContext();
    PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
    entity.getPropertyAccessor("foo");
}
Also used : SamplePersistentProperty(org.springframework.data.mapping.context.SamplePersistentProperty) SampleMappingContext(org.springframework.data.mapping.context.SampleMappingContext) Test(org.junit.Test)

Example 12 with SampleMappingContext

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

the class BasicPersistentEntityUnitTests method reportsRequiredPropertyName.

// DATACMNS-1122
@Test
public void reportsRequiredPropertyName() {
    SampleMappingContext context = new SampleMappingContext();
    PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
    assertThatThrownBy(() -> entity.getRequiredPersistentProperty("foo")).hasMessageContaining("Required property foo not found");
}
Also used : SamplePersistentProperty(org.springframework.data.mapping.context.SamplePersistentProperty) SampleMappingContext(org.springframework.data.mapping.context.SampleMappingContext) Test(org.junit.Test)

Example 13 with SampleMappingContext

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

the class PersistentEntityInformationUnitTests method obtainsIdAndIdTypeInformationFromPersistentEntity.

// DATACMNS-480
@Test
public void obtainsIdAndIdTypeInformationFromPersistentEntity() {
    SampleMappingContext context = new SampleMappingContext();
    PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Sample.class);
    EntityInformation<Object, Long> information = new PersistentEntityInformation<>(entity);
    assertThat(information.getIdType()).isEqualTo(Long.class);
    Sample sample = new Sample();
    sample.id = 5L;
    assertThat(information.getId(sample)).isEqualTo(5L);
}
Also used : SamplePersistentProperty(org.springframework.data.mapping.context.SamplePersistentProperty) SampleMappingContext(org.springframework.data.mapping.context.SampleMappingContext) Test(org.junit.Test)

Example 14 with SampleMappingContext

use of org.springframework.data.mapping.context.SampleMappingContext 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 15 with SampleMappingContext

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

the class MappingContextTypeInformationMapperUnitTests method createsTypeMapperForGenericTypesWithDifferentBindings.

// DATACMNS-485
@Test
@SuppressWarnings("unchecked")
public void createsTypeMapperForGenericTypesWithDifferentBindings() {
    AnnotatedTypeScanner scanner = new AnnotatedTypeScanner(TypeAlias.class);
    SampleMappingContext context = new SampleMappingContext();
    context.setInitialEntitySet(scanner.findTypes(getClass().getPackage().getName()));
    context.initialize();
    new MappingContextTypeInformationMapper(context);
}
Also used : AnnotatedTypeScanner(org.springframework.data.util.AnnotatedTypeScanner) SampleMappingContext(org.springframework.data.mapping.context.SampleMappingContext) Test(org.junit.Test)

Aggregations

SampleMappingContext (org.springframework.data.mapping.context.SampleMappingContext)16 Test (org.junit.Test)13 SamplePersistentProperty (org.springframework.data.mapping.context.SamplePersistentProperty)11 PersistentEntity (org.springframework.data.mapping.PersistentEntity)3 Before (org.junit.Before)2 PersistentPropertyAccessor (org.springframework.data.mapping.PersistentPropertyAccessor)2 Serializable (java.io.Serializable)1 CreatedBy (org.springframework.data.annotation.CreatedBy)1 PersistentEntities (org.springframework.data.mapping.context.PersistentEntities)1 AnnotatedTypeScanner (org.springframework.data.util.AnnotatedTypeScanner)1