Search in sources :

Example 76 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.

the class MultiValueListFacetDescriptionTest method filterDoesNotAddAFilterWhenTheFacetValueContainsNoValues.

@Test
public void filterDoesNotAddAFilterWhenTheFacetValueContainsNoValues() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY_NAME, serializedListOf("value1", "value2"))).withVertex(v -> v.withTimId("id2").withProperty(PROPERTY_NAME, serializedListOf("value2", "value3"))).withVertex(v -> v.withTimId("id3").withProperty(PROPERTY_NAME, serializedListOf("value1", "value3", "value4"))).build().traversal().V();
    List<FacetValue> facetValues = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList()));
    instance.filter(traversal, facetValues);
    assertThat(traversal.toList(), containsInAnyOrder(likeVertex().withTimId("id1"), likeVertex().withTimId("id2"), likeVertex().withTimId("id3")));
}
Also used : Arrays(java.util.Arrays) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Lists(com.google.common.collect.Lists) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) Test(org.junit.Test)

Example 77 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.

the class MultiValueListFacetDescriptionTest method filterFiltersAllTheVerticesThatDoNotContainTheFacetValue.

@Test
public void filterFiltersAllTheVerticesThatDoNotContainTheFacetValue() {
    String value1 = "value1";
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY_NAME, serializedListOf(value1, "value2"))).withVertex(v -> v.withTimId("id2").withProperty(PROPERTY_NAME, serializedListOf("value2", "value3"))).withVertex(v -> v.withTimId("id3").withProperty(PROPERTY_NAME, serializedListOf(value1, "value3", "value4"))).build().traversal().V();
    List<FacetValue> facetValues = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList(value1)));
    instance.filter(traversal, facetValues);
    List<Vertex> actual = traversal.toList();
    assertThat(actual, containsInAnyOrder(likeVertex().withTimId("id1"), likeVertex().withTimId("id3")));
}
Also used : Arrays(java.util.Arrays) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Lists(com.google.common.collect.Lists) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) Test(org.junit.Test)

Example 78 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.

the class RelatedDatableRangeFacetDescriptionTest method filterAddsAFilterIgnoresLastFourNumbers.

@Test
public void filterAddsAFilterIgnoresLastFourNumbers() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex("target1", v -> v.withTimId("id4").withProperty(PROPERTY_NAME, asSerializedDatable("2015-01"))).withVertex("target2", v -> v.withTimId("id5").withProperty(PROPERTY_NAME, asSerializedDatable("0015-01"))).withVertex("target3", v -> v.withTimId("id6").withProperty(PROPERTY_NAME, asSerializedDatable("0190-01"))).withVertex("source1", v -> v.withTimId("id1").withOutgoingRelation(RELATION, "target1")).withVertex("source2", v -> v.withTimId("id2").withOutgoingRelation(RELATION, "target2")).withVertex("source3", v -> v.withTimId("id3").withOutgoingRelation(RELATION, "target3")).build().traversal().V();
    List<FacetValue> facets = Lists.newArrayList(new DateRangeFacetValue(FACET_NAME, 20151001L, 20160101L));
    instance.filter(traversal, facets);
    assertThat(traversal.toList(), contains(likeVertex().withTimId("id1")));
}
Also used : Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Lists(com.google.common.collect.Lists) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) Test(org.junit.Test)

Example 79 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.

the class RelatedDatableRangeFacetDescriptionTest method filterIncludesTheVerticesWhereOnlyTheEndFallsInTheRange.

@Test
public void filterIncludesTheVerticesWhereOnlyTheEndFallsInTheRange() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex("target1", v -> v.withTimId("id4").withProperty(PROPERTY_NAME, asSerializedDatable("2015/2020"))).withVertex("target2", v -> v.withTimId("id5").withProperty(PROPERTY_NAME, asSerializedDatable("0015-01"))).withVertex("target3", v -> v.withTimId("id6").withProperty(PROPERTY_NAME, asSerializedDatable("0190-01"))).withVertex("source1", v -> v.withTimId("id1").withOutgoingRelation(RELATION, "target1")).withVertex("source2", v -> v.withTimId("id2").withOutgoingRelation(RELATION, "target2")).withVertex("source3", v -> v.withTimId("id3").withOutgoingRelation(RELATION, "target3")).build().traversal().V();
    List<FacetValue> facetValues = Lists.newArrayList(new DateRangeFacetValue(FACET_NAME, 20140101L, 20160224L));
    instance.filter(traversal, facetValues);
    assertThat(traversal.toList(), contains(likeVertex().withTimId("id1")));
}
Also used : Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Lists(com.google.common.collect.Lists) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) Test(org.junit.Test)

Example 80 with GraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal in project timbuctoo by HuygensING.

the class RelatedListFacetDescriptionTest method filterLetsTheParserParseEachDatabaseValue.

@Test
public void filterLetsTheParserParseEachDatabaseValue() {
    RelatedListFacetDescription instance = new RelatedListFacetDescription(FACET_NAME, PROPERTY, parser, RELATION);
    List<FacetValue> facets = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList(VALUE1)));
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex("v1", v -> v.withTimId("id1").withProperty(PROPERTY, VALUE1)).withVertex("v2", v -> v.withTimId("id2").withProperty(PROPERTY, VALUE2)).withVertex("v3", v -> v.withTimId("id3").withOutgoingRelation(RELATION, "v1")).withVertex("v4", v -> v.withTimId("id4").withOutgoingRelation(RELATION, "v2")).build().traversal().V();
    instance.filter(traversal, facets);
    // needed to verify the parser
    traversal.toList();
    verify(parser).parse(VALUE1);
    verify(parser).parse(VALUE2);
}
Also used : Test(org.junit.Test) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) PropertyParser(nl.knaw.huygens.timbuctoo.search.description.PropertyParser) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) Lists(com.google.common.collect.Lists) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) BDDMockito.given(org.mockito.BDDMockito.given) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) ListFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue) Test(org.junit.Test)

Aggregations

GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)93 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)67 Test (org.junit.Test)57 List (java.util.List)51 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)50 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)44 Before (org.junit.Before)42 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)40 Matchers.contains (org.hamcrest.Matchers.contains)39 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)35 Lists (com.google.common.collect.Lists)34 FacetValue (nl.knaw.huygens.timbuctoo.search.FacetValue)31 Optional (java.util.Optional)24 P (org.apache.tinkerpop.gremlin.process.traversal.P)21 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)20 ListFacetValue (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue)19 Matchers.is (org.hamcrest.Matchers.is)17 Mockito.mock (org.mockito.Mockito.mock)17 Matchers.empty (org.hamcrest.Matchers.empty)15 Edge (org.apache.tinkerpop.gremlin.structure.Edge)14