use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class ReadOnlyGraphTest method testReadOnlyElement.
public void testReadOnlyElement() {
Graph graph = new ReadOnlyGraph<TinkerGraph>(TinkerGraphFactory.createTinkerGraph());
for (Vertex vertex : graph.getVertices()) {
assertTrue(vertex instanceof ReadOnlyVertex);
try {
vertex.setProperty("name", "noname");
assertTrue(false);
} catch (UnsupportedOperationException e) {
assertTrue(true);
}
vertex.getProperty("name");
vertex.getPropertyKeys();
assertTrue(vertex.getEdges(Direction.OUT) instanceof ReadOnlyEdgeIterable);
assertTrue(vertex.getEdges(Direction.IN) instanceof ReadOnlyEdgeIterable);
assertTrue(vertex.getEdges(Direction.OUT, "knows") instanceof ReadOnlyEdgeIterable);
assertTrue(vertex.getEdges(Direction.IN, "created") instanceof ReadOnlyEdgeIterable);
}
for (Edge edge : graph.getEdges()) {
assertTrue(edge instanceof ReadOnlyEdge);
try {
edge.removeProperty("weight");
assertTrue(false);
} catch (UnsupportedOperationException e) {
assertTrue(true);
}
edge.getProperty("weight");
edge.getPropertyKeys();
assertTrue(edge.getVertex(Direction.OUT) instanceof ReadOnlyVertex);
assertTrue(edge.getVertex(Direction.IN) instanceof ReadOnlyVertex);
}
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class ReadOnlyGraphTest method testReadOnlyGraph.
public void testReadOnlyGraph() {
Graph graph = new ReadOnlyGraph<TinkerGraph>(TinkerGraphFactory.createTinkerGraph());
assertTrue(graph.getVertices() instanceof ReadOnlyVertexIterable);
assertTrue(graph.getEdges() instanceof ReadOnlyEdgeIterable);
assertEquals(count(graph.getVertices()), 6);
assertEquals(count(graph.getEdges()), 6);
try {
graph.addVertex(null);
assertTrue(false);
} catch (UnsupportedOperationException e) {
assertTrue(true);
}
try {
graph.addEdge(null, null, null, "knows");
assertTrue(false);
} catch (UnsupportedOperationException e) {
assertTrue(true);
}
try {
graph.removeVertex(graph.getVertex(1));
assertTrue(false);
} catch (UnsupportedOperationException e) {
assertTrue(true);
}
try {
graph.removeEdge(graph.getEdge(10));
assertTrue(false);
} catch (UnsupportedOperationException e) {
assertTrue(true);
}
try {
graph.shutdown();
assertTrue(false);
} catch (UnsupportedOperationException e) {
assertTrue(true);
}
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GraphSONReaderTest method inputStreamIsNull.
@Test(expected = IllegalArgumentException.class)
public void inputStreamIsNull() throws IOException {
TinkerGraph graph = new TinkerGraph();
InputStream inputStream = null;
GraphSONReader.inputGraph(graph, inputStream);
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GraphSONReaderTest method inputGraphCompactFullCycleBroken.
@Test(expected = IllegalArgumentException.class)
public void inputGraphCompactFullCycleBroken() throws IOException {
TinkerGraph graph = TinkerGraphFactory.createTinkerGraph();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Set<String> edgeKeys = new HashSet<String>();
edgeKeys.add(GraphSONTokens._IN_V);
edgeKeys.add(GraphSONTokens._OUT_V);
edgeKeys.add(GraphSONTokens._LABEL);
Set<String> vertexKeys = new HashSet<String>();
GraphSONWriter writer = new GraphSONWriter(graph);
writer.outputGraph(stream, vertexKeys, edgeKeys, GraphSONMode.COMPACT);
stream.flush();
stream.close();
String jsonString = new String(stream.toByteArray());
byte[] bytes = jsonString.getBytes();
InputStream inputStream = new ByteArrayInputStream(bytes);
TinkerGraph emptyGraph = new TinkerGraph();
GraphSONReader.inputGraph(emptyGraph, inputStream);
}
use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.
the class GraphSONUtilityTest method edgeFromJsonInputStreamCompactLabelOrIdOnEdge.
@Test
public void edgeFromJsonInputStreamCompactLabelOrIdOnEdge() throws IOException, JSONException {
Graph g = new TinkerGraph();
ElementFactory factory = new GraphElementFactory(g);
Vertex v1 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.COMPACT, null);
Vertex v2 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)), factory, GraphSONMode.COMPACT, null);
Edge e = GraphSONUtility.edgeFromJson(inputStreamEdgeJsonLight, v1, v2, factory, GraphSONMode.COMPACT, null);
Assert.assertSame(v1, g.getVertex(1));
Assert.assertSame(v2, g.getVertex(2));
Assert.assertSame(e, g.getEdge(0));
}
Aggregations