use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.
the class AnnotationTest method testColumnLength.
/**
* Test of JPA column length
*/
public void testColumnLength() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
// Retrieve the metadata from the MetaDataManager (populates and initialises everything)
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Printer.class.getName(), clr);
AbstractMemberMetaData fmd = cmd1.getMetaDataForMember("make");
assertEquals(fmd.getColumnMetaData().length, 1);
assertEquals(fmd.getColumnMetaData()[0].getName(), "MAKE");
assertEquals(40, fmd.getColumnMetaData()[0].getLength().intValue());
}
use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.
the class AnnotationTest method testOneToManyUniJoin.
/**
* Test of JPA 1-N unidir JoinTable relation
*/
public void testOneToManyUniJoin() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
// owner side
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Department.class.getName(), clr);
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("projects");
assertNotNull("Department.projects is null!", fmd1);
assertEquals("Department.projects mapped-by is incorrect", null, fmd1.getMappedBy());
assertEquals("Department.projects relationType is incorrect", RelationType.ONE_TO_MANY_UNI, fmd1.getRelationType(clr));
assertEquals("Department.projects jointable name is incorrect", "JPA_AN_DEPT_PROJECTS", fmd1.getTable());
JoinMetaData joinmd = fmd1.getJoinMetaData();
assertNotNull("Department.projects has no join table!", joinmd);
assertNotNull("Department.projects has incorrect join columns", joinmd.getColumnMetaData());
assertEquals("Department.projects has incorrect number of join columns", 2, joinmd.getColumnMetaData().length);
assertEquals("Department.projects has incorrect join column name", joinmd.getColumnMetaData()[0].getName(), "DEPT_ID");
assertEquals("Department.projects has incorrect join column name", joinmd.getColumnMetaData()[1].getName(), "DEPT_ID_STRING");
ElementMetaData elemmd = fmd1.getElementMetaData();
assertNotNull("Department.projects has no element column info but should", elemmd);
ColumnMetaData[] colmds = elemmd.getColumnMetaData();
assertNotNull("Department.projects has incorrect element columns", colmds);
assertEquals("Department.projects has incorrect number of element columns", 1, colmds.length);
assertEquals("Department.projects has incorrect element column name", "PROJECT_ID", colmds[0].getName());
}
use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.
the class AnnotationTest method testTableGenerator.
/**
* Test of basic JPA @TableGenerator
*/
public void testTableGenerator() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Employee.class.getName(), clr);
PackageMetaData pmd = cmd1.getPackageMetaData();
assertEquals("Number of TableGenerators registered for Employee class is wrong", pmd.getNoOfTableGenerators(), 1);
TableGeneratorMetaData tgmd = pmd.getTableGenerators()[0];
assertEquals("TableGenerator has incorrect name", tgmd.getName(), "EmployeeGenerator");
assertEquals("TableGenerator has incorrect table", tgmd.getTableName(), "ID_TABLE");
assertEquals("TableGenerator has incorrect pk column name", tgmd.getPKColumnName(), "TYPE");
assertEquals("TableGenerator has incorrect value column name", tgmd.getValueColumnName(), "LATEST_VALUE");
assertEquals("TableGenerator has incorrect pk column value", tgmd.getPKColumnValue(), "EMPLOYEE");
assertEquals("TableGenerator has incorrect initial value", tgmd.getInitialValue(), 0);
assertEquals("TableGenerator has incorrect allocation size", tgmd.getAllocationSize(), 50);
}
use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.
the class AnnotationTest method testEnumeratedJDBCType.
/**
* Test of JPA enumerated JDBC type.
*/
public void testEnumeratedJDBCType() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(EnumHolder.class.getName(), clr);
AbstractMemberMetaData mmd1 = cmd1.getMetaDataForMember("colour1");
assertEquals(JdbcType.INTEGER, mmd1.getColumnMetaData()[0].getJdbcType());
assertEquals(FieldPersistenceModifier.PERSISTENT, mmd1.getPersistenceModifier());
AbstractMemberMetaData mmd2 = cmd1.getMetaDataForMember("colour2");
assertEquals(JdbcType.VARCHAR, mmd2.getColumnMetaData()[0].getJdbcType());
assertEquals(FieldPersistenceModifier.PERSISTENT, mmd2.getPersistenceModifier());
}
use of org.datanucleus.PersistenceNucleusContextImpl in project tests by datanucleus.
the class AnnotationTest method testOneToManyUniMapFK.
/**
* Test of JPA 1-N unidir Map relation
*/
public void testOneToManyUniMapFK() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
ClassLoaderResolver clr = nucleusCtx.getClassLoaderResolver(null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
PersistenceUnitMetaData pumd = getMetaDataForPersistenceUnit(nucleusCtx, "JPATest");
metaDataMgr.loadPersistenceUnit(pumd, null);
// owner side
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("phoneNumbers");
assertNotNull("Department.phoneNumbers is null!", fmd1);
assertEquals("Department.phoneNumbers mapped-by is incorrect", fmd1.getMappedBy(), null);
assertEquals("Department.phoneNumbers relationType is incorrect", fmd1.getRelationType(clr), RelationType.ONE_TO_MANY_UNI);
assertEquals("Department.phoneNumbers jointable name is incorrect", fmd1.getTable(), null);
MapMetaData mmd = fmd1.getMap();
assertNotNull("Department.phoneNumbers has no Map metadata!", mmd);
KeyMetaData keymd = fmd1.getKeyMetaData();
assertNotNull("Department.phoneNumbers has no Key metadata!", keymd);
assertEquals("Department.phoneNumbers has incorrect key mapped-by", keymd.getMappedBy(), "name");
}
Aggregations