use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.
the class GraphLogValidatorTest method writeReportWritesALineForEachInvalidEdge.
@Test
public void writeReportWritesALineForEachInvalidEdge() throws Exception {
GraphWrapper wrapper = newGraph().withVertex("v1", v -> v.withTimId(VERTEX_ID_1).withProperty("rev", 1).withLabel("document")).withVertex("v2", v -> v.withTimId(VERTEX_ID_2).withProperty("rev", 1).withLabel("document").withOutgoingRelation("relatedTo", "v1", r -> r.withTim_id(REL_1_ID).withRev(1)).withOutgoingRelation("relatedTo", "v1", r -> r.withTim_id(REL_1_ID).withRev(2)).withOutgoingRelation("otherRelation", "v1", r -> r.withTim_id(REL_2_ID).withRev(1)).withOutgoingRelation("otherRelation", "v1", r -> r.withTim_id(REL_2_ID).withRev(2))).withVertex("v3", v -> v.withLabel("createVertexEntry").withProperty("TIM_tim_id", VERTEX_ID_1).withProperty("rev", 1).withOutgoingRelation("NEXT_ITEM", "v4")).withVertex("v4", v -> v.withLabel("updateVertexEntry").withProperty("TIM_tim_id", VERTEX_ID_2).withProperty("rev", 1).withOutgoingRelation("NEXT_ITEM", "v5")).withVertex("v5", v -> v.withLabel("createEdgeEntry").withProperty("TIM_tim_id", REL_2_ID.toString()).withProperty("rev", 1).withOutgoingRelation("NEXT_ITEM", "v6")).withVertex("v6", v -> v.withLabel("updateEdgeEntry").withProperty("TIM_tim_id", REL_2_ID.toString()).withProperty("rev", 2)).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("Edge", REL_1_ID.toString(), "1")), stringContainsInOrder(Lists.newArrayList("Edge", REL_1_ID.toString(), "2"))));
verifyNoMoreInteractions(writer);
}
use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.
the class D3GraphGeneratorServiceTest method getShouldGenerateAD3Graph.
@Test
public void getShouldGenerateAD3Graph() throws NotFoundException, IOException {
Graph graph = newGraph().withVertex("relationCollection", v -> v.withProperty(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, "wwrelation").withProperty(Collection.IS_RELATION_COLLECTION_PROPERTY_NAME, true)).withVertex("vreNode", v -> v.withProperty(Vre.VRE_NAME_PROPERTY_NAME, "WomenWriters").withOutgoingRelation(Vre.HAS_COLLECTION_RELATION_NAME, "relationCollection")).withVertex(v -> v.withLabel(Collection.DATABASE_LABEL).withProperty(Collection.ENTITY_TYPE_NAME_PROPERTY_NAME, "wwperson").withIncomingRelation(Vre.HAS_COLLECTION_RELATION_NAME, "vreNode")).withVertex("v1", v -> v.withProperty("isLatest", true).withTimId(THE_UUID).withProperty("types", TYPES).withProperty("wwperson_tempName", "name1")).withVertex("v2", v -> v.withTimId("2").withProperty("types", TYPES).withOutgoingRelation(RELATION_NAME, "v1", r -> r.withAccepted("wwrelation", true).withIsLatest(true)).withProperty("wwperson_tempName", "name2")).withVertex("v3", v -> v.withTimId("3").withProperty("types", TYPES).withOutgoingRelation(RELATION_NAME_2, "v1", r -> r.withAccepted("wwrelation", true).withIsLatest(true)).withProperty("wwperson_tempName", "name3")).withVertex("v4", v -> v.withTimId("4").withProperty("types", TYPES).withOutgoingRelation(RELATION_NAME, "v2", r -> r.withAccepted("wwrelation", true).withIsLatest(true)).withProperty("wwperson_tempName", "name4")).withVertex("v5", v -> v.withTimId("5").withProperty("types", TYPES).withOutgoingRelation(UNREQUESTED_RELATION, "v1", r -> r.withAccepted("wwrelation_accepted", true).withIsLatest(true)).withProperty("wwperson_tempName", "name5")).withVertex("v6", v -> v.withTimId("6").withProperty("types", TYPES).withOutgoingRelation(RELATION_NAME, "v4", r -> r.withAccepted("wwrelation", true).withIsLatest(true)).withProperty("wwperson_tempName", "name6")).build();
List<Vertex> vertices = graph.traversal().V().has("wwperson_tempName").asAdmin().clone().toList();
Collections.sort(vertices, Comparator.comparing(vertexA -> ((String) vertexA.property("wwperson_tempName").value())));
GraphWrapper graphWrapper = createGraphWrapper(graph);
D3GraphGeneratorService underTest = new D3GraphGeneratorService(graphWrapper, HuygensIng.mappings);
D3Graph result = underTest.get("wwperson", UUID.fromString(THE_UUID), Lists.newArrayList(RELATION_NAME, RELATION_NAME_2), 2);
assertThat(result.getNodes().get(0), is(new Node(vertices.get(0), "wwperson")));
assertThat(result.getNodes(), containsInAnyOrder(new Node(vertices.get(0), "wwperson"), new Node(vertices.get(1), "wwperson"), new Node(vertices.get(2), "wwperson"), new Node(vertices.get(3), "wwperson")));
int indexOfRoot = getIndex(result.getNodes(), "077bf0b5-6b7d-45aa-89ff-6ecf2cfc549c");
int indexOfPerson1 = getIndex(result.getNodes(), "2");
int indexOfPerson2 = getIndex(result.getNodes(), "3");
int indexOfPerson3 = getIndex(result.getNodes(), "4");
assertThat(result.getLinks(), containsInAnyOrder(new Link(mockEdge(RELATION_NAME), indexOfRoot, indexOfPerson1), new Link(mockEdge(RELATION_NAME_2), indexOfRoot, indexOfPerson2), new Link(mockEdge(RELATION_NAME), indexOfPerson1, indexOfPerson3)));
}
use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.
the class CollectionTest method addPropertyAddsHasNextEdgeBetweenTheProperties.
@Test
public void addPropertyAddsHasNextEdgeBetweenTheProperties() {
GraphWrapper graphWrapper = newGraph().withVertex(v -> v.withLabel(DATABASE_LABEL).withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, ENTITY_NAME).withProperty(COLLECTION_NAME_PROPERTY_NAME, COLLECTION_NAME)).wrap();
Vertex collectionVertex = graphWrapper.getGraph().traversal().V().next();
Collection instance = new Collection(VRE_NAME, collectionVertex, graphWrapper);
instance.addProperty(mock(Vertex.class), "prop1", "val1", type);
instance.addProperty(mock(Vertex.class), "prop2", "val2", type);
instance.addProperty(mock(Vertex.class), "prop3", "val3", type);
assertThat(graphWrapper.getGraph().traversal().V(collectionVertex.id()).out(HAS_INITIAL_PROPERTY_RELATION_NAME).out(HAS_NEXT_PROPERTY_RELATION_NAME).out(HAS_NEXT_PROPERTY_RELATION_NAME).count().next(), is(1L));
}
use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.
the class CollectionTest method addPropertyDoesNotAddAPropConfigWhenTheCollectionIsAnArchetype.
@Test
public void addPropertyDoesNotAddAPropConfigWhenTheCollectionIsAnArchetype() {
GraphWrapper graphWrapper = newGraph().withVertex(v -> v.withLabel(DATABASE_LABEL).withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "concept").withProperty(COLLECTION_NAME_PROPERTY_NAME, "concepts")).wrap();
Vertex collectionVertex = graphWrapper.getGraph().traversal().V().next();
CollectionDescription collectionDescription = CollectionDescription.createForAdmin("concept");
Collection instance = new Collection("Admin", collectionVertex, graphWrapper, collectionDescription);
Vertex entityVertex = mock(Vertex.class);
instance.addProperty(entityVertex, "prop1", "val1", type);
assertThat(graphWrapper.getGraph().traversal().V(collectionVertex.id()).out(HAS_PROPERTY_RELATION_NAME).count().next(), is(0L));
}
use of nl.knaw.huygens.timbuctoo.server.GraphWrapper in project timbuctoo by HuygensING.
the class CollectionTest method setArchetypeSetsTheUriOfTheOriginalArchetypeToEdgeToTheArchetype.
@Test
public void setArchetypeSetsTheUriOfTheOriginalArchetypeToEdgeToTheArchetype() {
String newArchetypeEntity = "newArchetype";
GraphWrapper graphWrapper = newGraph().withVertex(v -> v.withLabel(DATABASE_LABEL).withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, ENTITY_NAME).withProperty(COLLECTION_NAME_PROPERTY_NAME, COLLECTION_NAME)).withVertex(v -> v.withLabel(DATABASE_LABEL).withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, newArchetypeEntity)).wrap();
Vertex collectionVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of(DATABASE_LABEL)).has(ENTITY_TYPE_NAME_PROPERTY_NAME, ENTITY_NAME).next();
Collection instance = new Collection(VRE_NAME, collectionVertex, graphWrapper);
Vertex archetypeVertex = graphWrapper.getGraph().traversal().V().has(T.label, LabelP.of(DATABASE_LABEL)).has(ENTITY_TYPE_NAME_PROPERTY_NAME, newArchetypeEntity).next();
Collection archetype = new Collection("", archetypeVertex, graphWrapper);
String originalArchetypeUri = "http://example.com/originalArchetype";
instance.setArchetype(archetype, originalArchetypeUri);
assertThat(graphWrapper.getGraph().traversal().V(collectionVertex.id()).outE(HAS_ARCHETYPE_RELATION_NAME).toList(), hasItem(likeEdge().withProperty(RDF_URI_PROP, originalArchetypeUri)));
}
Aggregations