use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class OConsoleDatabaseAppTest method testSimple.
@Test
public void testSimple() {
String dbUrl = "memory:OConsoleDatabaseAppTest";
StringBuilder builder = new StringBuilder();
builder.append("create database " + dbUrl + ";\n");
builder.append("profile storage on;\n");
builder.append("create class foo;\n");
builder.append("config;\n");
builder.append("list classes;\n");
builder.append("list properties;\n");
builder.append("list clusters;\n");
builder.append("list indexes;\n");
builder.append("info class OUser;\n");
builder.append("info property OUser.name;\n");
builder.append("begin;\n");
builder.append("insert into foo set name = 'foo';\n");
builder.append("insert into foo set name = 'bla';\n");
builder.append("update foo set surname = 'bar' where name = 'foo';\n");
builder.append("commit;\n");
builder.append("select from foo;\n");
builder.append("create class bar;\n");
builder.append("create property bar.name STRING;\n");
builder.append("create index bar_name on bar (name) NOTUNIQUE;\n");
builder.append("insert into bar set name = 'foo';\n");
builder.append("delete from bar;\n");
builder.append("begin;\n");
builder.append("insert into bar set name = 'foo';\n");
builder.append("rollback;\n");
builder.append("create vertex V set name = 'foo';\n");
builder.append("create vertex V set name = 'bar';\n");
builder.append("traverse out() from V;\n");
builder.append("create edge from (select from V where name = 'foo') to (select from V where name = 'bar');\n");
builder.append("traverse out() from V;\n");
// builder.append("create user TestUser identified by password ROLE ['reader','writer'];\n");
builder.append("drop user TestUser;\n");
builder.append("profile storage off;\n");
builder.append("repair database -v;\n");
ConsoleTest c = new ConsoleTest(new String[] { builder.toString() });
OConsoleDatabaseApp console = c.console();
try {
console.run();
ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
db.open("admin", "admin");
try {
List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from foo where name = 'foo'"));
Assert.assertEquals(1, result.size());
ODocument doc = result.get(0);
Assert.assertEquals("bar", doc.field("surname"));
result = db.query(new OSQLSynchQuery<ODocument>("select from bar"));
Assert.assertEquals(0, result.size());
} finally {
db.close();
}
OrientGraph graph = new OrientGraph(dbUrl);
try {
Iterable<Vertex> result = graph.command(new OSQLSynchQuery<Vertex>("select expand(out()) from (select from V where name = 'foo')")).execute();
Iterator<Vertex> iterator = result.iterator();
Assert.assertTrue(iterator.hasNext());
Vertex next = iterator.next();
Assert.assertEquals("bar", next.getProperty("name"));
Assert.assertFalse(iterator.hasNext());
} finally {
graph.shutdown();
}
} finally {
console.close();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class GraphValidationTest method beforeMethod.
@Before
public void beforeMethod() {
OrientGraph g = new OrientGraph(URL, "admin", "admin");
g.drop();
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class GraphValidationTest method testPropertyReadOnly.
@Test(expected = OValidationException.class)
public void testPropertyReadOnly() {
OrientGraphNoTx graphNoTx = new OrientGraphNoTx(URL);
OrientVertexType testType = graphNoTx.createVertexType("Test");
OProperty prop;
prop = testType.createProperty("name", OType.STRING).setReadonly(true);
graphNoTx.shutdown();
//this one passes
Assert.assertTrue(prop.isReadonly());
OrientGraph graph = new OrientGraph(URL);
try {
OrientVertex vert1 = graph.addVertex("class:Test", "name", "Sam");
graph.commit();
//should throw an exception
vert1.setProperty("name", "Ben");
graph.commit();
//fails
Assert.assertEquals(vert1.getProperty("name"), "Sam");
} finally {
graph.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class GraphValidationTest method edgesCannotBeVertices.
@Test
public void edgesCannotBeVertices() {
OrientGraphNoTx gNoTx = new OrientGraphNoTx(URL, "admin", "admin");
try {
gNoTx.createVertexType("TestV");
gNoTx.createEdgeType("TestE");
OrientVertex v = gNoTx.addVertex("class:TestV");
OrientVertex loadedV = gNoTx.getVertex(v.getIdentity());
try {
OrientEdge e = gNoTx.getEdge(v.getIdentity().toString());
Assert.fail();
} catch (IllegalArgumentException e) {
// OK
}
} finally {
gNoTx.shutdown();
}
OrientGraph g = new OrientGraph(URL, "admin", "admin");
try {
OrientVertex v = g.addVertex("class:TestV");
OrientVertex loadedV = g.getVertex(v.getIdentity().toString());
try {
OrientEdge e = g.getEdge(v.getIdentity());
Assert.fail();
} catch (IllegalArgumentException e) {
// OK
}
} finally {
g.shutdown();
}
}
use of com.tinkerpop.blueprints.impls.orient.OrientGraph in project orientdb by orientechnologies.
the class GraphValidationTest method fail.
@Test
public void fail() {
setupSchema();
final OrientGraphFactory orientGraphFactory = new OrientGraphFactory(URL, "admin", "admin").setupPool(1, 10);
OrientGraph graph = orientGraphFactory.getTx();
try {
graph.addVertex("class:M", "name", "n0");
try {
graph.addVertex("class:M");
graph.commit();
// This is what happens => not OK?
throw new RuntimeException("Schema problem was not detected!");
} catch (OValidationException e) {
System.out.println("This is the Message I want to see: \n" + e);
}
} finally {
graph.shutdown();
}
}
Aggregations