use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.
the class EventGraphTest method testFireEdgePropertyChanged.
public void testFireEdgePropertyChanged() {
graph.addListener(graphChangedListener);
Edge edge = createEdge();
edge.setProperty("weight", System.currentTimeMillis());
assertEquals(1, graphChangedListener.edgePropertyChangedEventRecorded());
graphChangedListener.reset();
edge.getProperty("weight");
assertEquals(0, graphChangedListener.edgePropertyChangedEventRecorded());
}
use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.
the class EventGraphTest method testFireEdgeRemoved.
public void testFireEdgeRemoved() {
graph.addListener(graphChangedListener);
Edge edge = createEdge();
graph.removeEdge(edge);
assertEquals(1, graphChangedListener.edgeRemovedEventRecorded());
}
use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.
the class EventTransactionalGraphTest method testEventedElement.
public void testEventedElement() {
graph.addListener(new ConsoleGraphChangedListener(graph));
for (Vertex vertex : graph.getVertices()) {
assertTrue(vertex instanceof EventVertex);
vertex.setProperty("name", "noname");
assertEquals("noname", vertex.getProperty("name"));
assertTrue(vertex.getEdges(Direction.OUT) instanceof EventEdgeIterable);
assertTrue(vertex.getEdges(Direction.IN) instanceof EventEdgeIterable);
assertTrue(vertex.getEdges(Direction.OUT, "knows") instanceof EventEdgeIterable);
assertTrue(vertex.getEdges(Direction.IN, "created") instanceof EventEdgeIterable);
}
for (Edge edge : graph.getEdges()) {
assertTrue(edge instanceof EventEdge);
edge.removeProperty("weight");
assertNull(edge.getProperty("weight"));
assertTrue(edge.getVertex(Direction.OUT) instanceof EventVertex);
assertTrue(edge.getVertex(Direction.IN) instanceof EventVertex);
}
}
use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.
the class GraphSONUtilityTest method edgeFromJsonInputStreamCompactNoIdOnEdge.
@Test
public void edgeFromJsonInputStreamCompactNoIdOnEdge() throws IOException, JSONException {
Graph g = new TinkerGraph();
ElementFactory factory = new GraphElementFactory(g);
Set<String> vertexKeys = new HashSet<String>() {
{
add(GraphSONTokens._ID);
}
};
Set<String> edgeKeys = new HashSet<String>() {
{
add(GraphSONTokens._IN_V);
}
};
GraphSONUtility graphson = new GraphSONUtility(GraphSONMode.COMPACT, factory, vertexKeys, edgeKeys);
Vertex v1 = graphson.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)));
Vertex v2 = graphson.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)));
Edge e = graphson.edgeFromJson(inputStreamEdgeJsonLight, v1, v2);
Assert.assertSame(v1, g.getVertex(1));
Assert.assertSame(v2, g.getVertex(2));
Assert.assertSame(e, g.getEdge(0));
}
use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.
the class GraphSONUtilityTest method edgeFromJsonValid.
@Test
public void edgeFromJsonValid() throws IOException, JSONException {
Graph g = new TinkerGraph();
ElementFactory factory = new GraphElementFactory(g);
Vertex v1 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.NORMAL, null);
Vertex v2 = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)), factory, GraphSONMode.NORMAL, null);
Edge e = GraphSONUtility.edgeFromJson(new JSONObject(new JSONTokener(edgeJson)), v1, v2, factory, GraphSONMode.NORMAL, null);
Assert.assertSame(v1, g.getVertex(1));
Assert.assertSame(v2, g.getVertex(2));
Assert.assertSame(e, g.getEdge(7));
// tinkergraph converts id to string
Assert.assertEquals("7", e.getId());
Assert.assertEquals(0.5d, e.getProperty("weight"));
Assert.assertEquals("knows", e.getLabel());
Assert.assertEquals(v1, e.getVertex(Direction.OUT));
Assert.assertEquals(v2, e.getVertex(Direction.IN));
}
Aggregations