use of org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testAttribute_getAttribute_of_TransientNonEntityNonMappedSuperclass_SuperclassOfEntity_throws_IAE.
// Test that we are getting an Illegal argument exception when trying to access non-persistent fields from transient classes
public void testAttribute_getAttribute_of_TransientNonEntityNonMappedSuperclass_SuperclassOfEntity_throws_IAE() {
EntityManager em = null;
boolean exceptionThrown = false;
try {
em = privateTestSetup();
assertNotNull(em);
Metamodel metamodel = em.getMetamodel();
assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
// Verify that the non-Entity/non-MappedSuperclass is a BasicType
Type positionNonEntity = ((MetamodelImpl) metamodel).getType(Position.class);
assertNotNull(positionNonEntity);
assertEquals(Type.PersistenceType.BASIC, positionNonEntity.getPersistenceType());
// Get direct inheriting subclass
EntityTypeImpl<GalacticPosition> entityLocation_ = (EntityTypeImpl) metamodel.entity(GalacticPosition.class);
assertNotNull(entityLocation_);
// We will be testing that the non-persistent fields
Attribute anAttributeThatShouldNotHaveBeenInherited = entityLocation_.getAttribute("nonPersistentObject");
// we should never get to the following line - go directly to catch block
assertTrue("IllegalArgumentException expected on transient type attribute should not be in subclass for managedType.getAttribute()", exceptionThrown);
} catch (IllegalArgumentException iae) {
// iae.printStackTrace();
exceptionThrown = true;
assertTrue("IllegalArgumentException expected on transient type attribute should not be in subclass for managedType.getAttribute()", exceptionThrown);
} finally {
cleanup(em);
}
}
use of org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testMapAttribute_getKeyType_294811_UC12_DI86_Embedded_keyType_Method.
// This test verifies the workaround for 294811
public void testMapAttribute_getKeyType_294811_UC12_DI86_Embedded_keyType_Method() {
EntityManager em = null;
boolean exceptionThrown = false;
try {
em = privateTestSetup();
assertNotNull(em);
Metamodel metamodel = em.getMetamodel();
assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl) metamodel.entity(Computer.class);
assertNotNull(entityComputer_);
// Actual Test Case
/**
* Return the type representing the key type of the map.
* @return type representing key type
*/
// Type<K> getKeyType();
MapAttribute<? super Computer, ?, ?> anAttribute = entityComputer_.getMap("positionUC12");
// verify the key type is the Map key - not the managedType PK
Class<?> keyJavaType = anAttribute.getKeyJavaType();
// UC12: mapKey defined via generics and is an Embeddable (EmbeddedId) java class defined as an IdClass on the element(value) class
// @OneToMany(mappedBy="computerUC12", cascade=ALL, fetch=EAGER)
// @MapKey // key defaults to an instance of the composite pk class
// private Map<EmbeddedPK, GalacticPosition> positionUC12;
Type keyType = anAttribute.getKeyType();
// When @MapKey(name="name") is present or we use generics
assertEquals(EmbeddedPK.class, keyJavaType);
assertNotNull(keyType);
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
exceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", exceptionThrown);
}
}
use of org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testManagedType_getDeclaredSingularAttribute_Type_param_Method.
// TODO: This is not testing anything different?
public void testManagedType_getDeclaredSingularAttribute_Type_param_Method() {
EntityManager em = null;
boolean expectedIAExceptionThrown = false;
try {
em = privateTestSetup();
assertNotNull(em);
Metamodel metamodel = em.getMetamodel();
assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl) metamodel.entity(Manufacturer.class);
assertNotNull(entityManufacturer_);
MappedSuperclassTypeImpl<Person> msPerson_ = (MappedSuperclassTypeImpl) metamodel.managedType(Person.class);
assertNotNull(msPerson_);
MappedSuperclassTypeImpl<Corporation> msCorporation_ = (MappedSuperclassTypeImpl) metamodel.managedType(Corporation.class);
assertNotNull(msCorporation_);
EntityTypeImpl<GalacticPosition> entityLocation_ = (EntityTypeImpl) metamodel.entity(GalacticPosition.class);
assertNotNull(entityLocation_);
EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl) metamodel.entity(Computer.class);
assertNotNull(entityComputer_);
EntityTypeImpl<HardwareDesigner> entityHardwareDesigner_ = (EntityTypeImpl) metamodel.entity(HardwareDesigner.class);
assertNotNull(entityHardwareDesigner_);
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
expectedIAExceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
}
}
use of org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testIdentifiableType_getDeclaredVersion_does_not_exist_at_all_Method.
// TODO: This is not testing anything different?
public void testIdentifiableType_getDeclaredVersion_does_not_exist_at_all_Method() {
EntityManager em = null;
boolean expectedIAExceptionThrown = false;
try {
em = privateTestSetup();
assertNotNull(em);
Metamodel metamodel = em.getMetamodel();
assertNotNull(metamodel);
EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl) metamodel.entity(Manufacturer.class);
assertNotNull(entityManufacturer_);
// Actual Test Case
/**
* Return the attribute that corresponds to the version
* attribute declared by the entity or mapped superclass.
* @param type the type of the represented declared version
* attribute
* @return declared version attribute
* @throws IllegalArgumentException if version attribute of the
* type is not declared in the identifiable type
*/
// <Y> SingularAttribute<X, Y> getDeclaredVersion(Class<Y> type);
// Does not exist
// EntityType<Enclosure> anEnclosureType = metamodel.entity(Enclosure.class);
// assertNotNull(anEnclosureType.getDeclaredVersion(Integer.class));
// Is declared
assertNotNull(entityManufacturer_.getDeclaredVersion(int.class));
// FUTURE: need an undeclared subclass
// Is declared for assertNotNull(msPerson1_.getDeclaredVersion(Integer.class));
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
expectedIAExceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
}
}
use of org.eclipse.persistence.internal.jpa.metamodel.EntityTypeImpl in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testIdentifiableType_getDeclaredVersion_exists_Method.
public void testIdentifiableType_getDeclaredVersion_exists_Method() {
EntityManager em = null;
boolean expectedIAExceptionThrown = false;
try {
em = privateTestSetup();
assertNotNull(em);
Metamodel metamodel = em.getMetamodel();
assertNotNull(metamodel);
EntityTypeImpl<Manufacturer> entityManufacturer_ = (EntityTypeImpl) metamodel.entity(Manufacturer.class);
assertNotNull(entityManufacturer_);
// Actual Test Case
/**
* Return the attribute that corresponds to the version
* attribute declared by the entity or mapped superclass.
* @param type the type of the represented declared version
* attribute
* @return declared version attribute
* @throws IllegalArgumentException if version attribute of the
* type is not declared in the identifiable type
*/
// <Y> SingularAttribute<X, Y> getDeclaredVersion(Class<Y> type);
// FUTURE: need an undeclared subclass
// Is declared
SingularAttribute<Manufacturer, ?> anAttribute = entityManufacturer_.getDeclaredVersion(int.class);
assertNotNull(anAttribute);
assertNotNull(anAttribute.getType());
assertNotNull(anAttribute.getBindableType());
assertNotNull(anAttribute.getBindableJavaType());
assertNotNull(anAttribute.getDeclaringType());
assertEquals(entityManufacturer_, anAttribute.getDeclaringType());
assertFalse(anAttribute.isId());
assertTrue(anAttribute.isVersion());
assertEquals(PersistentAttributeType.BASIC, anAttribute.getPersistentAttributeType());
assertTrue(anAttribute.isOptional());
assertNotNull(anAttribute.getJavaType());
assertFalse(anAttribute.isAssociation());
assertFalse(anAttribute.isCollection());
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
expectedIAExceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
}
}
Aggregations