Package com.tinkerpop.blueprints.impls.tg

Examples of com.tinkerpop.blueprints.impls.tg.TinkerGraph$TinkerKeyIndex


    }

    @Test(expected = IllegalArgumentException.class)
    public void inputGraphCompactFullCycleBroken() throws IOException {
        TinkerGraph graph = TinkerGraphFactory.createTinkerGraph();

        ByteArrayOutputStream stream = new ByteArrayOutputStream();

        Set<String> edgeKeys = new HashSet<String>();
        edgeKeys.add(GraphSONTokens._IN_V);
        edgeKeys.add(GraphSONTokens._OUT_V);
        edgeKeys.add(GraphSONTokens._LABEL);

        Set<String> vertexKeys = new HashSet<String>();

        GraphSONWriter writer = new GraphSONWriter(graph);
        writer.outputGraph(stream, vertexKeys, edgeKeys, GraphSONMode.COMPACT);

        stream.flush();
        stream.close();

        String jsonString = new String(stream.toByteArray());

        byte[] bytes = jsonString.getBytes();
        InputStream inputStream = new ByteArrayInputStream(bytes);

        TinkerGraph emptyGraph = new TinkerGraph();
        GraphSONReader.inputGraph(emptyGraph, inputStream);

    }
View Full Code Here


    private static final String LABEL = "label";

    @Test
    public void exampleGMLGetsCorrectNumberOfElements() throws IOException {
        TinkerGraph graph = new TinkerGraph();

        GMLReader.inputGraph(graph, GMLReader.class.getResourceAsStream("example.gml"));

        Assert.assertEquals(3, getIterableCount(graph.getVertices()));
        Assert.assertEquals(3, getIterableCount(graph.getEdges()));
    }
View Full Code Here

        Assert.assertEquals(3, getIterableCount(graph.getEdges()));
    }

    @Test
    public void exampleGMLGetsCorrectTopology() throws IOException {
        TinkerGraph graph = new TinkerGraph();

        GMLReader.inputGraph(graph, GMLReader.class.getResourceAsStream("example.gml"));

        Vertex v1 = graph.getVertex(1);
        Vertex v2 = graph.getVertex(2);
        Vertex v3 = graph.getVertex(3);

        Iterable<Edge> out1 = v1.getEdges(Direction.OUT);
        Edge e1 = out1.iterator().next();
        Assert.assertEquals(v2, e1.getVertex(Direction.IN));
View Full Code Here

    }

    @Test
    public void exampleGMLGetsCorrectProperties() throws IOException {
        TinkerGraph graph = new TinkerGraph();

        GMLReader.inputGraph(graph, GMLReader.class.getResourceAsStream("example.gml"));

        Vertex v1 = graph.getVertex(1);
        Assert.assertEquals("Node 1", v1.getProperty(LABEL));

        Vertex v2 = graph.getVertex(2);
        Assert.assertEquals("Node 2", v2.getProperty(LABEL));

        Vertex v3 = graph.getVertex(3);
        Assert.assertEquals("Node 3", v3.getProperty(LABEL));

        Iterable<Edge> out1 = v1.getEdges(Direction.OUT);
        Edge e1 = out1.iterator().next();
        Assert.assertEquals("Edge from node 1 to node 2", e1.getLabel());
View Full Code Here

    }

    @Test(expected = IOException.class)
    public void malformedThrowsIOException() throws IOException {
        GMLReader.inputGraph(new TinkerGraph(), GMLReader.class.getResourceAsStream("malformed.gml"));
    }
View Full Code Here

        GMLReader.inputGraph(new TinkerGraph(), GMLReader.class.getResourceAsStream("malformed.gml"));
    }

    @Test
    public void example2GMLTestingMapParsing() throws IOException {
        TinkerGraph graph = new TinkerGraph();

        GMLReader.inputGraph(graph, GMLReader.class.getResourceAsStream("example2.gml"));

        Assert.assertEquals(2, getIterableCount(graph.getVertices()));
        Assert.assertEquals(1, getIterableCount(graph.getEdges()));

        Object property = graph.getVertex(1).getProperty(GMLTokens.GRAPHICS);
        Assert.assertTrue(property instanceof Map<?, ?>);

        @SuppressWarnings("unchecked")
        Map<String, Object> map = (Map<String, Object>) property;
        Assert.assertEquals(5, map.size());
View Full Code Here

    }

    @Test
    public void testEscapeQuotation() throws Exception {
        TinkerGraph graph = new TinkerGraph();
        GMLReader.inputGraph(graph, GMLReader.class.getResourceAsStream("example.gml"));
        Vertex v3 = graph.getVertex(3);
        Object tempProperty = v3.getProperty("escape_property");
        Assert.assertNotNull(tempProperty);
        Assert.assertEquals("Node 3 \"with quote\"", tempProperty);
    }
View Full Code Here

        Assert.assertEquals("Node 3 \"with quote\"", tempProperty);
    }

    @Test
    public void testIdGenerationInGML() throws IOException {
        TinkerGraph graph1 = new TinkerGraph();
        GMLReader.inputGraph(graph1, GMLReader.class.getResourceAsStream("simple.gml"));

        Vertex toRemove = graph1.getVertex("123");
        graph1.removeVertex(toRemove);

        String file = "/tmp/simple-" + UUID.randomUUID() + ".gml";
        GMLWriter.outputGraph(graph1, file);

        TinkerGraph graph2 = new TinkerGraph();
        GMLReader.inputGraph(graph2, file);

        String gml = new String(Files.readAllBytes(Paths.get(file)));
        String sep = "\r\n";
        String expected = "graph [" + sep +
                          "\tnode [" + sep +
                          "\t\tid 1" + sep +
                          "\t\tblueprintsId \"456\"" + sep +
                          "\t]" + sep +
                          "]" + sep;
        Assert.assertEquals(expected, gml);
        Assert.assertEquals(1, getIterableCount(graph2.getVertices()));
    }
View Full Code Here

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

    public void testCopyElementProperties() {
        Graph graph = new TinkerGraph();
        Vertex v = graph.addVertex(null);
        v.setProperty("name", "marko");
        v.setProperty("age", 31);
        Vertex u = graph.addVertex(null);
        assertEquals(u.getPropertyKeys().size(), 0);
        ElementHelper.copyProperties(v, u);
        assertEquals(u.getPropertyKeys().size(), 2);
        assertEquals(u.getProperty("name"), "marko");
        assertEquals(u.getProperty("age"), 31);
View Full Code Here

            assertTrue(e.getProperty("weight") instanceof Double);
        }
    }

    public void testHaveEqualProperties() {
        Graph graph = new TinkerGraph();
        Vertex a = graph.addVertex(null);
        Vertex b = graph.addVertex(null);
        Vertex c = graph.addVertex(null);
        Vertex d = graph.addVertex(null);

        a.setProperty("name", "marko");
        a.setProperty("age", 31);
        b.setProperty("name", "marko");
        b.setProperty("age", 31);
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.impls.tg.TinkerGraph$TinkerKeyIndex

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.