use of org.datanucleus.NucleusContext in project tests by datanucleus.
the class AnnotationTest method testEmbeddedId.
/**
* Test of basic JPA @EmbeddedId.
*/
public void testEmbeddedId() {
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(Department.class.getName(), clr);
assertEquals(1, cmd1.getNoOfPrimaryKeyMembers());
}
use of org.datanucleus.NucleusContext in project tests by datanucleus.
the class AnnotationTest method testOneToOneUni.
/**
* Test of JPA 1-1 unidir 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);
assertEquals("LoginAccount has incorrect table name", cmd1.getTable(), "JPA_AN_LOGINACCOUNT");
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");
ClassMetaData cmd2 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Login.class.getName(), clr);
assertEquals("LoginAccount has incorrect table name", cmd2.getTable(), "JPA_AN_LOGIN");
}
use of org.datanucleus.NucleusContext in project tests by datanucleus.
the class AnnotationTest method testNamedQuery.
/**
* Test of JPA @NamedQuery, @NamedNativeQuery.
*/
public void testNamedQuery() {
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 cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(LoginAccount.class.getName(), clr);
QueryMetaData[] qmds = cmd.getQueries();
assertNotNull("LoginAccount has no queries!", qmds);
assertEquals("LoginAccount has incorrect number of queries", 2, qmds.length);
QueryMetaData jpqlQuery = null;
QueryMetaData sqlQuery = null;
if (qmds[0].getLanguage().equals(QueryLanguage.JPQL.toString())) {
jpqlQuery = qmds[0];
} else if (qmds[1].getLanguage().equals(QueryLanguage.JPQL.toString())) {
jpqlQuery = qmds[1];
}
if (qmds[0].getLanguage().equals(QueryLanguage.SQL.toString())) {
sqlQuery = qmds[0];
} else if (qmds[1].getLanguage().equals(QueryLanguage.SQL.toString())) {
sqlQuery = qmds[1];
}
if (jpqlQuery == null) {
fail("No JPQL Query was registered for LoginAccount");
}
if (sqlQuery == null) {
fail("No SQL Query was registered for LoginAccount");
}
assertEquals("LoginAccount JPQL has incorrect query name", "LoginForJohnSmith", jpqlQuery.getName());
assertEquals("LoginAccount JPQL has incorrect query", "SELECT a FROM LoginAccount a WHERE a.firstName='John' AND a.lastName='Smith'", jpqlQuery.getQuery());
assertEquals("LoginAccount SQL has incorrect query name", "LoginForJohn", sqlQuery.getName());
assertEquals("LoginAccount SQL has incorrect query", "SELECT * FROM JPA_AN_LOGIN WHERE FIRSTNAME = 'John'", sqlQuery.getQuery());
}
use of org.datanucleus.NucleusContext 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.NucleusContext 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());
}
Aggregations