Search in sources :

Example 61 with HashSet

use of java.util.HashSet in project blueprints by tinkerpop.

the class GraphSONUtilityTest method vertexFromJsonIgnoreKeyValid.

@Test
public void vertexFromJsonIgnoreKeyValid() throws IOException, JSONException {
    Graph g = new TinkerGraph();
    ElementFactory factory = new GraphElementFactory(g);
    Set<String> ignoreAge = new HashSet<String>();
    ignoreAge.add("age");
    ElementPropertyConfig config = ElementPropertyConfig.excludeProperties(ignoreAge, null);
    GraphSONUtility utility = new GraphSONUtility(GraphSONMode.NORMAL, factory, config);
    Vertex v = utility.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)));
    Assert.assertSame(v, g.getVertex(1));
    // tinkergraph converts id to string
    Assert.assertEquals("1", v.getId());
    Assert.assertEquals("marko", v.getProperty("name"));
    Assert.assertNull(v.getProperty("age"));
}
Also used : JSONTokener(org.codehaus.jettison.json.JSONTokener) Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) JSONObject(org.codehaus.jettison.json.JSONObject) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 62 with HashSet

use of java.util.HashSet in project blueprints by tinkerpop.

the class ReadOnlyGraphTest method testWrappedElementUniqueness.

public void testWrappedElementUniqueness() {
    Graph graph = new ReadOnlyGraph<TinkerGraph>(TinkerGraphFactory.createTinkerGraph());
    assertEquals(graph.getVertex(1), graph.getVertex(1));
    Set<Vertex> set = new HashSet<Vertex>();
    set.add(graph.getVertex(2));
    set.add(graph.getVertex(2));
    assertEquals(set.size(), 1);
    assertEquals(graph.getEdge(7).hashCode(), graph.getEdge(7).hashCode());
    assertEquals(graph.getEdge(8), graph.getEdge(8));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) WrapperGraph(com.tinkerpop.blueprints.util.wrappers.WrapperGraph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IndexableGraph(com.tinkerpop.blueprints.IndexableGraph) Graph(com.tinkerpop.blueprints.Graph) HashSet(java.util.HashSet)

Example 63 with HashSet

use of java.util.HashSet in project blueprints by tinkerpop.

the class GraphSONUtilityTest method jsonFromElementEdgeCompactIdOnlyAsExclude.

@Test
public void jsonFromElementEdgeCompactIdOnlyAsExclude() throws JSONException {
    ElementFactory factory = new GraphElementFactory(this.graph);
    Vertex v1 = this.graph.addVertex(1);
    Vertex v2 = this.graph.addVertex(2);
    Edge e = this.graph.addEdge(3, v1, v2, "test");
    e.setProperty("weight", 0.5f);
    e.setProperty("x", "y");
    Set<String> propertiesToExclude = new HashSet<String>() {

        {
            add(GraphSONTokens._TYPE);
            add(GraphSONTokens._LABEL);
            add(GraphSONTokens._IN_V);
            add(GraphSONTokens._OUT_V);
            add("weight");
        }
    };
    ElementPropertyConfig config = new ElementPropertyConfig(null, propertiesToExclude, ElementPropertyConfig.ElementPropertiesRule.INCLUDE, ElementPropertyConfig.ElementPropertiesRule.EXCLUDE);
    GraphSONUtility utility = new GraphSONUtility(GraphSONMode.COMPACT, factory, config);
    JSONObject json = utility.jsonFromElement(e);
    Assert.assertNotNull(json);
    Assert.assertFalse(json.has(GraphSONTokens._TYPE));
    Assert.assertFalse(json.has(GraphSONTokens._LABEL));
    Assert.assertFalse(json.has(GraphSONTokens._IN_V));
    Assert.assertFalse(json.has(GraphSONTokens._OUT_V));
    Assert.assertTrue(json.has(GraphSONTokens._ID));
    Assert.assertFalse(json.has("weight"));
    Assert.assertTrue(json.has("x"));
    Assert.assertEquals("y", json.optString("x"));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) JSONObject(org.codehaus.jettison.json.JSONObject) Edge(com.tinkerpop.blueprints.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 64 with HashSet

use of java.util.HashSet in project blueprints by tinkerpop.

the class GraphSONUtilityTest method jsonFromElementVertexCompactIdOnlyAsInclude.

@Test
public void jsonFromElementVertexCompactIdOnlyAsInclude() throws JSONException {
    Vertex v = this.graph.addVertex(1);
    v.setProperty("name", "marko");
    Set<String> propertiesToInclude = new HashSet<String>() {

        {
            add(GraphSONTokens._ID);
        }
    };
    JSONObject json = GraphSONUtility.jsonFromElement(v, propertiesToInclude, GraphSONMode.COMPACT);
    Assert.assertNotNull(json);
    Assert.assertFalse(json.has(GraphSONTokens._TYPE));
    Assert.assertTrue(json.has(GraphSONTokens._ID));
    Assert.assertFalse(json.has("name"));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) JSONObject(org.codehaus.jettison.json.JSONObject) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 65 with HashSet

use of java.util.HashSet in project blueprints by tinkerpop.

the class GraphSONUtilityTest method edgeFromJsonInputStreamCompactNoIdOnEdge.

@Test
public void edgeFromJsonInputStreamCompactNoIdOnEdge() throws IOException, JSONException {
    Graph g = new TinkerGraph();
    ElementFactory factory = new GraphElementFactory(g);
    Set<String> vertexKeys = new HashSet<String>() {

        {
            add(GraphSONTokens._ID);
        }
    };
    Set<String> edgeKeys = new HashSet<String>() {

        {
            add(GraphSONTokens._IN_V);
        }
    };
    GraphSONUtility graphson = new GraphSONUtility(GraphSONMode.COMPACT, factory, vertexKeys, edgeKeys);
    Vertex v1 = graphson.vertexFromJson(new JSONObject(new JSONTokener(vertexJson1)));
    Vertex v2 = graphson.vertexFromJson(new JSONObject(new JSONTokener(vertexJson2)));
    Edge e = graphson.edgeFromJson(inputStreamEdgeJsonLight, v1, v2);
    Assert.assertSame(v1, g.getVertex(1));
    Assert.assertSame(v2, g.getVertex(2));
    Assert.assertSame(e, g.getEdge(0));
}
Also used : JSONTokener(org.codehaus.jettison.json.JSONTokener) Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) JSONObject(org.codehaus.jettison.json.JSONObject) Edge(com.tinkerpop.blueprints.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

HashSet (java.util.HashSet)13945 Set (java.util.Set)2858 ArrayList (java.util.ArrayList)2664 Test (org.junit.Test)2369 HashMap (java.util.HashMap)2357 Map (java.util.Map)1363 List (java.util.List)1033 IOException (java.io.IOException)1032 Iterator (java.util.Iterator)1030 File (java.io.File)684 LinkedHashSet (java.util.LinkedHashSet)561 Test (org.testng.annotations.Test)534 TreeSet (java.util.TreeSet)288 Collection (java.util.Collection)281 LinkedList (java.util.LinkedList)270 LinkedHashMap (java.util.LinkedHashMap)232 Region (org.apache.geode.cache.Region)202 Date (java.util.Date)195 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)192 Method (java.lang.reflect.Method)189