/** * Checks if a property with the given key is contained in the properties. * * @param key property key * @return true, if there is a property with the given key */ public boolean containsKey(String key) { return get(key) != null; }
@Override public PropertyValue getPropertyValue(String key) { // TODO: return PropertyValue.NULL_VALUE instead? return (properties != null) ? properties.get(key) : null; }
@Test public void testGet() throws Exception { Properties properties = Properties.createFromMap(SUPPORTED_PROPERTIES); assertNotNull("property was null", properties.get(KEY_1)); assertEquals("wrong property", BOOL_VAL_1, properties.get(KEY_1).getBoolean()); assertNull("unexpected property", properties.get("1234")); }
@Test public void testCreateFromMap() throws Exception { Properties properties = Properties.createFromMap(SUPPORTED_PROPERTIES); assertEquals(SUPPORTED_PROPERTIES.size(), properties.size()); for (Map.Entry<String, Object> entry : SUPPORTED_PROPERTIES.entrySet()) { String k = entry.getKey(); assertTrue(properties.containsKey(k)); assertEquals(entry.getValue(), properties.get(k).getObject()); } }
/** * find all vertices by property value regex * * @throws Throwable if error */ @Test public void propRegex() throws Throwable { doTest(TEST03, (loader, store, config) -> { Pattern queryFormula = Pattern.compile("(Leipzig|Dresden)"); List<Vertex> inputVertices = loader.getVertices().stream() .filter(it -> { assert it.getProperties() != null; return it.getProperties().get("city") != null && it.getProperties().get("city").isString() && queryFormula .matcher(it.getProperties().get("city").getString()) .matches(); }) .collect(Collectors.toList()); List<Vertex> query = store .getVertexSpace( Query.elements() .fromAll() .where(AccumuloFilters.propReg("city", queryFormula))) .readRemainsAndClose(); GradoopTestUtils.validateEPGMElementCollections(inputVertices, query); }); }
/** * Find all person who's age is not smaller than 35 * * @throws Throwable if error */ @Test public void findPersonByAge() throws Throwable { doTest(TEST02, (loader, store, config) -> { //vertex label and property query List<Vertex> inputVertices = loader.getVertices() .stream() .filter(it -> Objects.equals(it.getLabel(), "Person")) .filter(it -> it.getProperties() != null) .filter(it -> it.getProperties().get("age") != null) .filter(it -> it.getProperties().get("age").getInt() >= 35) .collect(Collectors.toList()); List<Vertex> queryResult = store .getVertexSpace( Query.elements() .fromAll() .where(AccumuloFilters.propLargerThan("age", 35, true))) .readRemainsAndClose(); validateEPGMElementCollections(inputVertices, queryResult); }); }
@Test public void testSet() throws Exception { Properties properties = Properties.create(); properties.set(Property.create(KEY_1, BOOL_VAL_1)); assertEquals(BOOL_VAL_1, properties.get(KEY_1).getObject()); // override properties.set(Property.create(KEY_1, INT_VAL_2)); assertEquals(INT_VAL_2, properties.get(KEY_1).getObject()); }
@Test public void testSet1() throws Exception { Properties properties = Properties.create(); properties.set(KEY_1, PropertyValue.create(BOOL_VAL_1)); assertEquals(BOOL_VAL_1, properties.get(KEY_1).getObject()); // override properties.set(KEY_1, PropertyValue.create(INT_VAL_2)); assertEquals(INT_VAL_2, properties.get(KEY_1).getObject()); }
/** * find all edges by property equality * * @throws Throwable if error */ @Test public void edgePropEquals() throws Throwable { doTest(TEST02, (loader, store, config) -> { List<Edge> inputVertices = loader.getEdges().stream() .filter(it -> { assert it.getProperties() != null; return it.getProperties().get("since") != null && Objects.equals(it.getProperties() .get("since") .getInt(), 2014); }) .collect(Collectors.toList()); List<Edge> query = store .getEdgeSpace( Query.elements() .fromAll() .where(AccumuloFilters.propEquals("since", 2014))) .readRemainsAndClose(); GradoopTestUtils.validateEPGMElementCollections(inputVertices, query); }); }
/** * find all edges by property value compare * * @throws Throwable if error */ @Test public void propLargerThan() throws Throwable { doTest(TEST04, (loader, store, config) -> { List<Edge> inputVertices = loader.getEdges().stream() .filter(it -> { assert it.getProperties() != null; return it.getProperties().get("since") != null && it.getProperties().get("since").isInt() && it.getProperties() .get("since") .getInt() >= 2014; }) .collect(Collectors.toList()); List<Edge> query = store .getEdgeSpace( Query.elements() .fromAll() .where(AccumuloFilters .propLargerThan("since", 2014, true))) .readRemainsAndClose(); GradoopTestUtils.validateEPGMElementCollections(inputVertices, query); }); }
/** * find all vertices by property equality * * @throws Throwable if error */ @Test public void vertexPropEquals() throws Throwable { doTest(TEST01, (loader, store, config) -> { List<Vertex> inputVertices = loader.getVertices().stream() .filter(it -> { assert it.getProperties() != null; return it.getProperties().get("gender") != null && Objects.equals(it.getProperties() .get("gender") .getString(), "f"); }) .collect(Collectors.toList()); List<Vertex> query = store .getVertexSpace( Query.elements() .fromAll() .where(AccumuloFilters.propEquals("gender", "f"))) .readRemainsAndClose(); GradoopTestUtils.validateEPGMElementCollections(inputVertices, query); }); }
/** * Find all person who's age is not smaller than 35 * * @throws Throwable if error */ @Test public void findPersonByAgeBiggerThan35() throws Throwable { doTest(TEST02, (loader, store, config) -> { //vertex label and property query List<Vertex> inputVertices = loader.getVertices() .stream() .filter(it -> Objects.equals(it.getLabel(), "Person")) .filter(it -> it.getProperties() != null) .filter(it -> it.getProperties().get("age") != null) .filter(it -> it.getProperties().get("age").getInt() >= 35) .collect(Collectors.toList()); AccumuloDataSource source = new AccumuloDataSource(store, config); List<Vertex> queryResult = source .applyVertexPredicate( Query.elements() .fromAll() .where(AccumuloFilters.<Vertex>labelIn("Person") .and(AccumuloFilters.propLargerThan("age", 35, true))) ) .getGraphCollection() .getVertices() .collect(); validateEPGMElementCollections(inputVertices, queryResult); }); }
/** * Find all person who's age is smaller than 35 * * @throws Throwable if error */ @Test public void findPersonByAgeSmallerThan35() throws Throwable { doTest(TEST03, (loader, store, config) -> { //vertex label and property query List<Vertex> inputVertices = loader.getVertices() .stream() .filter(it -> Objects.equals(it.getLabel(), "Person")) .filter(it -> it.getProperties() != null) .filter(it -> it.getProperties().get("age") != null) .filter(it -> it.getProperties().get("age").getInt() < 35) .collect(Collectors.toList()); AccumuloDataSource source = new AccumuloDataSource(store, config); List<Vertex> queryResult = source .applyVertexPredicate( Query.elements() .fromAll() .where(AccumuloFilters.<Vertex>labelIn("Person") .and(AccumuloFilters.<Vertex>propLargerThan("age", 35, true) .negate()))) .getGraphCollection() .getVertices() .collect(); validateEPGMElementCollections(inputVertices, queryResult); }); }
.map(it -> { assert it.getProperties() != null; String name = it.getProperties().get("name").getString(); return (AccumuloElementFilter<Vertex>) AccumuloFilters .<Vertex>propEquals("name", name);
@Test public void queryEdgeByProperty() throws Throwable { doTest(TEST01, (loader, store, config) -> { List<Edge> storeEdges = loader.getEdges().stream() .filter(it -> { assert it.getProperties() != null; return it.getProperties().get("since") != null && Objects.equals(it.getProperties() .get("since") .getInt(), 2013); }) .collect(Collectors.toList()); AccumuloDataSource source = new AccumuloDataSource( store, GradoopFlinkConfig.createConfig(getExecutionEnvironment())); List<Edge> query = source.applyEdgePredicate( Query.elements() .fromAll() .where(AccumuloFilters.propEquals("since", 2013))) .getGraphCollection() .getEdges() .collect(); GradoopTestUtils.validateEPGMElementCollections(storeEdges, query); }); }
.map(it -> { assert it.getProperties() != null; return it.getProperties().get("name").getString(); }) .collect(Collectors.toList());
/** * Query graph head by property only * * @throws Throwable if error */ @Test public void queryGraphByProperty() throws Throwable { doTest(TEST01, (loader, store, config) -> { List<GraphHead> storeGraphs = loader.getGraphHeads().stream() .filter(it -> { assert it.getProperties() != null; return it.getProperties().get("vertexCount") != null && it.getProperties() .get("vertexCount") .getInt() > 3; }) .collect(Collectors.toList()); AccumuloDataSource source = new AccumuloDataSource(store, config); List<GraphHead> query = source.applyGraphPredicate( Query.elements() .fromAll() .where(AccumuloFilters.propLargerThan("vertexCount", 3, false))) .getGraphCollection() .getGraphHeads() .collect(); GradoopTestUtils.validateEPGMElementCollections(storeGraphs, query); }); }
@Test public void testRemoveExistentProperty() { Properties properties = Properties.create(); properties.set(KEY_0, STRING_VAL_6); GradoopId gradoopId = GradoopId.get(); // create element mock with property Element elementMock = mock(Element.class, withSettings() .useConstructor(gradoopId, "someLabel", properties) .defaultAnswer(CALLS_REAL_METHODS)); assertEquals(properties.get(KEY_0), elementMock.removeProperty(KEY_0)); assertFalse(elementMock.hasProperty(KEY_0)); }