Search in sources :

Example 6 with SamplePersistentProperty

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

the class BasicPersistentEntityUnitTests method rejectsNullBeanForPropertyAccessor.

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

Example 7 with SamplePersistentProperty

use of org.springframework.data.mapping.context.SamplePersistentProperty 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);
}
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 8 with SamplePersistentProperty

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

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

use of org.springframework.data.mapping.context.SamplePersistentProperty 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)

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