DATACMNS-345 - Use the actual type of the persistent property.

Changed getPersistentEntity(PersistentProperty<?>) to return the actual type of the persistent property in order to deal with collection and map types transparently.

Original pull request: #31.
This commit is contained in:
Thomas Darimont
2013-07-16 12:00:50 +02:00
committed by Oliver Gierke
parent 634789c3b7
commit 2afb570729
2 changed files with 22 additions and 9 deletions

View File

@@ -21,6 +21,7 @@ import static org.mockito.Mockito.*;
import groovy.lang.MetaClass;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
@@ -144,7 +145,7 @@ public class AbstractMappingContextUnitTests {
}
/**
* @see DATACMNS-???
* @see DATACMNS-332
*/
@Test
public void usesMostConcreteProperty() {
@@ -154,6 +155,22 @@ public class AbstractMappingContextUnitTests {
assertThat(entity.getPersistentProperty("foo").isIdProperty(), is(true));
}
/**
* @see DATACMNS-345
*/
@Test
@SuppressWarnings("rawtypes")
public void returnsEntityForComponentType() {
SampleMappingContext mappingContext = new SampleMappingContext();
PersistentEntity<Object, SamplePersistentProperty> entity = mappingContext.getPersistentEntity(Sample.class);
SamplePersistentProperty property = entity.getPersistentProperty("persons");
PersistentEntity<Object, SamplePersistentProperty> propertyEntity = mappingContext.getPersistentEntity(property);
assertThat(propertyEntity, is(notNullValue()));
assertThat(propertyEntity.getType(), is(equalTo((Class) Person.class)));
}
class Person {
String name;
}
@@ -165,6 +182,7 @@ public class AbstractMappingContextUnitTests {
class Sample {
MetaClass metaClass;
List<Person> persons;
}
static class Base {
@@ -172,7 +190,6 @@ public class AbstractMappingContextUnitTests {
}
static class Extension extends Base {
@Id
String foo;
@Id String foo;
}
}