use of com.orientechnologies.orient.core.exception.OValidationException in project orientdb by orientechnologies.
the class OSqlUpdateContentValidationTest method testReadOnlyValidation.
@Test
public void testReadOnlyValidation() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + OSqlUpdateContentValidationTest.class.getSimpleName());
db.create();
OClass clazz = db.getMetadata().getSchema().createClass("Test");
clazz.createProperty("testNormal", OType.STRING);
clazz.createProperty("test", OType.STRING).setReadonly(true);
OIdentifiable res = db.command(new OCommandSQL("insert into Test content {\"testNormal\":\"hello\",\"test\":\"only read\"} ")).execute();
try {
db.command(new OCommandSQL("update " + res.getIdentity() + " CONTENT {\"testNormal\":\"by\"}")).execute();
Assert.fail("Error on update of a record removing a readonly property");
} catch (OValidationException val) {
}
}
use of com.orientechnologies.orient.core.exception.OValidationException in project orientdb by orientechnologies.
the class HookChangeValidationTest method testHookUpdateChangeTx.
@Test
public void testHookUpdateChangeTx() {
ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + HookChangeValidationTest.class.getName());
db.create();
try {
OSchema schema = db.getMetadata().getSchema();
OClass classA = schema.createClass("TestClass");
classA.createProperty("property1", OType.STRING).setNotNull(true);
classA.createProperty("property2", OType.STRING).setReadonly(true);
classA.createProperty("property3", OType.STRING).setMandatory(true);
db.registerHook(new ODocumentHookAbstract() {
@Override
public RESULT onRecordBeforeCreate(ODocument doc) {
return RESULT.RECORD_NOT_CHANGED;
}
@Override
public RESULT onRecordBeforeUpdate(ODocument doc) {
doc.removeField("property1");
doc.removeField("property2");
doc.removeField("property3");
return RESULT.RECORD_CHANGED;
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
}
});
ODocument doc = new ODocument(classA);
doc.field("property1", "value1-create");
doc.field("property2", "value2-create");
doc.field("property3", "value3-create");
doc.save();
assertEquals("value1-create", doc.field("property1"));
assertEquals("value2-create", doc.field("property2"));
assertEquals("value3-create", doc.field("property3"));
doc.field("property1", "value1-update");
doc.field("property2", "value2-update");
try {
db.begin();
doc.save();
db.commit();
Assert.fail("The document save should fail for validation exception");
} catch (OValidationException ex) {
}
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.exception.OValidationException in project orientdb by orientechnologies.
the class HookChangeValidationTest method testHookCreateChangeTx.
@Test
public void testHookCreateChangeTx() {
ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + HookChangeValidationTest.class.getName());
db.create();
try {
OSchema schema = db.getMetadata().getSchema();
OClass classA = schema.createClass("TestClass");
classA.createProperty("property1", OType.STRING).setNotNull(true);
classA.createProperty("property2", OType.STRING).setReadonly(true);
classA.createProperty("property3", OType.STRING).setMandatory(true);
db.registerHook(new ODocumentHookAbstract() {
@Override
public RESULT onRecordBeforeCreate(ODocument doc) {
doc.removeField("property1");
doc.removeField("property2");
doc.removeField("property3");
return RESULT.RECORD_CHANGED;
}
@Override
public RESULT onRecordBeforeUpdate(ODocument doc) {
return RESULT.RECORD_NOT_CHANGED;
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
}
});
ODocument doc = new ODocument(classA);
doc.field("property1", "value1-create");
doc.field("property2", "value2-create");
doc.field("property3", "value3-create");
try {
db.begin();
doc.save();
db.commit();
Assert.fail("The document save should fail for validation exception");
} catch (OValidationException ex) {
}
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.exception.OValidationException in project orientdb by orientechnologies.
the class HookChangeValidationTest method testHookCreateChange.
@Test
public void testHookCreateChange() {
ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + HookChangeValidationTest.class.getName());
db.create();
try {
OSchema schema = db.getMetadata().getSchema();
OClass classA = schema.createClass("TestClass");
classA.createProperty("property1", OType.STRING).setNotNull(true);
classA.createProperty("property2", OType.STRING).setReadonly(true);
classA.createProperty("property3", OType.STRING).setMandatory(true);
db.registerHook(new ODocumentHookAbstract() {
@Override
public RESULT onRecordBeforeCreate(ODocument doc) {
doc.removeField("property1");
doc.removeField("property2");
doc.removeField("property3");
return RESULT.RECORD_CHANGED;
}
@Override
public RESULT onRecordBeforeUpdate(ODocument doc) {
return RESULT.RECORD_NOT_CHANGED;
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
}
});
ODocument doc = new ODocument(classA);
doc.field("property1", "value1-create");
doc.field("property2", "value2-create");
doc.field("property3", "value3-create");
try {
doc.save();
Assert.fail("The document save should fail for validation exception");
} catch (OValidationException ex) {
}
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.exception.OValidationException in project orientdb by orientechnologies.
the class ServerClusterSchemaTest method executeTest.
@Override
protected void executeTest() throws Exception {
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
System.out.println("Creating vertex class Client" + s + " against server " + g + "...");
OrientVertexType t = g.createVertexType("Client" + s);
t.createProperty("name", OType.STRING).setMandatory(true);
System.out.println("Creating vertex class Knows" + s + " against server " + g + "...");
g.createEdgeType("Knows" + s);
} finally {
g.shutdown();
}
}
for (int s = 0; s < SERVERS; ++s) {
System.out.println("Checking vertices classes on server " + s + "...");
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
for (int i = 0; i < SERVERS; ++i) {
Assert.assertNotNull(g.getVertexType("Client" + i));
Assert.assertNotNull(g.getEdgeType("Knows" + i));
}
} finally {
g.shutdown();
}
}
for (int s = 0; s < SERVERS; ++s) {
System.out.println("Add vertices on server " + s + "...");
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
for (int i = 0; i < SERVERS; ++i) {
try {
final OrientVertex v = g.addVertex("class:" + "Client" + i);
Assert.assertTrue(false);
} catch (OValidationException e) {
// EXPECTED
}
}
} finally {
g.shutdown();
}
}
for (int s = 0; s < SERVERS; ++s) {
System.out.println("Add vertices in TX on server " + s + "...");
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraph g = factory.getTx();
try {
for (int i = 0; i < SERVERS; ++i) {
try {
final OrientVertex v = g.addVertex("class:" + "Client" + i);
g.commit();
Assert.assertTrue(false);
} catch (ONeedRetryException e) {
// EXPECTED
} catch (OValidationException e) {
// EXPECTED
}
}
} finally {
g.shutdown();
}
}
}
Aggregations