Search in sources :

Example 1 with DateWidget

use of org.datanucleus.samples.widget.DateWidget in project tests by datanucleus.

the class BasicTest method testLoadingMetaDataForPackage.

/**
 * Tests the loading of XML metadata specified in package,jdo.
 */
public void testLoadingMetaDataForPackage() {
    MetaDataManager mmgr = new PersistenceNucleusContextImpl("JDO", null).getMetaDataManager();
    ClassLoaderResolver clr = new ClassLoaderResolverImpl();
    // Validate metadata for DateWidget
    AbstractClassMetaData cmd = mmgr.getMetaDataForClass(DateWidget.class, clr);
    assertNotNull("ClassMetaData is null!", cmd);
    assertEquals("Class name", DateWidget.class.getName(), cmd.getFullClassName());
    assertEquals("Package name", "org.datanucleus.samples.widget", cmd.getPackageName());
    assertEquals("Superclass", Widget.class.getName(), cmd.getPersistableSuperclass());
    assertEquals("Identity type", IdentityType.DATASTORE, cmd.getIdentityType());
    assertNull("Identity class", cmd.getObjectidClass());
    assertNotNull("Inheritance", cmd.getInheritanceMetaData());
    assertEquals("Inheritance strategy", cmd.getInheritanceMetaData().getStrategy().toString(), "new-table");
    String[] sortedFieldNames = new String[] { "dateField", "dateJdbcTimestampField", "sqlDateField", "sqlTimestampField" };
    Assert.assertEquals("Field count", sortedFieldNames.length, cmd.getNoOfManagedMembers());
    for (int i = 0; i < sortedFieldNames.length; ++i) {
        AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtRelativePosition(i);
        String s = sortedFieldNames[i];
        assertEquals(s, fmd.getName());
        assertEquals(s + " persistence modifier", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
        assertEquals(s + " primary key", false, fmd.isPrimaryKey());
        assertEquals(s + " null value handling", NullValue.NONE, fmd.getNullValue());
        assertEquals(s + " default fetch group", true, fmd.isDefaultFetchGroup());
        assertNull(s + " collection metadata", fmd.getContainer());
        assertNull(s + " map metadata", fmd.getContainer());
    }
    // Validate metadata for FloatWidget
    cmd = mmgr.getMetaDataForClass(FloatWidget.class, clr);
    assertNotNull("Metadata", cmd);
    assertEquals("Class name", FloatWidget.class.getName(), cmd.getFullClassName());
    assertEquals("Package name", "org.datanucleus.samples.widget", cmd.getPackageName());
    assertEquals("Superclass", Widget.class.getName(), cmd.getPersistableSuperclass());
    assertEquals("Identity type", IdentityType.DATASTORE, cmd.getIdentityType());
    assertNull("Identity class", cmd.getObjectidClass());
    sortedFieldNames = new String[] { "doubleField", "doubleObjField", "floatField", "floatObjField" };
    NullValue[] nullValueHandlings = new NullValue[] { NullValue.EXCEPTION, NullValue.NONE, NullValue.EXCEPTION, NullValue.NONE };
    assertEquals("Field count", sortedFieldNames.length, cmd.getNoOfManagedMembers());
    for (int i = 0; i < sortedFieldNames.length; ++i) {
        AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtRelativePosition(i);
        String s = sortedFieldNames[i];
        Assert.assertEquals(s, fmd.getName());
        Assert.assertEquals(s + " persistence modifier", FieldPersistenceModifier.PERSISTENT, fmd.getPersistenceModifier());
        Assert.assertEquals(s + " primary key", false, fmd.isPrimaryKey());
        Assert.assertEquals(s + " null value handling", nullValueHandlings[i], fmd.getNullValue());
        Assert.assertEquals(s + " default fetch group", true, fmd.isDefaultFetchGroup());
        Assert.assertNull(s + " collection metadata", fmd.getContainer());
        Assert.assertNull(s + " map metadata", fmd.getContainer());
    }
}
Also used : FloatWidget(org.datanucleus.samples.widget.FloatWidget) ClassLoaderResolver(org.datanucleus.ClassLoaderResolver) DateWidget(org.datanucleus.samples.widget.DateWidget) LevelAboveWidget(org.datanucleus.samples.widget.LevelAboveWidget) DateWidget(org.datanucleus.samples.widget.DateWidget) FloatWidget(org.datanucleus.samples.widget.FloatWidget) Widget(org.datanucleus.samples.widget.Widget) PackageClassWidget(org.datanucleus.samples.widget.PackageClassWidget) JDOMetaDataManager(org.datanucleus.api.jdo.metadata.JDOMetaDataManager) MetaDataManager(org.datanucleus.metadata.MetaDataManager) PersistenceNucleusContextImpl(org.datanucleus.PersistenceNucleusContextImpl) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) NullValue(org.datanucleus.metadata.NullValue) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) ClassLoaderResolverImpl(org.datanucleus.ClassLoaderResolverImpl)

Aggregations

ClassLoaderResolver (org.datanucleus.ClassLoaderResolver)1 ClassLoaderResolverImpl (org.datanucleus.ClassLoaderResolverImpl)1 PersistenceNucleusContextImpl (org.datanucleus.PersistenceNucleusContextImpl)1 JDOMetaDataManager (org.datanucleus.api.jdo.metadata.JDOMetaDataManager)1 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)1 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)1 MetaDataManager (org.datanucleus.metadata.MetaDataManager)1 NullValue (org.datanucleus.metadata.NullValue)1 DateWidget (org.datanucleus.samples.widget.DateWidget)1 FloatWidget (org.datanucleus.samples.widget.FloatWidget)1 LevelAboveWidget (org.datanucleus.samples.widget.LevelAboveWidget)1 PackageClassWidget (org.datanucleus.samples.widget.PackageClassWidget)1 Widget (org.datanucleus.samples.widget.Widget)1