Search in sources :

Example 6 with Edge

use of com.tinkerpop.blueprints.Edge in project pentaho-metaverse by pentaho.

the class MetaverseBuilderTest method testAddLink2.

@Test
public void testAddLink2() {
    MetaverseTransientNode node2 = new MetaverseTransientNode();
    node2.setStringID("nodeToId");
    node2.setName("to name");
    builder.addLink(node, "uses", node2);
    Vertex fromResult = graph.getVertex(node.getStringID());
    Vertex toResult = graph.getVertex(node2.getStringID());
    // we added this node implicitly through the addLink, it should be flagged as virtual
    assertTrue((Boolean) fromResult.getProperty(DictionaryConst.NODE_VIRTUAL));
    // we added this node implicitly through the addLink, it should be flagged as virtual
    assertTrue((Boolean) toResult.getProperty(DictionaryConst.NODE_VIRTUAL));
    assertNotNull(fromResult.getEdges(Direction.OUT, "uses"));
    for (Edge e : fromResult.getEdges(Direction.OUT, "uses")) {
        assertEquals(e.getVertex(Direction.OUT).getProperty("name"), node.getName());
        assertEquals(e.getVertex(Direction.IN).getProperty("name"), node2.getName());
        // we added this node implicitly through the addLink, it should be flagged as virtual
        assertTrue((Boolean) e.getVertex(Direction.OUT).getProperty(DictionaryConst.NODE_VIRTUAL));
    }
    assertNotNull(toResult.getEdges(Direction.IN, "uses"));
    for (Edge e : fromResult.getEdges(Direction.IN, "uses")) {
        assertEquals(e.getVertex(Direction.OUT).getProperty("name"), node.getName());
        assertEquals(e.getVertex(Direction.IN).getProperty("name"), node2.getName());
        // we added this node implicitly through the addLink, it should be flagged as virtual
        assertTrue((Boolean) e.getVertex(Direction.IN).getProperty(DictionaryConst.NODE_VIRTUAL));
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) MetaverseTransientNode(org.pentaho.dictionary.MetaverseTransientNode) Edge(com.tinkerpop.blueprints.Edge) Test(org.junit.Test)

Example 7 with Edge

use of com.tinkerpop.blueprints.Edge in project pentaho-metaverse by pentaho.

the class MetaverseBuilderTest method testAddLink.

@Test
public void testAddLink() {
    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());
    // we added this node implicitly through the addLink, it should be flagged as virtual
    assertTrue((Boolean) fromResult.getProperty(DictionaryConst.NODE_VIRTUAL));
    // we added this node implicitly through the addLink, it should be flagged as virtual
    assertTrue((Boolean) toResult.getProperty(DictionaryConst.NODE_VIRTUAL));
    assertNotNull(fromResult.getEdges(Direction.OUT, "uses"));
    for (Edge e : fromResult.getEdges(Direction.OUT, "uses")) {
        assertEquals(e.getVertex(Direction.OUT).getProperty("name"), node.getName());
        assertEquals(e.getVertex(Direction.IN).getProperty("name"), node2.getName());
        // we added this node implicitly through the addLink, it should be flagged as virtual
        assertTrue((Boolean) e.getVertex(Direction.OUT).getProperty(DictionaryConst.NODE_VIRTUAL));
    }
    assertNotNull(toResult.getEdges(Direction.IN, "uses"));
    for (Edge e : fromResult.getEdges(Direction.IN, "uses")) {
        assertEquals(e.getVertex(Direction.OUT).getProperty("name"), node.getName());
        assertEquals(e.getVertex(Direction.IN).getProperty("name"), node2.getName());
        // we added this node implicitly through the addLink, it should be flagged as virtual
        assertTrue((Boolean) e.getVertex(Direction.IN).getProperty(DictionaryConst.NODE_VIRTUAL));
    }
}
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)

Example 8 with Edge

use of com.tinkerpop.blueprints.Edge in project pentaho-metaverse by pentaho.

the class MetaverseBuilderTest method testCopyLinkPropertiesToEdge.

@Test
public void testCopyLinkPropertiesToEdge() {
    final String LABEL = "myLabel";
    IMetaverseLink link = new MetaverseLink();
    link.setLabel("sourceLabel");
    // Create from/to nodes and an edge between them
    Vertex fromNode = graph.addVertex("from");
    Vertex toNode = graph.addVertex("to");
    Edge edge = graph.addEdge("myId", fromNode, toNode, LABEL);
    // Call with null for branch coverage (and to prove no NPE occurs)
    builder.copyLinkPropertiesToEdge(null, edge);
    builder.copyLinkPropertiesToEdge(link, null);
    // Call with empty list for branch coverage (and to prove no NPE occurs)
    builder.copyLinkPropertiesToEdge(link, edge);
    // Set some properties on the source link
    link.setProperty(DictionaryConst.PROPERTY_LABEL, "sourceLabel");
    link.setProperty(DictionaryConst.PROPERTY_NAME, "sourceLink");
    // Set some properties on the target edge (including the reserved one "label")
    edge.setProperty(DictionaryConst.PROPERTY_NAME, "myEdge");
    edge.setProperty(DictionaryConst.PROPERTY_TYPE, "relates to");
    // Invoke the method under test and see that the appropriate properties are set on the target edge
    builder.copyLinkPropertiesToEdge(link, edge);
    assertEquals("sourceLink", edge.getProperty(DictionaryConst.PROPERTY_NAME));
    assertEquals("relates to", edge.getProperty(DictionaryConst.PROPERTY_TYPE));
    // The label should not be overridden (Blueprints does not allow it)
    assertEquals(LABEL, edge.getLabel());
    // The property "label" is not set on the edge by either setLabel() or the method under test
    // It's a Blueprints thing
    assertNull(edge.getProperty(DictionaryConst.PROPERTY_LABEL));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) MetaverseLink(org.pentaho.dictionary.MetaverseLink) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) Edge(com.tinkerpop.blueprints.Edge) Test(org.junit.Test)

Example 9 with Edge

use of com.tinkerpop.blueprints.Edge in project wildfly-swarm by wildfly-swarm.

the class OrientDBArquillianTest method shouldAddAFriendshipToTheGraph.

@Test
public void shouldAddAFriendshipToTheGraph() {
    String firstName = "test-name-" + LocalTime.now();
    String secondName = "test-name-" + LocalTime.now();
    OrientEdge edge = statefulTestBean.addFriend(firstName, secondName);
    assertEquals(firstName, edge.getVertex(Direction.OUT).getProperty("name"));
    assertEquals(secondName, edge.getVertex(Direction.IN).getProperty("name"));
    assertEquals("knows", edge.getLabel());
    List<Edge> edges = statefulTestBean.getFriends();
    assertEquals(1, edges.size());
    assertEquals(edge, edges.get(0));
}
Also used : Edge(com.tinkerpop.blueprints.Edge) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Test(org.junit.Test)

Example 10 with Edge

use of com.tinkerpop.blueprints.Edge in project wildfly-swarm by wildfly-swarm.

the class TestPeopleDao method getFriends.

public List<Edge> getFriends() {
    List<Edge> edges = new LinkedList<>();
    OrientGraph database = new OrientGraph(databasePool);
    try {
        database.getEdges().forEach(edges::add);
    } finally {
        database.shutdown();
    }
    return edges;
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientEdge(com.tinkerpop.blueprints.impls.orient.OrientEdge) Edge(com.tinkerpop.blueprints.Edge) LinkedList(java.util.LinkedList)

Aggregations

Edge (com.tinkerpop.blueprints.Edge)214 Vertex (com.tinkerpop.blueprints.Vertex)141 Test (org.junit.Test)53 Graph (com.tinkerpop.blueprints.Graph)49 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)49 HashSet (java.util.HashSet)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)13 ArrayList (java.util.ArrayList)13 Collection (java.util.Collection)11 JSONObject (org.codehaus.jettison.json.JSONObject)11 HashMap (java.util.HashMap)10 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)9 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)8 Map (java.util.Map)8 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)6 URI (org.openrdf.model.URI)6