Java Code Examples for org.apache.tinkerpop.gremlin.structure.Edge#property()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.Edge#property() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBatchNormalUpdateDateTime.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void batchUpdateDurationEdge() throws InterruptedException {
    this.sqlgGraph.tx().normalBatchModeOn();
    Duration duration = Duration.ofHours(5);
    for (int i = 0; i < 10; i++) {
        Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person");
        Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person");
        v1.addEdge("test", v2, "duration", duration);
    }
    this.sqlgGraph.tx().commit();
    List<Edge> edges = this.sqlgGraph.traversal().E().toList();
    Assert.assertEquals(10, edges.size());
    Assert.assertEquals(duration, edges.get(0).<Duration>value("duration"));
    this.sqlgGraph.tx().normalBatchModeOn();
    duration = Duration.ofHours(10);
    for (Edge edge : edges) {
        edge.property("duration", duration);
    }
    this.sqlgGraph.tx().commit();
    testUpdateDurationEdge_assert(this.sqlgGraph, duration);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testUpdateDurationEdge_assert(this.sqlgGraph1, duration);
    }
}
 
Example 2
Source File: GraphSONMessageSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSerializeEdgeProperty() throws Exception {
    final Graph g = TinkerGraph.open();
    final Vertex v1 = g.addVertex();
    final Vertex v2 = g.addVertex();
    final Edge e = v1.addEdge("test", v2);
    e.property("abc", 123);

    final Iterable<Property<Object>> iterable = IteratorUtils.list(e.properties("abc"));
    final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(iterable).create());

    final JsonNode json = mapper.readTree(results);

    assertNotNull(json);
    assertEquals(msg.getRequestId().toString(), json.get(SerTokens.TOKEN_REQUEST).asText());
    final JsonNode converted = json.get(SerTokens.TOKEN_RESULT).get(SerTokens.TOKEN_DATA);

    assertNotNull(converted);
    assertEquals(1, converted.size());

    final JsonNode propertyAsJson = converted.get(0);
    assertNotNull(propertyAsJson);

    assertEquals(123, propertyAsJson.get(GraphSONTokens.VALUEPROP).get("value").get(GraphSONTokens.VALUEPROP).asInt());
}
 
Example 3
Source File: GraphSONMessageSerializerGremlinV1d0Test.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSerializeEdgeProperty() throws Exception {
    final Graph graph = TinkerGraph.open();
    final Vertex v1 = graph.addVertex();
    final Vertex v2 = graph.addVertex();
    final Edge e = v1.addEdge("test", v2);
    e.property("abc", 123);

    final Iterable<Property<Object>> iterable = IteratorUtils.list(e.properties("abc"));
    final ResponseMessage response = convert(iterable);
    assertCommon(response);

    final List<Map<String, Object>> propertyList = (List<Map<String, Object>>) response.getResult().getData();
    assertEquals(1, propertyList.size());
    assertEquals(123, propertyList.get(0).get("value"));
}
 
Example 4
Source File: TestBatchNormalUpdateDateTime.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void batchUpdateLocalTimeEdge() throws InterruptedException {
    this.sqlgGraph.tx().normalBatchModeOn();
    LocalTime now = LocalTime.now();
    for (int i = 0; i < 10; i++) {
        Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person");
        Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person");
        v1.addEdge("test", v2, "createOn", now);
    }
    this.sqlgGraph.tx().commit();
    List<Edge> edges = this.sqlgGraph.traversal().E().toList();
    Assert.assertEquals(10, edges.size());
    Assert.assertEquals(now.toSecondOfDay(), edges.get(0).<LocalTime>value("createOn").toSecondOfDay());
    this.sqlgGraph.tx().normalBatchModeOn();
    LocalTime nowAgain = LocalTime.now().minusHours(3);
    for (Edge edge : edges) {
        edge.property("createOn", nowAgain);
    }
    this.sqlgGraph.tx().commit();
    testUpdateLocalTimeEdge_assert(this.sqlgGraph, nowAgain);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testUpdateLocalTimeEdge_assert(this.sqlgGraph1, nowAgain);
    }
}
 
Example 5
Source File: TestBatchNormalUpdateDateTime.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void batchUpdateZonedDateTimeEdge() throws InterruptedException {
    this.sqlgGraph.tx().normalBatchModeOn();
    ZonedDateTime zonedDateTime = ZonedDateTime.now();
    for (int i = 0; i < 10; i++) {
        Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "createOn", zonedDateTime);
        Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person", "createOn", zonedDateTime);
        v1.addEdge("test", v2, "createOn", zonedDateTime);
    }
    this.sqlgGraph.tx().commit();
    List<Edge> edges = this.sqlgGraph.traversal().E().toList();
    Assert.assertEquals(10, edges.size());
    Assert.assertEquals(zonedDateTime, edges.get(0).value("createOn"));
    this.sqlgGraph.tx().normalBatchModeOn();
    zonedDateTime = ZonedDateTime.now().minusDays(1);
    for (Edge edge : edges) {
        edge.property("createOn", zonedDateTime);
    }
    this.sqlgGraph.tx().commit();
    batchUpdateZonedDateTimeEdge_assert(this.sqlgGraph, zonedDateTime);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        batchUpdateZonedDateTimeEdge_assert(this.sqlgGraph1, zonedDateTime);
    }
}
 
Example 6
Source File: TestSchema.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testEdgeAcrossSchemaCreatesPropertyInAll() {
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A.A");
    Vertex b1 = this.sqlgGraph.addVertex(T.label, "B.B");
    Vertex c1 = this.sqlgGraph.addVertex(T.label, "C.C");
    Edge ab1 = a1.addEdge("yourEdge", b1);
    Edge bc1 = b1.addEdge("yourEdge", c1);
    this.sqlgGraph.tx().commit();
    ab1.property("test", "halo");
    this.sqlgGraph.tx().commit();
    Assert.assertTrue(this.sqlgGraph.traversal().E(ab1.id()).next().property("test").isPresent());
    Assert.assertFalse(this.sqlgGraph.traversal().E(bc1.id()).next().property("test").isPresent());
    bc1.property("test", "halo");
    this.sqlgGraph.tx().commit();
    Assert.assertTrue(this.sqlgGraph.traversal().E(bc1.id()).next().property("test").isPresent());
}
 
Example 7
Source File: TestBatchNormalUpdateDateTime.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void batchUpdateLocalDateEdge() throws InterruptedException {
    this.sqlgGraph.tx().normalBatchModeOn();
    LocalDate now = LocalDate.now();
    for (int i = 0; i < 10; i++) {
        Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person");
        Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person");
        v1.addEdge("test", v2, "createOn", now);
    }
    this.sqlgGraph.tx().commit();
    List<Edge> edges = this.sqlgGraph.traversal().E().toList();
    Assert.assertEquals(10, edges.size());
    Assert.assertEquals(now, edges.get(0).value("createOn"));
    this.sqlgGraph.tx().normalBatchModeOn();
    LocalDate nowAgain = LocalDate.now();
    for (Edge edge : edges) {
        edge.property("createOn", nowAgain);
    }
    this.sqlgGraph.tx().commit();
    testUpdateLocalDateEdge_assert(this.sqlgGraph, nowAgain);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testUpdateLocalDateEdge_assert(this.sqlgGraph1, nowAgain);
    }
}
 
Example 8
Source File: VertexDuplicator.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
static void moveOutgoingEdges(Vertex vertex, Vertex duplicate, IndexHandler indexHandler) {
  for (Iterator<Edge> edges = vertex.edges(Direction.OUT); edges.hasNext(); ) {
    Edge edge = edges.next();
    if (edge.label().equals(VERSION_OF)) {
      continue;
    }

    Edge duplicateEdge = duplicate.addEdge(edge.label(), edge.inVertex());

    for (Iterator<Property<Object>> properties = edge.properties(); properties.hasNext(); ) {
      Property<Object> property = properties.next();

      duplicateEdge.property(property.key(), property.value());
    }
    if (duplicateEdge.<Boolean>property("isLatest").orElse(false)) {
      duplicateEdge.<String>property("tim_id")
        .ifPresent(p -> indexHandler.upsertIntoEdgeIdIndex(UUID.fromString(p), duplicateEdge));
    }
    edge.remove();
  }
}
 
Example 9
Source File: MapInAdjacentVerticesHandler.java    From windup with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Getter.
 */
private static Map<String, WindupVertexFrame> handleGetter(Vertex vertex, Method method, Object[] arguments,
            MapInAdjacentVertices annotation, FramedGraph framedGraph)
{
    if (arguments != null && arguments.length != 0)
        throw new WindupException("Method must take zero arguments: " + method.getName());

    Map<String, WindupVertexFrame> result = new HashMap<>();
    Iterator<Edge> edges = vertex.edges(Direction.IN, annotation.label());
    while (edges.hasNext())
    {
        Edge edge = edges.next();
        Property<String> property = edge.property(annotation.mapKeyField());
        if (property == null)
            continue;

        Vertex v = edge.outVertex();
        WindupVertexFrame frame = framedGraph.frameElement(v, WindupVertexFrame.class);
        result.put(property.value(), frame);
    }
    return result;
}
 
Example 10
Source File: DetachedPropertyTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldAttachToVertex() {
    final Edge e = g.E(convertToEdgeId("josh", "created", "lop")).next();
    final Property toDetach = e.property("weight");
    final DetachedProperty<?> detachedProperty = DetachedFactory.detach(toDetach);
    final Property attached = detachedProperty.attach(Attachable.Method.get(e.outVertex()));

    assertEquals(toDetach, attached);
    assertFalse(attached instanceof DetachedProperty);
}
 
Example 11
Source File: GraphSONMessageSerializerGremlinV2d0Test.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSerializeEdge() throws Exception {
    final Graph graph = TinkerGraph.open();
    final Vertex v1 = graph.addVertex();
    final Vertex v2 = graph.addVertex();
    final Edge e = v1.addEdge("test", v2);
    e.property("abc", 123);

    final Iterable<Edge> iterable = IteratorUtils.list(graph.edges());

    final ResponseMessage response = convert(iterable);
    assertCommon(response);

    final List<Edge> edgeList = (List<Edge>) response.getResult().getData();
    assertEquals(1, edgeList.size());

    final Edge deserializedEdge = edgeList.get(0);
    assertEquals(e.id(), deserializedEdge.id());
    assertEquals(v1.id(), deserializedEdge.outVertex().id());
    assertEquals(v2.id(), deserializedEdge.inVertex().id());
    assertEquals(v1.label(), deserializedEdge.outVertex().label());
    assertEquals(v2.label(), deserializedEdge.inVertex().label());
    assertEquals(e.label(), deserializedEdge.label());

    final List<Property> properties = new ArrayList<>();
    deserializedEdge.properties().forEachRemaining(properties::add);
    assertEquals(1, properties.size());

    assertNotNull(properties);
    assertEquals("abc", properties.get(0).key());
    assertEquals(123, properties.get(0).value());

}
 
Example 12
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
@Test
public void deserializersTestsProperty() {
    final TinkerGraph tg = TinkerGraph.open();

    final Vertex v = tg.addVertex("vertexTest");
    final Vertex v2 = tg.addVertex("vertexTest");

    final Edge ed = v.addEdge("knows", v2);

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final Property prop = ed.property("since", Year.parse("1993"));

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, prop);
        final String json = out.toString();

        final Property pRead = (Property)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        //can't use equals here, because pRead is detached, its parent element has not been intentionally
        //serialized and "equals()" checks that.
        assertTrue(prop.key().equals(pRead.key()) && prop.value().equals(pRead.value()));
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
Example 13
Source File: TinkerPopOperations.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
private void replaceRelation(Collection collection, UUID id, int rev, boolean accepted, String userId,
                             Instant instant)
  throws NotFoundException {

  requireCommit = true;

  // FIXME: string concatenating methods like this should be delegated to a configuration class
  final String acceptedPropName = collection.getEntityTypeName() + "_accepted";


  // FIXME: throw a AlreadyUpdatedException when the rev of the client is not the latest
  Optional<Edge> origEdgeOpt = indexHandler.findEdgeById(id);

  if (!origEdgeOpt.isPresent()) {
    throw new NotFoundException();
  }

  Edge origEdge = origEdgeOpt.get();
  if (!origEdge.property("isLatest").isPresent() || !(origEdge.value("isLatest") instanceof Boolean) ||
    !origEdge.<Boolean>value("isLatest")) {
    LOG.error("edge {} is not the latest edge, or it has no valid isLatest property.", origEdge.id());
  }

  //FIXME: throw a distinct Exception when the client tries to save a relation with wrong source, target or type.

  Edge edge = duplicateEdge(origEdge);
  edge.property(acceptedPropName, accepted);
  edge.property("rev", getProp(origEdge, "rev", Integer.class).orElse(1) + 1);
  setModified(edge, userId, instant);

  listener.onEdgeUpdate(collection, origEdge, edge);
}
 
Example 14
Source File: FactEdgeTest.java    From act-platform with ISC License 5 votes vote down vote up
@Test
public void testGetPropertyKeysOnEdge() {
  UUID factID = mockFact(null);
  Edge edge = new FactEdge(getActGraph(), factID, mockObject(), mockObject());

  // Test that the following properties exists on the edge.
  Map<String, Object> expected = MapUtils.map(
          T("factID", factID.toString()),
          T("value", "value"),
          T("inReferenceToID", "00000000-0000-0000-0000-000000000001"),
          T("organizationID", "00000000-0000-0000-0000-000000000002"),
          T("originID", "00000000-0000-0000-0000-000000000003"),
          T("trust", 0.3f),
          T("confidence", 0.5f),
          T("certainty", 0.15f),
          T("accessMode", "Public"),
          T("timestamp", 123456789L),
          T("lastSeenTimestamp", 987654321L)
  );

  Set<String> keys = edge.keys();
  Set<Property<Object>> properties = SetUtils.set(edge.properties());

  assertEquals(expected.size(), keys.size());
  assertEquals(expected.size(), properties.size());

  for (Map.Entry<String, Object> entry : expected.entrySet()) {
    assertTrue(keys.contains(entry.getKey()));

    Property<Object> property = edge.property(entry.getKey());
    assertEquals(entry.getValue(), property.value());
    assertEquals(StringFactory.propertyString(property), property.toString());
    assertSame(edge, property.element());
  }
}
 
Example 15
Source File: StarGraphTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY)
public void shouldHandleBothEdgesGraphFilterOnSelfLoop() {
    assertEquals(0l, IteratorUtils.count(graph.vertices()));
    assertEquals(0l, IteratorUtils.count(graph.edges()));

    // these vertex label, edge label, and property names/values were copied from existing tests
    StarGraph starGraph = StarGraph.open();
    Vertex vertex = starGraph.addVertex(T.label, "person", "name", "furnace");
    Edge edge = vertex.addEdge("self", vertex);
    edge.property("acl", "private");

    // traversing a self-loop should yield the edge once for inE/outE
    // and the edge twice for bothE (one edge emitted two times, not two edges)
    assertEquals(1L, IteratorUtils.count(starGraph.traversal().V().inE()));
    assertEquals(1L, IteratorUtils.count(starGraph.traversal().V().outE()));
    assertEquals(2L, IteratorUtils.count(starGraph.traversal().V().bothE()));
    
    // Try a filter that retains BOTH
    GraphFilter graphFilter = new GraphFilter();
    graphFilter.setEdgeFilter(__.bothE("self"));
    starGraph = starGraph.applyGraphFilter(graphFilter).get();

    // Retest traversal counts after filtering
    assertEquals(1L, IteratorUtils.count(starGraph.traversal().V().inE()));
    assertEquals(1L, IteratorUtils.count(starGraph.traversal().V().outE()));
    assertEquals(2L, IteratorUtils.count(starGraph.traversal().V().bothE()));
}
 
Example 16
Source File: GraphSONMessageSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSerializeEdge() throws Exception {
    final Graph g = TinkerGraph.open();
    final Vertex v1 = g.addVertex();
    final Vertex v2 = g.addVertex();
    final Edge e = v1.addEdge("test", v2);
    e.property("abc", 123);

    final Iterable<Edge> iterable = IteratorUtils.list(g.edges());
    final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(iterable).create());

    final JsonNode json = mapper.readTree(results);

    assertNotNull(json);
    assertEquals(msg.getRequestId().toString(), json.get(SerTokens.TOKEN_REQUEST).asText());
    final JsonNode converted = json.get(SerTokens.TOKEN_RESULT).get(SerTokens.TOKEN_DATA);

    assertNotNull(converted);
    assertEquals(1, converted.size());

    final JsonNode edgeAsJson = converted.get(0).get(GraphSONTokens.VALUEPROP);
    assertNotNull(edgeAsJson);

    assertEquals(((Long) e.id()).longValue(), edgeAsJson.get(GraphSONTokens.ID).get(GraphSONTokens.VALUEPROP).asLong());
    assertEquals(((Long) v1.id()).longValue(), edgeAsJson.get(GraphSONTokens.OUT).get(GraphSONTokens.VALUEPROP).asLong());
    assertEquals(((Long) v2.id()).longValue(), edgeAsJson.get(GraphSONTokens.IN).get(GraphSONTokens.VALUEPROP).asLong());
    assertEquals(e.label(), edgeAsJson.get(GraphSONTokens.LABEL).asText());

    final JsonNode properties = edgeAsJson.get(GraphSONTokens.PROPERTIES);
    assertNotNull(properties);
    assertEquals(123, properties.get("abc").get(GraphSONTokens.VALUEPROP).get("value").get(GraphSONTokens.VALUEPROP).asInt());
}
 
Example 17
Source File: BitsyMemGraphIT.java    From bitsy with Apache License 2.0 4 votes vote down vote up
public void testObsolescence() {
    IGraphStore store = ((BitsyGraph)graph).getStore();
    
    // Create a vertex
    Vertex v = graph.addVertex();
    Object vid = v.id();
    v.property("foo", "bar");
    
    // Self edge
    Edge e = v.addEdge("self", v);
    Object eid = e.id();
    
    graph.tx().commit();

    Record v1MRec = new Record(RecordType.V, "{\"id\":\"" + vid + "\",\"v\":1,\"s\":\"M\"}");
    assertFalse(v1MRec.checkObsolete(store, false, 1, null));
    assertFalse(v1MRec.checkObsolete(store, true, 1, null));

    Record e1MRec = new Record(RecordType.E, "{\"id\":\"" + eid + "\",\"v\":1,\"s\":\"M\",\"o\":\"" + vid + "\",\"l\":\"" + vid + "\",\"i\":\"" + vid + "\"}");
    assertFalse(e1MRec.checkObsolete(store, false, 1, null));
    assertFalse(e1MRec.checkObsolete(store, true, 1, null));

    // Create a vertex
    v = graph.vertices(vid).next();
    v.property("foo", "baz");

    e = v.edges(Direction.IN, "self").next();
    e.property("foo", "baz");

    graph.tx().commit();

    Record v2MRec = new Record(RecordType.V, "{\"id\":\"" + vid + "\",\"v\":2,\"s\":\"M\"}");
    Record v1DRec = new Record(RecordType.V, "{\"id\":\"" + vid + "\",\"v\":1,\"s\":\"D\"}");
    
    assertTrue(v1MRec.checkObsolete(store, false, 1, null));
    assertTrue(v1MRec.checkObsolete(store, true, 1, null));

    assertFalse(v1DRec.checkObsolete(store, false, 1, null));
    assertTrue(v1DRec.checkObsolete(store, true, 1, null));

    assertFalse(v2MRec.checkObsolete(store, false, 1, null));
    assertFalse(v2MRec.checkObsolete(store, true, 1, null));

    Record e2MRec = new Record(RecordType.E, "{\"id\":\"" + eid + "\",\"v\":2,\"s\":\"M\",\"o\":\"" + vid + "\",\"l\":\"" + vid + "\",\"i\":\"" + vid + "\"}");
    Record e1DRec = new Record(RecordType.E, "{\"id\":\"" + eid + "\",\"v\":1,\"s\":\"D\",\"o\":\"" + vid + "\",\"l\":\"" + vid + "\",\"i\":\"" + vid + "\"}");
    
    assertTrue(e1MRec.checkObsolete(store, false, 1, null));
    assertTrue(e1MRec.checkObsolete(store, true, 1, null));

    assertFalse(e1DRec.checkObsolete(store, false, 1, null));
    assertTrue(e1DRec.checkObsolete(store, true, 1, null));

    assertFalse(e2MRec.checkObsolete(store, false, 1, null));
    assertFalse(e2MRec.checkObsolete(store, true, 1, null));

    // Delete vertex
    v = graph.vertices(vid).next();
    v.remove();

    // Edge will get deleted automatically!
    
    graph.tx().commit();
    
    Record v2DRec = new Record(RecordType.V, "{\"id\":\"" + vid + "\",\"v\":1,\"s\":\"D\"}");
    assertFalse(v2DRec.checkObsolete(store, false, 1, null));
    assertTrue(v2DRec.checkObsolete(store, true, 1, null));
}
 
Example 18
Source File: FactEdgeTest.java    From act-platform with ISC License 4 votes vote down vote up
@Test
public void testReturnEmptyPropertyIfKeyNonExistent() {
  Edge edge = createEdge();
  Property property = edge.property("something");
  assertEquals(Property.empty(), property);
}
 
Example 19
Source File: EdgeManipulator.java    From timbuctoo with GNU General Public License v3.0 4 votes vote down vote up
private static void changeLatest(Edge duplicate, Edge edgeToDuplicate) {
  duplicate.property("isLatest", true);
  edgeToDuplicate.property("isLatest", false);
}
 
Example 20
Source File: StarGraphTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY)
@FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY)
@FeatureRequirement(featureClass = Graph.Features.EdgePropertyFeatures.class, feature = Graph.Features.EdgePropertyFeatures.FEATURE_STRING_VALUES)
public void shouldHandleSelfLoops() {
    assertEquals(0l, IteratorUtils.count(graph.vertices()));
    assertEquals(0l, IteratorUtils.count(graph.edges()));
    final Vertex vertex = graph.addVertex("person");
    final VertexProperty<String> vertexProperty = vertex.property("name", "furnace");
    final Edge edge = vertex.addEdge("self", vertex);
    final Property<String> edgeProperty = edge.property("acl", "private");
    assertEquals(1l, IteratorUtils.count(graph.vertices()));
    assertEquals(1l, IteratorUtils.count(graph.edges()));
    assertEquals(1l, IteratorUtils.count(vertex.properties()));
    assertEquals(1l, IteratorUtils.count(edge.properties()));
    assertEquals(vertexProperty, vertex.properties().next());
    assertEquals(edgeProperty, edge.properties().next());
    ///
    final StarGraph starGraph = StarGraph.of(vertex);
    final StarGraph.StarVertex starVertex = starGraph.getStarVertex();
    final Edge starEdge = starVertex.edges(Direction.OUT).next();
    assertEquals(vertex, starVertex);
    assertEquals(edge, starEdge);
    assertEquals(1l, IteratorUtils.count(starVertex.properties()));
    assertEquals("furnace", starVertex.value("name"));
    assertEquals(2l, IteratorUtils.count(starVertex.vertices(Direction.BOTH, "self")));
    assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.OUT, "self")));
    assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.IN, "self")));
    Iterator<Vertex> vertexIterator = starVertex.vertices(Direction.BOTH, "self");
    assertEquals(starVertex, vertexIterator.next());
    assertEquals(starVertex, vertexIterator.next());
    assertFalse(vertexIterator.hasNext());
    assertEquals(starVertex, starVertex.vertices(Direction.OUT, "self").next());
    assertEquals(starVertex, starVertex.vertices(Direction.IN, "self").next());
    ///
    assertEquals(2l, IteratorUtils.count(starVertex.vertices(Direction.BOTH)));
    assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.OUT)));
    assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.IN)));
    vertexIterator = starVertex.vertices(Direction.BOTH);
    assertEquals(starVertex, vertexIterator.next());
    assertEquals(starVertex, vertexIterator.next());
    assertFalse(vertexIterator.hasNext());
    assertEquals(starVertex, starVertex.vertices(Direction.OUT).next());
    assertEquals(starVertex, starVertex.vertices(Direction.IN).next());
    ///
    assertEquals(2l, IteratorUtils.count(starVertex.edges(Direction.BOTH, "self", "nothing")));
    assertEquals(1l, IteratorUtils.count(starVertex.edges(Direction.OUT, "self", "nothing")));
    assertEquals(1l, IteratorUtils.count(starVertex.edges(Direction.IN, "self", "nothing")));
    Iterator<Edge> edgeIterator = starVertex.edges(Direction.BOTH, "self", "nothing");
    Edge tempEdge = edgeIterator.next();
    assertEquals(1l, IteratorUtils.count(tempEdge.properties()));
    assertEquals("private", tempEdge.value("acl"));
    assertEquals(starEdge, tempEdge);
    tempEdge = edgeIterator.next();
    assertEquals(1l, IteratorUtils.count(tempEdge.properties()));
    assertEquals("private", tempEdge.value("acl"));
    assertEquals(starEdge, tempEdge);
    assertFalse(edgeIterator.hasNext());
    assertEquals(starEdge, starVertex.edges(Direction.OUT, "self", "nothing").next());
    assertEquals(starEdge, starVertex.edges(Direction.IN, "self", "nothing").next());
    //
    final StarGraph starGraphCopy = serializeDeserialize(starGraph).getValue0();
    TestHelper.validateVertexEquality(vertex, starGraph.getStarVertex(), true);
    TestHelper.validateVertexEquality(vertex, starGraphCopy.getStarVertex(), true);
    TestHelper.validateVertexEquality(starGraph.getStarVertex(), starGraphCopy.getStarVertex(), true);
    // test native non-clone-based methods
    final StarGraph starGraphNative = StarGraph.open();
    Vertex v1 = starGraphNative.addVertex(T.label, "thing", T.id, "v1");
    assertEquals("v1", v1.id());
    assertEquals("thing", v1.label());
    Edge e1 = v1.addEdge("self", v1, "name", "pipes");
    assertEquals(2l, IteratorUtils.count(v1.vertices(Direction.BOTH, "self", "nothing")));
    assertEquals(1l, IteratorUtils.count(v1.vertices(Direction.OUT)));
    assertEquals(1l, IteratorUtils.count(v1.vertices(Direction.IN, "self")));
    edgeIterator = v1.edges(Direction.BOTH);
    TestHelper.validateEdgeEquality(e1, edgeIterator.next());
    TestHelper.validateEdgeEquality(e1, edgeIterator.next());
    assertFalse(edgeIterator.hasNext());
    TestHelper.validateEdgeEquality(e1, v1.edges(Direction.OUT, "self", "nothing").next());
    TestHelper.validateEdgeEquality(e1, v1.edges(Direction.IN).next());
}