Search in sources :

Example 6 with MetaverseLink

use of org.pentaho.dictionary.MetaverseLink in project pentaho-metaverse by pentaho.

the class MetaverseBuilderTest method testAddLink_existingLink.

@Test
public void testAddLink_existingLink() throws Exception {
    // Retain current number of edges
    int originalEdgeCount = 0;
    for (Edge e : graph.getEdges()) {
        originalEdgeCount++;
    }
    MetaverseTransientNode node2 = new MetaverseTransientNode();
    node2.setStringID("nodeToId");
    node2.setName("to name");
    MetaverseLink link = new MetaverseLink(node, "uses", node2);
    builder.addLink(link);
    Vertex fromResult = graph.getVertex(node.getStringID());
    Vertex toResult = graph.getVertex(node2.getStringID());
    // make sure the edge exits before we try to add it again
    assertNotNull(graph.getEdge(builder.getEdgeId(fromResult, link.getLabel(), toResult)));
    // make sure we only added 1
    int count = 0;
    for (Edge e : graph.getEdges()) {
        count++;
    }
    assertEquals(originalEdgeCount + 1, count);
    // now lets add it again
    builder.addLink(link);
    // make sure we still only have one edge
    count = 0;
    for (Edge e : graph.getEdges()) {
        count++;
    }
    assertEquals(originalEdgeCount + 1, count);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) MetaverseLink(org.pentaho.dictionary.MetaverseLink) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) Edge(com.tinkerpop.blueprints.Edge) Test(org.junit.Test)

Aggregations

MetaverseLink (org.pentaho.dictionary.MetaverseLink)6 Vertex (com.tinkerpop.blueprints.Vertex)5 IMetaverseLink (org.pentaho.metaverse.api.IMetaverseLink)5 Edge (com.tinkerpop.blueprints.Edge)4 Test (org.junit.Test)4 MetaverseTransientNode (org.pentaho.dictionary.MetaverseTransientNode)3 Direction (com.tinkerpop.blueprints.Direction)1 Before (org.junit.Before)1 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)1 MetaverseNode (org.pentaho.metaverse.impl.MetaverseNode)1