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();
}
}
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();
}
}
Aggregations