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"));
}
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));
}
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"));
}
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"));
}
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));
}
Aggregations