Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.Graph


* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class EdgeHelperTest extends BaseTest {

    public void testRelabelEdge() {
        Graph graph = TinkerGraphFactory.createTinkerGraph();
        EdgeHelper.relabelEdge(graph, graph.getEdge(7), "1234", "use_to_know");
        assertEquals(count(graph.getVertices()), 6);
        assertEquals(count(graph.getEdges()), 6);
        int counter = 0;
        int counter2 = 0;
        Edge temp = null;
        for (Edge edge : graph.getVertex(1).getEdges(Direction.OUT)) {
            if (edge.getLabel().equals("use_to_know")) {
                counter++;
                assertEquals(edge.getId(), "1234");
                assertEquals(edge.getProperty("weight"), 0.5f);
                temp = edge;
            }

            counter2++;
        }
        assertEquals(counter, 1);
        assertEquals(counter2, 3);

        counter = 0;
        counter2 = 0;
        for (Edge edge : graph.getVertex(2).getEdges(Direction.IN)) {
            if (edge.getLabel().equals("use_to_know")) {
                counter++;
                assertEquals(edge.getId(), "1234");
                assertEquals(edge.getProperty("weight"), 0.5f);
                assertEquals(edge, temp);
View Full Code Here


        assertEquals(counter, 1);
        assertEquals(counter2, 1);
    }

    public void testRelabelEdges() {
        Graph graph = TinkerGraphFactory.createTinkerGraph();
        EdgeHelper.relabelEdges(graph, Arrays.asList(graph.getEdge(7)), "use_to_know");
        assertEquals(count(graph.getVertices()), 6);
        assertEquals(count(graph.getEdges()), 6);
        int counter = 0;
        int counter2 = 0;
        Edge temp = null;
        for (Edge edge : graph.getVertex(1).getEdges(Direction.OUT)) {
            if (edge.getLabel().equals("use_to_know")) {
                counter++;
                assertEquals(edge.getProperty("weight"), 0.5f);
                temp = edge;
            }

            counter2++;
        }
        assertEquals(counter, 1);
        assertEquals(counter2, 3);

        counter = 0;
        counter2 = 0;
        for (Edge edge : graph.getVertex(2).getEdges(Direction.IN)) {
            if (edge.getLabel().equals("use_to_know")) {
                counter++;
                assertEquals(edge.getProperty("weight"), 0.5f);
                assertEquals(edge, temp);
            }
View Full Code Here

        assertEquals(counter, 1);
        assertEquals(counter2, 1);
    }

    public void testGetOther() {
        Graph graph = TinkerGraphFactory.createTinkerGraph();
        for (Vertex vertex : graph.getVertices()) {
            for (Edge edge : vertex.getEdges(Direction.BOTH)) {
                assertNotSame(vertex, EdgeHelper.getOther(edge, vertex));
            }
        }
    }
View Full Code Here

* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class VertexHelperTest extends BaseTest {

    public void testEdgeSetEquality() {
        Graph graph = TinkerGraphFactory.createTinkerGraph();

        for (Vertex v : graph.getVertices()) {
            for (Vertex u : graph.getVertices()) {
                if (ElementHelper.areEqual(v, u)) {
                    assertTrue(VertexHelper.haveEqualEdges(v, u, true));
                    assertTrue(VertexHelper.haveEqualEdges(v, u, false));
                } else {
                    assertFalse(VertexHelper.haveEqualEdges(v, u, true));
View Full Code Here

        }

    }

    public void testNeighborhoodEquality() {
        Graph graph = TinkerGraphFactory.createTinkerGraph();

        for (Vertex v : graph.getVertices()) {
            for (Vertex u : graph.getVertices()) {
                if (ElementHelper.areEqual(v, u)) {
                    assertTrue(VertexHelper.haveEqualNeighborhood(v, u, true));
                    assertTrue(VertexHelper.haveEqualNeighborhood(v, u, false));
                } else {
                    assertFalse(VertexHelper.haveEqualNeighborhood(v, u, true));
View Full Code Here

    private final URI markoKnowsVadas, markoKnowsJosh, markoCreatedLop, joshCreatedRipple, joshCreatedLop, peterCreatedLop;

    private SailConnection sc;

    public PropertyGraphSailTest() throws Exception {
        Graph g = new TinkerGraph();
        GraphMLReader r = new GraphMLReader(g);
        r.inputGraph(GraphMLReader.class.getResourceAsStream("graph-example-1.xml"));

        sail = new PropertyGraphSail(g);
        sail.initialize();
View Full Code Here

        Vertex v2 = g2.getVertex(1);
        assertEquals("\u00E9", v2.getProperty("text"));
    }

    public void testStreamStaysOpen() throws IOException {
        final Graph g = TinkerGraphFactory.createTinkerGraph();
        final PrintStream oldStream = System.out;
        final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
        System.setOut(new PrintStream(outContent));

        final GraphMLWriter writer = new GraphMLWriter(g);
View Full Code Here

        Assert.assertFalse(json.has("alwaysNull"));
    }

    @Test
    public void jsonFromElementNullsNoKeysNoTypes() throws JSONException {
        Graph g = new TinkerGraph();
        Vertex v = g.addVertex(1);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("innerkey", null);

        List<String> innerList = new ArrayList<String>();
View Full Code Here

        Assert.assertEquals("string", jsonArray.get(1));
    }

    @Test
    public void jsonFromElementNullsNoKeysWithTypes() throws JSONException {
        Graph g = new TinkerGraph();
        Vertex v = g.addVertex(1);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("innerkey", null);

        List<String> innerList = new ArrayList<String>();
View Full Code Here

        Assert.assertEquals(GraphSONTokens.TYPE_UNKNOWN, jsonObjectListFirst.optString(GraphSONTokens.TYPE));
    }

    @Test
    public void vertexFromJsonValid() throws IOException, JSONException {
        Graph g = new TinkerGraph();
        ElementFactory factory = new GraphElementFactory(g);

        Vertex v = GraphSONUtility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)), factory, GraphSONMode.NORMAL, null);

        Assert.assertSame(v, g.getVertex(1));

        // tinkergraph converts id to string
        Assert.assertEquals("1", v.getId());
        Assert.assertEquals("marko", v.getProperty("name"));
        Assert.assertEquals(29, v.getProperty("age"));
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.Graph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.