Search in sources :

Example 1 with SamplePersistentProperty

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

the class ConvertingPropertyAccessorUnitTests method getIdProperty.

private static SamplePersistentProperty getIdProperty() {
    SampleMappingContext mappingContext = new SampleMappingContext();
    BasicPersistentEntity<Object, SamplePersistentProperty> entity = mappingContext.getRequiredPersistentEntity(Entity.class);
    return entity.getPersistentProperty("id");
}
Also used : SamplePersistentProperty(org.springframework.data.mapping.context.SamplePersistentProperty) SampleMappingContext(org.springframework.data.mapping.context.SampleMappingContext)

Example 2 with SamplePersistentProperty

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

the class BasicPersistentEntityUnitTests method detectsPropertyWithAnnotation.

// DATACMNS-365
@Test
public void detectsPropertyWithAnnotation() {
    SampleMappingContext context = new SampleMappingContext();
    PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
    SamplePersistentProperty property = entity.getPersistentProperty(LastModifiedBy.class);
    assertThat(property.getName()).isEqualTo("field");
    property = entity.getPersistentProperty(CreatedBy.class);
    assertThat(property.getName()).isEqualTo("property");
    assertThat(entity.getPersistentProperty(CreatedDate.class)).isNull();
}
Also used : CreatedBy(org.springframework.data.annotation.CreatedBy) SamplePersistentProperty(org.springframework.data.mapping.context.SamplePersistentProperty) SampleMappingContext(org.springframework.data.mapping.context.SampleMappingContext) Test(org.junit.Test)

Example 3 with SamplePersistentProperty

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

the class BasicPersistentEntityUnitTests method supportsSubtypeInstancesOnPropertyAccessorLookup.

// DATACMNS-597
@Test
public void supportsSubtypeInstancesOnPropertyAccessorLookup() {
    SampleMappingContext context = new SampleMappingContext();
    PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Entity.class);
    assertThat(entity.getPropertyAccessor(new Subtype())).isNotNull();
}
Also used : SamplePersistentProperty(org.springframework.data.mapping.context.SamplePersistentProperty) SampleMappingContext(org.springframework.data.mapping.context.SampleMappingContext) Test(org.junit.Test)

Example 4 with SamplePersistentProperty

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

Example 5 with SamplePersistentProperty

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

the class AnnotationBasedPersistentPropertyUnitTests method cachesNonPresenceOfAnnotationOnField.

// DATACMNS-677
@Test
@SuppressWarnings("unchecked")
public void cachesNonPresenceOfAnnotationOnField() {
    SamplePersistentProperty property = getProperty(Sample.class, "getterWithoutField");
    assertThat(property).satisfies(it -> {
        assertThat(it.findAnnotation(MyAnnotation.class)).isNull();
        Map<Class<?>, ?> field = (Map<Class<?>, ?>) ReflectionTestUtils.getField(it, "annotationCache");
        assertThat(field.containsKey(MyAnnotation.class)).isTrue();
        assertThat(field.get(MyAnnotation.class)).isEqualTo(Optional.empty());
    });
}
Also used : SamplePersistentProperty(org.springframework.data.mapping.context.SamplePersistentProperty) Map(java.util.Map) 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