@Test public void writeReportWritesALineForEachInvalidVertex() throws Exception { GraphWrapper wrapper = newGraph().withVertex(v -> v.withTimId(VERTEX_ID_1) .withProperty("rev", 1) .withLabel("document")) .withVertex(v -> v.withTimId(VERTEX_ID_2) .withProperty("rev", 1) .withLabel("document")) .withVertex(v -> v.withTimId(VERTEX_ID_1) .withProperty("rev", 2) .withLabel("document")) .withVertex(v -> v.withTimId(VERTEX_ID_2) .withProperty("rev", 2) .withLabel("document")) .withVertex(v -> v.withLabel("history") .withOutgoingRelation("NEXT_ITEM", "v1")) .withVertex("v1", v -> v.withProperty("TIM_tim_id", VERTEX_ID_1) .withProperty("rev", 1) .withLabel("createVertexEntry") .withOutgoingRelation("NEXT_ITEM", "v2") ) .withVertex("v2", v -> v.withProperty("TIM_tim_id", VERTEX_ID_1) .withProperty("rev", 2) .withLabel("updateVertexEntry")) .wrap(); GraphLogValidator graphLogValidator = new GraphLogValidator(wrapper); Writer writer = mock(Writer.class); graphLogValidator.writeReport(writer); ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class); verify(writer, times(2)).write(stringArgumentCaptor.capture()); assertThat(stringArgumentCaptor.getAllValues(), containsInAnyOrder( stringContainsInOrder(Lists.newArrayList("Vertex", VERTEX_ID_2, "2")), stringContainsInOrder(Lists.newArrayList("Vertex", VERTEX_ID_2, "1")) )); verifyNoMoreInteractions(writer); }
@SuppressWarnings("unchecked") public void writeReport(Writer writer) { LOG.info("Start Vertex validation"); Graph graph = graphWrapper.getGraph(); Set<ValidationElement> vertexIdsAndVersions = graph.traversal().V() .not(has(T.label, LabelP.of("searchresult"))) .not(has(T.label, LabelP.of("createEdgeEntry"))) .not(has(T.label, LabelP.of("updateEdgeEntry"))) .not(has(T.label, LabelP.of("createVertexEntry"))) .not(has(T.label, LabelP.of("updateVertexEntry"))) .has("tim_id") .has("rev") .map(v -> new ValidationElement( "Vertex", v.get().id(), v.get().value("tim_id"), v.get().value("rev"))) .toSet(); Set<ValidationElement> vertexLogEntryIdsAndVersions = graph.traversal().V() .or(has(T.label, LabelP.of("createVertexEntry")), has(T.label, LabelP.of("updateVertexEntry")) ) .map(v -> new ValidationElement( "Vertex", v.get().id(), v.get().value("TIM_tim_id"), v.get().value("rev"))) .toSet(); Set<ValidationElement> missingVertexLogEntries = Sets.difference(vertexIdsAndVersions, vertexLogEntryIdsAndVersions); missingVertexLogEntries.forEach(el -> el.writeLogString(writer)); LOG.info("Start Edge validation"); Set<ValidationElement> edgeIdsAndVersions = graph.traversal().E() .not(__.hasLabel("VERSION_OF", "NEXT_ITEM")) .has("tim_id") .has("rev") .map(e -> new ValidationElement( "Edge", e.get().id(), e.get().value("tim_id"), e.get().value("rev"))) .toSet(); Set<ValidationElement> edgeLogEntryIdsAndVersions = graph.traversal().V() .or(has(T.label, LabelP.of("createEdgeEntry")), has(T.label, LabelP.of("updateEdgeEntry")) ) .map(e -> new ValidationElement( "Edge", e.get().id(), e.get().value("TIM_tim_id"), e.get().value("rev"))) .toSet(); Set<ValidationElement> missingLogEntries = Sets.difference(edgeIdsAndVersions, edgeLogEntryIdsAndVersions); missingLogEntries.forEach(el -> el.writeLogString(writer)); }
GraphLogValidator { @SuppressWarnings("unchecked") public void writeReport(Writer writer) { LOG.info("Start Vertex validation"); Graph graph = graphWrapper.getGraph(); Set<ValidationElement> vertexIdsAndVersions = graph.traversal().V() .not(has(T.label, LabelP.of("searchresult"))) .not(has(T.label, LabelP.of("createEdgeEntry"))) .not(has(T.label, LabelP.of("updateEdgeEntry"))) .not(has(T.label, LabelP.of("createVertexEntry"))) .not(has(T.label, LabelP.of("updateVertexEntry"))) .has("tim_id") .has("rev") .map(v -> new ValidationElement( "Vertex", v.get().id(), v.get().value("tim_id"), v.get().value("rev"))) .toSet(); Set<ValidationElement> vertexLogEntryIdsAndVersions = graph.traversal().V() .or(has(T.label, LabelP.of("createVertexEntry")), has(T.label, LabelP.of("updateVertexEntry")) ) .map(v -> new ValidationElement( "Vertex", v.get().id(), v.get().value("TIM_tim_id"), v.get().value("rev"))) .toSet(); Set<ValidationElement> missingVertexLogEntries = Sets.difference(vertexIdsAndVersions, vertexLogEntryIdsAndVersions); missingVertexLogEntries.forEach(el -> el.writeLogString(writer)); LOG.info("Start Edge validation"); Set<ValidationElement> edgeIdsAndVersions = graph.traversal().E() .not(__.hasLabel("VERSION_OF", "NEXT_ITEM")) .has("tim_id") .has("rev") .map(e -> new ValidationElement( "Edge", e.get().id(), e.get().value("tim_id"), e.get().value("rev"))) .toSet(); Set<ValidationElement> edgeLogEntryIdsAndVersions = graph.traversal().V() .or(has(T.label, LabelP.of("createEdgeEntry")), has(T.label, LabelP.of("updateEdgeEntry")) ) .map(e -> new ValidationElement( "Edge", e.get().id(), e.get().value("TIM_tim_id"), e.get().value("rev"))) .toSet(); Set<ValidationElement> missingLogEntries = Sets.difference(edgeIdsAndVersions, edgeLogEntryIdsAndVersions); missingLogEntries.forEach(el -> el.writeLogString(writer)); } }
GraphLogValidator { @SuppressWarnings("unchecked") public void writeReport(Writer writer) { LOG.info("Start Vertex validation"); Graph graph = graphWrapper.getGraph(); Set<ValidationElement> vertexIdsAndVersions = graph.traversal().V() .not(has(T.label, LabelP.of("searchresult"))) .not(has(T.label, LabelP.of("createEdgeEntry"))) .not(has(T.label, LabelP.of("updateEdgeEntry"))) .not(has(T.label, LabelP.of("createVertexEntry"))) .not(has(T.label, LabelP.of("updateVertexEntry"))) .has("tim_id") .has("rev") .map(v -> new ValidationElement( "Vertex", v.get().id(), v.get().value("tim_id"), v.get().value("rev"))) .toSet(); Set<ValidationElement> vertexLogEntryIdsAndVersions = graph.traversal().V() .or(has(T.label, LabelP.of("createVertexEntry")), has(T.label, LabelP.of("updateVertexEntry")) ) .map(v -> new ValidationElement( "Vertex", v.get().id(), v.get().value("TIM_tim_id"), v.get().value("rev"))) .toSet(); Set<ValidationElement> missingVertexLogEntries = Sets.difference(vertexIdsAndVersions, vertexLogEntryIdsAndVersions); missingVertexLogEntries.forEach(el -> el.writeLogString(writer)); LOG.info("Start Edge validation"); Set<ValidationElement> edgeIdsAndVersions = graph.traversal().E() .not(__.hasLabel("VERSION_OF", "NEXT_ITEM")) .has("tim_id") .has("rev") .map(e -> new ValidationElement( "Edge", e.get().id(), e.get().value("tim_id"), e.get().value("rev"))) .toSet(); Set<ValidationElement> edgeLogEntryIdsAndVersions = graph.traversal().V() .or(has(T.label, LabelP.of("createEdgeEntry")), has(T.label, LabelP.of("updateEdgeEntry")) ) .map(e -> new ValidationElement( "Edge", e.get().id(), e.get().value("TIM_tim_id"), e.get().value("rev"))) .toSet(); Set<ValidationElement> missingLogEntries = Sets.difference(edgeIdsAndVersions, edgeLogEntryIdsAndVersions); missingLogEntries.forEach(el -> el.writeLogString(writer)); } GraphLogValidator(GraphWrapper graphWrapper); }
GraphLogValidator { @SuppressWarnings("unchecked") public void writeReport(Writer writer) { LOG.info("Start Vertex validation"); Graph graph = graphWrapper.getGraph(); Set<ValidationElement> vertexIdsAndVersions = graph.traversal().V() .not(has(T.label, LabelP.of("searchresult"))) .not(has(T.label, LabelP.of("createEdgeEntry"))) .not(has(T.label, LabelP.of("updateEdgeEntry"))) .not(has(T.label, LabelP.of("createVertexEntry"))) .not(has(T.label, LabelP.of("updateVertexEntry"))) .has("tim_id") .has("rev") .map(v -> new ValidationElement( "Vertex", v.get().id(), v.get().value("tim_id"), v.get().value("rev"))) .toSet(); Set<ValidationElement> vertexLogEntryIdsAndVersions = graph.traversal().V() .or(has(T.label, LabelP.of("createVertexEntry")), has(T.label, LabelP.of("updateVertexEntry")) ) .map(v -> new ValidationElement( "Vertex", v.get().id(), v.get().value("TIM_tim_id"), v.get().value("rev"))) .toSet(); Set<ValidationElement> missingVertexLogEntries = Sets.difference(vertexIdsAndVersions, vertexLogEntryIdsAndVersions); missingVertexLogEntries.forEach(el -> el.writeLogString(writer)); LOG.info("Start Edge validation"); Set<ValidationElement> edgeIdsAndVersions = graph.traversal().E() .not(__.hasLabel("VERSION_OF", "NEXT_ITEM")) .has("tim_id") .has("rev") .map(e -> new ValidationElement( "Edge", e.get().id(), e.get().value("tim_id"), e.get().value("rev"))) .toSet(); Set<ValidationElement> edgeLogEntryIdsAndVersions = graph.traversal().V() .or(has(T.label, LabelP.of("createEdgeEntry")), has(T.label, LabelP.of("updateEdgeEntry")) ) .map(e -> new ValidationElement( "Edge", e.get().id(), e.get().value("TIM_tim_id"), e.get().value("rev"))) .toSet(); Set<ValidationElement> missingLogEntries = Sets.difference(edgeIdsAndVersions, edgeLogEntryIdsAndVersions); missingLogEntries.forEach(el -> el.writeLogString(writer)); } GraphLogValidator(GraphWrapper graphWrapper); @SuppressWarnings("unchecked") void writeReport(Writer writer); }
GraphLogValidator { @SuppressWarnings("unchecked") public void writeReport(Writer writer) { LOG.info("Start Vertex validation"); Graph graph = graphWrapper.getGraph(); Set<ValidationElement> vertexIdsAndVersions = graph.traversal().V() .not(has(T.label, LabelP.of("searchresult"))) .not(has(T.label, LabelP.of("createEdgeEntry"))) .not(has(T.label, LabelP.of("updateEdgeEntry"))) .not(has(T.label, LabelP.of("createVertexEntry"))) .not(has(T.label, LabelP.of("updateVertexEntry"))) .has("tim_id") .has("rev") .map(v -> new ValidationElement( "Vertex", v.get().id(), v.get().value("tim_id"), v.get().value("rev"))) .toSet(); Set<ValidationElement> vertexLogEntryIdsAndVersions = graph.traversal().V() .or(has(T.label, LabelP.of("createVertexEntry")), has(T.label, LabelP.of("updateVertexEntry")) ) .map(v -> new ValidationElement( "Vertex", v.get().id(), v.get().value("TIM_tim_id"), v.get().value("rev"))) .toSet(); Set<ValidationElement> missingVertexLogEntries = Sets.difference(vertexIdsAndVersions, vertexLogEntryIdsAndVersions); missingVertexLogEntries.forEach(el -> el.writeLogString(writer)); LOG.info("Start Edge validation"); Set<ValidationElement> edgeIdsAndVersions = graph.traversal().E() .not(__.hasLabel("VERSION_OF", "NEXT_ITEM")) .has("tim_id") .has("rev") .map(e -> new ValidationElement( "Edge", e.get().id(), e.get().value("tim_id"), e.get().value("rev"))) .toSet(); Set<ValidationElement> edgeLogEntryIdsAndVersions = graph.traversal().V() .or(has(T.label, LabelP.of("createEdgeEntry")), has(T.label, LabelP.of("updateEdgeEntry")) ) .map(e -> new ValidationElement( "Edge", e.get().id(), e.get().value("TIM_tim_id"), e.get().value("rev"))) .toSet(); Set<ValidationElement> missingLogEntries = Sets.difference(edgeIdsAndVersions, edgeLogEntryIdsAndVersions); missingLogEntries.forEach(el -> el.writeLogString(writer)); } GraphLogValidator(GraphWrapper graphWrapper); @SuppressWarnings("unchecked") void writeReport(Writer writer); static final Logger LOG; }