Search in sources :

Example 16 with OValidationException

use of com.orientechnologies.orient.core.exception.OValidationException in project orientdb by orientechnologies.

the class ODocumentValidationTest method testValidationNotValidEmbeddedList.

@Test
public void testValidationNotValidEmbeddedList() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + ODocumentValidationTest.class.getSimpleName());
    db.create();
    try {
        OClass embeddedClazz = db.getMetadata().getSchema().createClass("EmbeddedValidation");
        embeddedClazz.createProperty("int", OType.INTEGER).setMandatory(true);
        embeddedClazz.createProperty("long", OType.LONG).setMandatory(true);
        OClass clazz = db.getMetadata().getSchema().createClass("Validation");
        clazz.createProperty("int", OType.INTEGER).setMandatory(true);
        clazz.createProperty("long", OType.LONG).setMandatory(true);
        clazz.createProperty("embeddedList", OType.EMBEDDEDLIST, embeddedClazz).setMandatory(true);
        ODocument d = new ODocument(clazz);
        d.field("int", 30);
        d.field("long", 30);
        final ArrayList<ODocument> embeddedList = new ArrayList<ODocument>();
        d.field("embeddedList", embeddedList);
        ODocument embeddedInList = new ODocument("EmbeddedValidation");
        embeddedInList.field("int", 30);
        embeddedInList.field("long", 30);
        embeddedList.add(embeddedInList);
        ODocument embeddedInList2 = new ODocument("EmbeddedValidation");
        embeddedInList2.field("int", 30);
        embeddedList.add(embeddedInList2);
        try {
            d.validate();
            Assert.fail("Validation doesn't throw exception");
        } catch (OValidationException e) {
            Assert.assertTrue(e.toString().contains("EmbeddedValidation.long"));
        }
    } finally {
        db.drop();
    }
}
Also used : OValidationException(com.orientechnologies.orient.core.exception.OValidationException) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Test(org.testng.annotations.Test)

Example 17 with OValidationException

use of com.orientechnologies.orient.core.exception.OValidationException in project orientdb by orientechnologies.

the class ODocumentValidationTest method testValidationNotValidEmbedded.

@Test
public void testValidationNotValidEmbedded() {
    ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + ODocumentValidationTest.class.getSimpleName());
    db.create();
    try {
        OClass embeddedClazz = db.getMetadata().getSchema().createClass("EmbeddedValidation");
        embeddedClazz.createProperty("int", OType.INTEGER).setMandatory(true);
        OClass clazz = db.getMetadata().getSchema().createClass("Validation");
        clazz.createProperty("int", OType.INTEGER).setMandatory(true);
        clazz.createProperty("long", OType.LONG).setMandatory(true);
        clazz.createProperty("embedded", OType.EMBEDDED, embeddedClazz).setMandatory(true);
        ODocument d = new ODocument(clazz);
        d.field("int", 30);
        d.field("long", 30);
        d.field("embedded", new ODocument("EmbeddedValidation").field("test", "test"));
        try {
            d.validate();
            Assert.fail("Validation doesn't throw exception");
        } catch (OValidationException e) {
            Assert.assertTrue(e.toString().contains("EmbeddedValidation.int"));
        }
    } finally {
        db.drop();
    }
}
Also used : OValidationException(com.orientechnologies.orient.core.exception.OValidationException) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Test(org.testng.annotations.Test)

Aggregations

OValidationException (com.orientechnologies.orient.core.exception.OValidationException)17 Test (org.testng.annotations.Test)11 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)10 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)10 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)9 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)7 ODocumentHookAbstract (com.orientechnologies.orient.core.hook.ODocumentHookAbstract)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)4 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 ODocumentSerializable (com.orientechnologies.orient.core.serialization.ODocumentSerializable)2 OSerializableStream (com.orientechnologies.orient.core.serialization.OSerializableStream)2 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)2 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)2 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)2 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)2 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)2 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)2 BigDecimal (java.math.BigDecimal)2 Test (org.junit.Test)2 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1