use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationTest method testFetchGroups.
/**
* Test for use of annotations with fetch groups
*/
public void testFetchGroups() {
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
String prefix = cmd1.getFullClassName() + " : ";
Set<FetchGroupMetaData> fgmds = cmd1.getFetchGroupMetaData();
assertNotNull(prefix + "fetch group info is incorrect", fgmds);
FetchGroupMetaData fgmd = fgmds.iterator().next();
assertEquals(prefix + "fetch group name incorrect", "names", fgmd.getName());
assertFalse(prefix + "fetch group fields incorrect", fgmd.getPostLoad());
Set<FetchGroupMemberMetaData> fgmmds = fgmd.getMembers();
assertNotNull(fgmmds);
assertEquals(prefix + "number of fetch group fields is wrong", 2, fgmmds.size());
Iterator<FetchGroupMemberMetaData> fgmmdIter = fgmmds.iterator();
FetchGroupMemberMetaData fgmmd0 = fgmmdIter.next();
FetchGroupMemberMetaData fgmmd1 = fgmmdIter.next();
assertTrue(prefix + "fields in fetch group are incorrect", (fgmmd0.getName().equals("firstName") && fgmmd1.getName().equals("lastName")) || (fgmmd1.getName().equals("firstName") && fgmmd0.getName().equals("lastName")));
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationTest method testPrimaryKeyColumns.
/**
* Test for use of annotations to define PK columns, overriding those of the superclass
*/
public void testPrimaryKeyColumns() {
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Manager.class.getName(), clr);
String prefix = cmd1.getFullClassName() + " : ";
PrimaryKeyMetaData pkmd = cmd1.getPrimaryKeyMetaData();
assertNotNull(prefix + "has null primary-key metadata!", pkmd);
assertNotNull(prefix + "has no primary-key columns!", pkmd.getColumnMetaData());
assertEquals(prefix + "has incorrect no of PK columns", 2, pkmd.getColumnMetaData().length);
ColumnMetaData[] colmds = pkmd.getColumnMetaData();
assertEquals("Name of first col of pk is incorrect", "MGR_ID", colmds[0].getName());
assertEquals("Target of first col of pk is incorrect", "PERSON_ID", colmds[0].getTarget());
assertEquals("Name of second col of pk is incorrect", "MGR_GLOBAL_ID", colmds[1].getName());
assertEquals("Target of second col of pk is incorrect", "PERSON_GLOB_ID", colmds[1].getTarget());
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationPlusXMLOverrideTest method testDefaultFetchGroup.
/**
* Test enabling forgotten DFG on a field in "package.jdo".
*/
public void testDefaultFetchGroup() {
// Department
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Department.class.getName(), clr);
String prefix = cmd.getFullClassName() + " : ";
// "manager"
AbstractMemberMetaData fmd = cmd.getMetaDataForMember("manager");
assertEquals(prefix + "field should be persistent", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
assertTrue(prefix + "dfg is wrong", fmd.isDefaultFetchGroup());
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationPlusXMLOverrideTest method testValueStrategy.
/* Overriding features (required use-cases) ----------------------------- */
/**
* Test of @Persistent(primaryKey="true", valueStrategy=SEQUENCE) on a field,
* where annotation is set to NATIVE - which is the default anyway.
*/
public void testValueStrategy() {
// Account
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Account.class.getName(), clr);
String prefix = cmd.getFullClassName() + " : ";
assertEquals(prefix + "number of PK members is wrong", 1, cmd.getNoOfPrimaryKeyMembers());
AbstractMemberMetaData fmd = cmd.getMetaDataForMember("id");
assertEquals(prefix + "field should be persistent", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
assertTrue(prefix + "pk is wrong", fmd.isPrimaryKey());
// package.orm (overriding) - Annotation: NATIVE, .jdo: IDENTITY
assertEquals(prefix + "PK value strategy incorrect", ValueGenerationStrategy.SEQUENCE, fmd.getValueStrategy());
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationPlusXMLTest method testColumn.
/**
* Check explicit column information in "package.jdo" and/or "package.orm".
*/
public void testColumn() {
// Person
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
String prefix = cmd.getFullClassName() + " : ";
// "lastName"
AbstractMemberMetaData fmd = cmd.getMetaDataForMember("lastName");
ColumnMetaData[] colmds = fmd.getColumnMetaData();
assertEquals(prefix + "column identifier incorrect", "LASTNAME", colmds[0].getName());
assertEquals(prefix + "column length incorrect", new Integer(64), colmds[0].getLength());
assertEquals(prefix + "column JDBC type incorrect", JdbcType.VARCHAR, colmds[0].getJdbcType());
// "firstName"
fmd = cmd.getMetaDataForMember("firstName");
colmds = fmd.getColumnMetaData();
assertEquals(prefix + "column identifier incorrect", "FIRSTNAME", colmds[0].getName());
assertEquals(prefix + "column length incorrect", new Integer(32), colmds[0].getLength());
assertEquals(prefix + "column JDBC type incorrect", JdbcType.VARCHAR, colmds[0].getJdbcType());
// "emailAddress"
fmd = cmd.getMetaDataForMember("emailAddress");
colmds = fmd.getColumnMetaData();
assertEquals(prefix + "column identifier incorrect", "EMAILADDRESS", colmds[0].getName());
assertEquals(prefix + "column length incorrect", new Integer(128), colmds[0].getLength());
assertEquals(prefix + "column JDBC type incorrect", JdbcType.VARCHAR, colmds[0].getJdbcType());
// "dateOfBirth"
fmd = cmd.getMetaDataForMember("dateOfBirth");
colmds = fmd.getColumnMetaData();
assertEquals("column identifier incorrect", "DATEOFBIRTH", colmds[0].getName());
assertEquals("column JDBC type incorrect", JdbcType.TIMESTAMP, colmds[0].getJdbcType());
// package.orm (additional)
Map<String, String> extmds = fmd.getExtensions();
assertNotNull(prefix + "extension info is null!", extmds);
assertEquals(prefix + "incorrect number of extensions", 1, extmds.size());
assertTrue("extension not present", extmds.containsKey("insert-function"));
assertEquals("extension value is incorrect", "CURRENT_TIMESTAMP", extmds.get("insert-function"));
}
Aggregations