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