Search in sources :

Example 1 with GraphSONWriter

use of com.tinkerpop.blueprints.util.io.graphson.GraphSONWriter in project orientdb by orientechnologies.

the class OGremlinConsoleTest method testGraphSONImport.

@Test
public void testGraphSONImport() throws IOException {
    final String INPUT_FILE = "src/test/resources/graph-example-fromexport.xml";
    String dbUrl1 = "memory:testGraphSONImport1";
    String dbUrl2 = "memory:testGraphSONImport2";
    final OrientGraphNoTx g1 = new OrientGraphNoTx(dbUrl1);
    new OGraphMLReader(g1).inputGraph(INPUT_FILE);
    // EXPORT IN GRAPHSON FORMAT
    final ByteArrayOutputStream output = new ByteArrayOutputStream();
    new GraphSONWriter(g1).outputGraph(output, null, null, GraphSONMode.NORMAL);
    final OrientGraphNoTx g2 = new OrientGraphNoTx(dbUrl2);
    ByteArrayInputStream is = new ByteArrayInputStream(output.toByteArray());
    new OGraphSONReader(g2).inputGraph(is);
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl2);
    db.open("admin", "admin");
    try {
        boolean foundTypeVAttr = false;
        boolean foundFriendEAttr = false;
        List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from V"));
        Assert.assertFalse(result.isEmpty());
        for (ODocument d : result) {
            if (d.containsField("__type__"))
                foundTypeVAttr = true;
        }
        Assert.assertTrue(foundTypeVAttr);
        result = db.query(new OSQLSynchQuery<ODocument>("select from E"));
        Assert.assertFalse(result.isEmpty());
        for (ODocument d : result) {
            if (d.containsField("friend"))
                foundFriendEAttr = true;
        }
        Assert.assertTrue(foundFriendEAttr);
    } finally {
        db.close();
    }
}
Also used : GraphSONWriter(com.tinkerpop.blueprints.util.io.graphson.GraphSONWriter) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OGraphSONReader(com.orientechnologies.orient.graph.graphml.OGraphSONReader) OGraphMLReader(com.orientechnologies.orient.graph.graphml.OGraphMLReader) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Aggregations

ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1 OGraphMLReader (com.orientechnologies.orient.graph.graphml.OGraphMLReader)1 OGraphSONReader (com.orientechnologies.orient.graph.graphml.OGraphSONReader)1 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)1 GraphSONWriter (com.tinkerpop.blueprints.util.io.graphson.GraphSONWriter)1 Test (org.junit.Test)1