Search in sources :

Example 1 with SecurityRole

use of com.orientechnologies.orient.test.domain.customserialization.SecurityRole in project orientdb by orientechnologies.

the class ObjectTreeTest method testEnumListWithCustomTypes.

@Test(dependsOnMethods = "testCustomTypesDatabaseNewInstance")
public void testEnumListWithCustomTypes() {
    OObjectDatabaseTx database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    ORID rid = null;
    try {
        OObjectSerializerContext serializerContext = new OObjectSerializerContext();
        serializerContext.bind(new OObjectSerializer<SecurityRole, String>() {

            @Override
            public Object serializeFieldValue(Class<?> type, SecurityRole role) {
                return role.name();
            }

            @Override
            public Object unserializeFieldValue(Class<?> type, String str) {
                return SecurityRole.getByName(str);
            }
        }, database);
        OObjectSerializerHelper.bindSerializerContext(null, serializerContext);
        database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.customserialization");
        Sec s = new Sec();
        s.getSecurityRoleList().add(SecurityRole.LOGIN);
        Assert.assertTrue(s.getSecurityRoleList().contains(SecurityRole.LOGIN));
        s = database.save(s);
        rid = database.getRecordByUserObject(s, false).getIdentity();
        database.close();
        database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
        s = database.load(rid);
        Assert.assertTrue(s.getSecurityRoleList().contains(SecurityRole.LOGIN));
    } finally {
        database.close();
    }
}
Also used : Sec(com.orientechnologies.orient.test.domain.customserialization.Sec) OObjectSerializerContext(com.orientechnologies.orient.object.serialization.OObjectSerializerContext) SecurityRole(com.orientechnologies.orient.test.domain.customserialization.SecurityRole) OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) OSchemaProxyObject(com.orientechnologies.orient.object.metadata.schema.OSchemaProxyObject) ORID(com.orientechnologies.orient.core.id.ORID) Test(org.testng.annotations.Test)

Example 2 with SecurityRole

use of com.orientechnologies.orient.test.domain.customserialization.SecurityRole in project orientdb by orientechnologies.

the class ObjectTreeTestSchemaFull method testEnumListWithCustomTypes.

@Test(dependsOnMethods = "testCustomTypesDatabaseNewInstance")
public void testEnumListWithCustomTypes() {
    OObjectDatabaseTx database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
    ORID rid = null;
    try {
        OObjectSerializerContext serializerContext = new OObjectSerializerContext();
        serializerContext.bind(new OObjectSerializer<SecurityRole, String>() {

            @Override
            public Object serializeFieldValue(Class<?> type, SecurityRole role) {
                return role.name();
            }

            @Override
            public Object unserializeFieldValue(Class<?> type, String str) {
                return SecurityRole.getByName(str);
            }
        }, database);
        OObjectSerializerHelper.bindSerializerContext(null, serializerContext);
        database.getEntityManager().registerEntityClasses("com.orientechnologies.orient.test.domain.customserialization");
        Sec s = new Sec();
        s.getSecurityRoleList().add(SecurityRole.LOGIN);
        Assert.assertTrue(s.getSecurityRoleList().contains(SecurityRole.LOGIN));
        s = database.save(s);
        rid = database.getRecordByUserObject(s, false).getIdentity();
        database.close();
        database = OObjectDatabasePool.global().acquire(url, "admin", "admin");
        s = database.load(rid);
        Assert.assertTrue(s.getSecurityRoleList().contains(SecurityRole.LOGIN));
    } finally {
        database.close();
    }
}
Also used : Sec(com.orientechnologies.orient.test.domain.customserialization.Sec) OObjectSerializerContext(com.orientechnologies.orient.object.serialization.OObjectSerializerContext) SecurityRole(com.orientechnologies.orient.test.domain.customserialization.SecurityRole) OObjectDatabaseTx(com.orientechnologies.orient.object.db.OObjectDatabaseTx) ORID(com.orientechnologies.orient.core.id.ORID) Test(org.testng.annotations.Test)

Aggregations

ORID (com.orientechnologies.orient.core.id.ORID)2 OObjectDatabaseTx (com.orientechnologies.orient.object.db.OObjectDatabaseTx)2 OObjectSerializerContext (com.orientechnologies.orient.object.serialization.OObjectSerializerContext)2 Sec (com.orientechnologies.orient.test.domain.customserialization.Sec)2 SecurityRole (com.orientechnologies.orient.test.domain.customserialization.SecurityRole)2 Test (org.testng.annotations.Test)2 OSchemaProxyObject (com.orientechnologies.orient.object.metadata.schema.OSchemaProxyObject)1