Search in sources :

Example 11 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue in project timbuctoo by HuygensING.

the class EdgeListFacetDescriptionTest method filterAddsAFilterToFilterOutTheNonMatchingVertices.

@Test
public void filterAddsAFilterToFilterOutTheNonMatchingVertices() {
    List<FacetValue> facetValues = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList(RELATION_NAME)));
    SearchRequestV2_1 searchRequest = new SearchRequestV2_1();
    searchRequest.setFacetValues(facetValues);
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex("v1", v -> v.withTimId("1")).withVertex("v2", v -> v.withTimId("2").withOutgoingRelation(RELATION_NAME, "v1")).build().traversal().V();
    instance.filter(traversal, facetValues);
    assertThat(traversal.toList(), contains(VertexMatcher.likeVertex().withTimId("1")));
}
Also used : VertexMatcher(nl.knaw.huygens.timbuctoo.util.VertexMatcher) 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) SearchRequestV2_1(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1) 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) Matchers.equalTo(org.hamcrest.Matchers.equalTo) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Collections(java.util.Collections) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) 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) SearchRequestV2_1(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1) Test(org.junit.Test)

Example 12 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue in project timbuctoo by HuygensING.

the class ListFacetDescriptionTest method filterLetsTheParserParseEachDatabaseValue.

@Test
public void filterLetsTheParserParseEachDatabaseValue() {
    String value1 = "value1";
    List<FacetValue> facetValues = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList(value1)));
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withProperty(PROPERTY, "value1").withTimId("1")).withVertex(v -> v.withProperty(PROPERTY, "value2").withTimId("2")).build().traversal().V();
    instance.filter(traversal, facetValues);
    // needed to verify the parser
    traversal.toList();
    verify(propertyParser).parse("value1");
    verify(propertyParser).parse("value2");
}
Also used : VertexMatcher(nl.knaw.huygens.timbuctoo.util.VertexMatcher) 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) SearchRequestV2_1(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1) 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) 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) 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 13 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue in project timbuctoo by HuygensING.

the class ListFacetDescriptionTest method filterAddsAFilterToFilterOutTheNonMatchingVertices.

@Test
public void filterAddsAFilterToFilterOutTheNonMatchingVertices() {
    String value1 = "value1";
    List<FacetValue> facetValues = Lists.newArrayList(new ListFacetValue(FACET_NAME, Lists.newArrayList(value1)));
    SearchRequestV2_1 searchRequest = new SearchRequestV2_1();
    searchRequest.setFacetValues(facetValues);
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withProperty(PROPERTY, value1).withTimId("1")).withVertex(v -> v.withProperty(PROPERTY, "value2").withTimId("2")).build().traversal().V();
    instance.filter(traversal, facetValues);
    assertThat(traversal.toList(), contains(VertexMatcher.likeVertex().withTimId("1")));
}
Also used : VertexMatcher(nl.knaw.huygens.timbuctoo.util.VertexMatcher) 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) SearchRequestV2_1(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1) 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) 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) 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) SearchRequestV2_1(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 14 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue in project timbuctoo by HuygensING.

the class MultiValueListFacetDescriptionTest method filterAddsAFilterThatChecksIfTheVerticesContainOnOfTheValues.

@Test
public void filterAddsAFilterThatChecksIfTheVerticesContainOnOfTheValues() {
    String value3 = "value3";
    String value4 = "value4";
    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", value4))).build().traversal().V();
    List<String> values = Lists.newArrayList(value3, value4);
    List<FacetValue> facetValues = Lists.newArrayList(new ListFacetValue(FACET_NAME, values));
    instance.filter(traversal, facetValues);
    assertThat(traversal.toList(), containsInAnyOrder(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 15 with ListFacetValue

use of nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue 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)

Aggregations

List (java.util.List)18 ListFacetValue (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.ListFacetValue)18 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)18 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)18 FacetValue (nl.knaw.huygens.timbuctoo.search.FacetValue)17 Lists (com.google.common.collect.Lists)16 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)14 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)14 Test (org.junit.Test)14 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)13 Matchers.contains (org.hamcrest.Matchers.contains)11 Before (org.junit.Before)11 PropertyParser (nl.knaw.huygens.timbuctoo.search.description.PropertyParser)9 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 BDDMockito.given (org.mockito.BDDMockito.given)6 Mockito.mock (org.mockito.Mockito.mock)6 Mockito.verify (org.mockito.Mockito.verify)6 ArrayList (java.util.ArrayList)5 SearchRequestV2_1 (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SearchRequestV2_1)5