SwarmScanner { protected void removeDockerLabels(String neo4jLabel, String idName, String idVal, JsonNode intended, JsonNode actual) { List<String> x = Lists.newArrayList(); actual.fieldNames().forEachRemaining(it -> { if (it != null && it.startsWith("label_")) { if (!intended.has(it)) { if (!it.contains(" ")) { x.add("a.`" + it + "`"); } } } }); if (!x.isEmpty()) { String cypher = "match (a:" + neo4jLabel + " {" + idName + ":{id}}) remove " + Joiner.on(", ").join(x) + " return a"; dockerScanner.getNeoRxClient().execCypher(cypher, "id", idVal); } } SwarmScanner(DockerScanner ds); DockerRestClient getRestClient(); static WebTarget extractWebTarget(DockerClient c); void scan(); void scanServicesForSwarm(String swarmClusterId); void scanNode(String nodeId); void scanTask(String taskId); void deleteTask(String id); void deleteNode(String id); void scanTasksForSwarm(String swarmClusterId); Optional<String> getSwarmClusterId(); void scanService(String id); void deleteService(String id);  }
@Test public void testLabels() { Projector p = getProjector(); SwarmScanner ss = new SwarmScanner(p.createBuilder(DockerScannerBuilder.class).build()); String id = "junit-"+System.currentTimeMillis(); JsonNode actual = p.getNeoRxClient().execCypher("merge (x:DockerService {serviceId:{id}}) set x.label_c='c', x.label_foo='foo', x.junitData=true return x","id",id).blockingFirst(); JsonNode intended = mapper.createObjectNode().put("label_a", "1").put("label_b", "2").put("chinacat","sunflower"); p.getNeoRxClient().execCypher("merge (a:DockerService {serviceId:{id}}) set a+={props} return a","id",id,"props",intended); ss.removeDockerLabels("DockerService","serviceId",id,intended, actual); JsonNode result = p.getNeoRxClient().execCypher("match (x:DockerService {serviceId:{id}}) return x","id",id).blockingFirst(); Assertions.assertThat(result.path("serviceId").asText()).isEqualTo(id); Assertions.assertThat(result.has("label_c")).isFalse(); Assertions.assertThat(result.has("label_foo")).isFalse(); Assertions.assertThat(result.get("label_a").asText()).isEqualTo("1"); }