use of org.datanucleus.ClassLoaderResolver in project tests by datanucleus.
the class AnnotationPlusXMLTest method testTableGenerator.
/**
* Test of JPA <table-generator>
*/
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.ClassLoaderResolver in project tests by datanucleus.
the class AnnotationTest method testSecondaryTable.
/**
* Test for use of annotations for secondary tables, in particular @SecondaryTable.
* Uses Printer class, storing some fields in table "PRINTER" and some in "PRINTER_TONER".
*/
public void testSecondaryTable() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Printer.class.getName(), clr);
assertEquals("detachable is wrong", cmd.isDetachable(), true);
assertEquals("identity-type is wrong", cmd.getIdentityType(), IdentityType.APPLICATION);
assertEquals("embedded-only is wrong", cmd.isEmbeddedOnly(), false);
assertEquals("requires-extent is wrong", cmd.isRequiresExtent(), true);
assertNull("catalog is wrong", cmd.getCatalog());
assertNull("schema is wrong", cmd.getSchema());
assertEquals("table is wrong", cmd.getTable(), "JPA_AN_PRINTER");
assertEquals("has incorrect number of persistent fields", cmd.getNoOfManagedMembers(), 5);
// Check JoinMetaData at class-level
List<JoinMetaData> joinmds = cmd.getJoinMetaData();
assertNotNull("JoinMetaData at class-level is null!", joinmds);
assertEquals("Number of JoinMetaData at class-level is wrong!", joinmds.size(), 1);
assertEquals("Table of JoinMetaData at class-level is wrong", "JPA_AN_PRINTER_TONER", joinmds.get(0).getTable());
ColumnMetaData[] joinColmds = joinmds.get(0).getColumnMetaData();
assertEquals("Number of columns with MetaData in secondary table is incorrect", 1, joinColmds.length);
assertEquals("Column of JoinMetaData at class-level is wrong", joinColmds[0].getName(), "PRINTER_ID");
// "model" (stored in primary-table)
AbstractMemberMetaData fmd = cmd.getMetaDataForMember("model");
assertNotNull("Doesnt have required field", fmd);
assertNull("Field 'model' has non-null table!", fmd.getTable());
// "tonerModel" (stored in secondary-table)
fmd = cmd.getMetaDataForMember("tonerModel");
assertNotNull("Doesnt have required field", fmd);
assertEquals("Field 'tonerModel' has non-null table!", fmd.getTable(), "JPA_AN_PRINTER_TONER");
}
use of org.datanucleus.ClassLoaderResolver in project tests by datanucleus.
the class AnnotationTest method testSequenceGenerator.
/**
* Test of basic JPA @SequenceGenerator
*/
public void testSequenceGenerator() {
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(Department.class.getName(), clr);
PackageMetaData pmd = cmd1.getPackageMetaData();
assertEquals("Number of Sequences registered for Department class is wrong", pmd.getNoOfSequences(), 1);
SequenceMetaData seqmd = pmd.getSequences()[0];
assertEquals("SequenceGenerator has incorrect name", seqmd.getName(), "DepartmentGenerator");
assertEquals("SequenceGenerator has incorrect sequence name", seqmd.getDatastoreSequence(), "DEPT_SEQ");
assertEquals("SequenceGenerator has incorrect initial value", seqmd.getInitialValue(), 1);
assertEquals("SequenceGenerator has incorrect allocation size", seqmd.getAllocationSize(), 50);
}
use of org.datanucleus.ClassLoaderResolver in project tests by datanucleus.
the class AnnotationTest method testCharDefaultTo1Length.
/**
* Test of char length default to 1 with JPA.
*/
public void testCharDefaultTo1Length() {
NucleusContext nucleusCtx = new PersistenceNucleusContextImpl("JPA", null);
MetaDataManager metaDataMgr = new JPAMetaDataManager(nucleusCtx);
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(TypeHolder.class.getName(), clr);
assertEquals(1, cmd1.getMetaDataForMember("char1").getColumnMetaData()[0].getLength().intValue());
}
use of org.datanucleus.ClassLoaderResolver in project tests by datanucleus.
the class AnnotationTest method testOneToManyBiFK.
/**
* Test of JPA 1-N bidir FK relation
*/
public void testOneToManyBiFK() {
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(Manager.class.getName(), clr);
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("departments");
assertNotNull("Manager.departments is null!", fmd1);
assertEquals("Manager.departments mapped-by is incorrect", fmd1.getMappedBy(), "manager");
assertEquals("Manager.departments relationType is incorrect", fmd1.getRelationType(clr), RelationType.ONE_TO_MANY_BI);
ElementMetaData elemmd = fmd1.getElementMetaData();
assertNull("Manager.departments has join column info but shouldnt (specified on N side)", elemmd);
// non-owner side
ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Department.class.getName(), clr);
AbstractMemberMetaData fmd2 = cmd2.getMetaDataForMember("manager");
assertNotNull("Department.manager is null!", fmd2);
assertEquals("Department.manager mapped-by is incorrect", fmd2.getMappedBy(), null);
assertEquals("Department.manager relationType is incorrect", fmd2.getRelationType(clr), RelationType.MANY_TO_ONE_BI);
ColumnMetaData[] colmds = fmd2.getColumnMetaData();
assertNotNull("Department.manager has no join column info", colmds);
assertEquals("Department.manager has incorrect number of joincolumns", colmds.length, 1);
assertEquals("Department.manager joincolumn name is wrong", "MGR_ID", colmds[0].getName());
}
Aggregations