use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationTest method testExtensions.
/**
* Test for use of @Extension and @Extensions
*/
public void testExtensions() {
ClassMetaData cmd1 = (ClassMetaData) metaDataMgr.getMetaDataForClass(Manager.class.getName(), clr);
String prefix = cmd1.getFullClassName() + " : ";
// Test class level @Extension
Map<String, String> extmds1 = cmd1.getExtensions();
assertNotNull(prefix + "extension info is null!", extmds1);
assertTrue(prefix + "extension info has incorrect number of extensions", extmds1.size() == 1);
assertTrue("extension not present", extmds1.containsKey("someExtensionProp"));
assertEquals("extension value is incorrect", "My Value", extmds1.get("someExtensionProp"));
// Test field level @Extensions
AbstractMemberMetaData fmd = cmd1.getMetaDataForMember("departments");
assertNotNull(prefix + "doesnt have required field", fmd);
Map<String, String> extmds2 = fmd.getExtensions();
assertNotNull(prefix + "extension info is null!", extmds2);
assertEquals(prefix + "extension info has incorrect number of extensions", 2, extmds2.size());
assertTrue("extension not present", extmds2.containsKey("prop1"));
assertTrue("extension not present", extmds2.containsKey("prop2"));
assertEquals("extension value is incorrect", "val1", extmds2.get("prop1"));
assertEquals("extension value is incorrect", "val2", extmds2.get("prop2"));
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationPlusXMLOverrideTest method testPersistent.
/**
* Test enabling persistence on a field erroneously annotated as @NotPersistent.
*/
public void testPersistent() {
// Person
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
String prefix = cmd.getFullClassName() + " : ";
// "mood" - annotated "@NotPersistent", overidden in "package.jdo"
AbstractMemberMetaData fmd = cmd.getMetaDataForMember("mood");
assertNotNull(prefix + "doesnt have required field", fmd);
assertEquals(prefix + "field should be persistent", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationPlusXMLOverrideTest method testPersistenceCapable.
/* Quick fix tests (artificial) ----------------------------------------- */
/**
* Test enabling forgotten @PersistenceCapable(detachable="true") annotation
* parameter on a class in "package.jdo", and correcting the table-name set
* in "package.jdo" in vendor specific "package.orm".
* .
*/
public void testPersistenceCapable() {
// Person
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
String prefix = cmd.getFullClassName() + " : ";
assertEquals(prefix + "table is wrong", "T_Person", cmd.getTable());
assertTrue(prefix + "detachable is wrong", cmd.isDetachable());
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationPlusXMLOverrideTest method testColumn.
/**
* Check explicit vendor specific column information in "package.orm",
* overriding the standard settings in "package.jdo".
*/
public void testColumn() {
// Person
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
String prefix = cmd.getFullClassName() + " : ";
// "dateOfBirth" - JDBC type is TIMESTAMP in "package.jdo"
AbstractMemberMetaData fmd = cmd.getMetaDataForMember("dateOfBirth");
ColumnMetaData[] colmds = fmd.getColumnMetaData();
assertEquals("column identifier incorrect", "DATE_OF_BIRTH", colmds[0].getName());
assertEquals("column JDBC type incorrect", JdbcType.DATE, 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"));
// package.orm (overriding)
// "emailAddress" - package.jdo VARCHAR(128), package.orm CHAR(100)
fmd = cmd.getMetaDataForMember("emailAddress");
colmds = fmd.getColumnMetaData();
assertEquals(prefix + "column identifier incorrect", "EMAIL_ADDRESS", colmds[0].getName());
assertEquals(prefix + "column length incorrect", new Integer(100), colmds[0].getLength());
assertEquals(prefix + "column JDBC type incorrect", JdbcType.CHAR, colmds[0].getJdbcType());
}
use of org.datanucleus.metadata.ClassMetaData in project tests by datanucleus.
the class AnnotationPlusXMLOverrideTest method testQuery.
/**
* A named query using annotation @Query would/should use 'language="JDOQL"',
* so it's up to the JDO implementation to translate it to applicable SQL
* - even if it's vendor specific.
* <p/>
* Test named query (language="SQL"): proprietary vendor SQL in "package.orm"
* overriding ANSI-SQL in "package.jdo".
*/
public void testQuery() {
// Person
ClassMetaData cmd = (ClassMetaData) metaDataMgr.getMetaDataForClass(Person.class.getName(), clr);
String prefix = cmd.getFullClassName() + " : ";
QueryMetaData[] qmds = cmd.getQueries();
assertNotNull(prefix + "query info is incorrect", qmds);
assertEquals(prefix + "query name incorrect", "NumberOfPeople", qmds[0].getName());
assertEquals(prefix + "query language incorrect", "SQL", qmds[0].getLanguage());
assertFalse(prefix + "query unmodifiable incorrect", qmds[0].isUnmodifiable());
assertTrue(prefix + "query unique incorrect", qmds[0].isUnique());
assertEquals(prefix + "query string incorrect", "SELECT COUNT(ALL) AS THESIZE FROM PERSON", qmds[0].getQuery());
}
Aggregations