Search in sources :

Example 26 with OrientGraph

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();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 27 with OrientGraph

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();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) Before(org.junit.Before)

Example 28 with OrientGraph

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();
    }
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.junit.Test)

Example 29 with OrientGraph

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();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Test(org.junit.Test)

Example 30 with OrientGraph

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();
    }
}
Also used : OValidationException(com.orientechnologies.orient.core.exception.OValidationException) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) Test(org.junit.Test)

Aggregations

OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)94 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)43 Test (org.junit.Test)33 Vertex (com.tinkerpop.blueprints.Vertex)22 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)19 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)18 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)13 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)12 Edge (com.tinkerpop.blueprints.Edge)8 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)7 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)7 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)7 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)6 Test (org.testng.annotations.Test)6 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)5 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)5 Before (org.junit.Before)5 BeforeClass (org.junit.BeforeClass)5 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)4