use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationPlusXMLTest method testPersistent.
/**
* Test of @Persistent on a field.
*/
public void testPersistent() {
// Person
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
String prefix = cmd.getFullClassName() + " : ";
// "bestFriend" - explicitly set
AbstractMemberMetaData fmd = cmd.getMetaDataForMember("bestFriend");
assertEquals(prefix + "field should be persistent", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
// "lastName" - not annotated, but default
fmd = cmd.getMetaDataForMember("lastName");
assertNotNull(prefix + "doesnt have required field", fmd);
assertEquals(prefix + "should be persistent", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationPlusXMLTest method testValueStrategy.
/**
* Test of @Persistent(primaryKey="true", valueStrategy=IDENTITY) on a field.
*/
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());
assertEquals(prefix + "pk value strategy incorrect", ValueGenerationStrategy.IDENTITY, fmd.getValueStrategy());
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationTest method testCollectionJoinTable.
/**
* Test for use of collection with join table
*/
public void testCollectionJoinTable() {
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Manager.class.getName(), clr);
String prefix = cmd1.getFullClassName() + " : ";
AbstractMemberMetaData fmd = cmd1.getMetaDataForMember("subordinates");
assertNotNull(prefix + "doesnt have required field", fmd);
CollectionMetaData colmd = fmd.getCollection();
assertNotNull(prefix + "CollectionMetaData is null!", colmd);
assertEquals(prefix + "CollectionMetaData elementType is incorrect", Employee.class.getName(), colmd.getElementType());
JoinMetaData joinmd = fmd.getJoinMetaData();
assertNotNull(prefix + "field \"subordinates\" has no join information!", joinmd);
assertEquals(prefix + "field \"subordinates\" is stored in wrong table", "MANAGER_EMPLOYEES", fmd.getTable());
assertEquals(prefix + "field \"subordinates\" join table has incorrect column", "MANAGER_ID", joinmd.getColumnName());
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationTest method testStrategyValue.
/**
* Test of basic JDO strategy value
*/
public void testStrategyValue() {
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
assertEquals(ValueGenerationStrategy.INCREMENT, cmd1.getMetaDataForMember("personNum").getValueStrategy());
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationTest method testIndexOnField.
/**
* Test of Index at field level
*/
public void testIndexOnField() {
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
AbstractMemberMetaData fmd = cmd1.getMetaDataForMember("age");
assertNotNull("JDOPerson.age metadata should have had an Index constraint but didnt", fmd.getIndexMetaData());
IndexMetaData idxmd = fmd.getIndexMetaData();
assertEquals("PERSON_AGE_IDX", idxmd.getName());
}
Aggregations