use of org.datanucleus.NucleusContext in project tests by datanucleus.
the class AnnotationTest method testMapKeyColumn.
/**
* Test of persistent properties using annotations.
*/
/*public void testPersistentProperties()
{
NucleusContext nucleusCtx = new NucleusContext("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(JPAGetter.class.getName(), clr);
assertEquals(1, cmd1.getNoOfPrimaryKeyMembers());
}*/
/**
* Test of column name for property instead of field
*/
/*public void testPropertyColumName()
{
NucleusContext nucleusCtx = new NucleusContext("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(Employee.class.getName(), clr);
// it is valid according JPA to have property accessor instead of field accessors. property accessors are persistent while field not.
assertNotNull("Employee.lastName has no field information", cmd1.getMetaDataForMember("lastName"));
assertNotNull("Employee.lastName has no column information", cmd1.getMetaDataForMember("lastName").getColumnMetaData());
assertEquals("Employee.lastName has incorrect number of columns",
1, cmd1.getMetaDataForMember("lastName").getColumnMetaData().length);
assertEquals("Employee.last has incorrect column spec",
"LASTNAME", cmd1.getMetaDataForMember("lastName").getColumnMetaData()[0].getName());
ClassMetaData cmd2 = (ClassMetaData)metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
// it is valid according JPA to have property accessor instead of field accessors. property accessors are persistent while field not.
assertNotNull(cmd2.getMetaDataForMember("age"));
assertNotNull("AGE_COL",cmd2.getMetaDataForMember("age").getColumnMetaData()[0].getName());
assertNotNull(cmd2.getMetaDataForMember("maidenName"));
assertEquals(FieldPersistenceModifier.NONE,cmd2.getMetaDataForMember("_maidenName").getPersistenceModifier());
assertEquals(FieldPersistenceModifier.PERSISTENT,cmd2.getMetaDataForMember("maidenName").getPersistenceModifier());
}*/
/**
* Test of JPA @MapKeyColumn.
*/
public void testMapKeyColumn() {
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(Person.class.getName(), clr);
assertEquals("phoneNumbers_key1", cmd1.getMetaDataForMember("phoneNumbers").getKeyMetaData().getColumnMetaData()[0].getName());
}
use of org.datanucleus.NucleusContext in project tests by datanucleus.
the class AnnotationTest method testByteArrayEmbeddedByDefault.
/**
* Test of JPA Byte[] is embedded by default
*/
public void testByteArrayEmbeddedByDefault() {
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(ByteArray.class.getName(), clr);
assertTrue(cmd1.getMetaDataForMember("array1").isEmbedded());
}
use of org.datanucleus.NucleusContext in project tests by datanucleus.
the class AnnotationTest method testOneToOneBi.
/**
* Test of JPA 1-1 bidir relation
*/
public void testOneToOneBi() {
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);
// non-owner side
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Boiler.class.getName(), clr);
assertEquals("Boiler has incorrect table name", "JPA_AN_BOILER", cmd1.getTable());
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("timer");
assertNotNull("Boiler.timer is null!", fmd1);
assertEquals("Boiler.timer mapped-by is incorrect", "boiler", fmd1.getMappedBy());
assertEquals("Boiler.timer relationType is incorrect", RelationType.ONE_TO_ONE_BI, fmd1.getRelationType(clr));
// owner side
ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Timer.class.getName(), clr);
assertEquals("Timer has incorrect table name", "JPA_AN_TIMER", cmd2.getTable());
AbstractMemberMetaData fmd2 = cmd2.getMetaDataForMember("boiler");
assertNotNull("Timer.boiler is null!", fmd2);
assertEquals("Timer.boiler mapped-by is incorrect", null, fmd2.getMappedBy());
assertEquals("Timer.boiler relationType is incorrect", RelationType.ONE_TO_ONE_BI, fmd2.getRelationType(clr));
assertNotNull("Timer.boiler has no column info", fmd2.getColumnMetaData());
assertEquals("Timer.boiler has incorrect number of columns", 1, fmd2.getColumnMetaData().length);
assertEquals("Timer.boiler column name is wrong", "BOILER_ID", fmd2.getColumnMetaData()[0].getName());
}
use of org.datanucleus.NucleusContext in project tests by datanucleus.
the class XMLTest method testOneToOneUni.
/**
* Test of 1-1 uni relation
*/
public void testOneToOneUni() {
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(LoginAccount.class.getName(), clr);
AbstractMemberMetaData fmd1 = cmd1.getMetaDataForMember("login");
assertNotNull("LoginAccount.login is null!", fmd1);
assertEquals("LoginAccount.login mapped-by is incorrect", fmd1.getMappedBy(), null);
assertEquals("LoginAccount.login relationType is incorrect", fmd1.getRelationType(clr), RelationType.ONE_TO_ONE_UNI);
assertNotNull("LoginAccount.login has no column info", fmd1.getColumnMetaData());
assertEquals("LoginAccount.login has incorrect number of columns", fmd1.getColumnMetaData().length, 1);
assertEquals("LoginAccount.login column name is wrong", fmd1.getColumnMetaData()[0].getName(), "LOGIN_ID");
}
use of org.datanucleus.NucleusContext in project tests by datanucleus.
the class XMLTest 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_MD_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", 1, joinmd.getColumnMetaData().length);
assertEquals("Department.projects has incorrect join column name", joinmd.getColumnMetaData()[0].getName(), "DEPT_ID");
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());
}
Aggregations