Search in sources :

Example 1 with SortParameter

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

the class SortDescriptionTest method sortAddsASortParametersThatSortsTheVertices.

@Test
@SuppressWarnings("unchecked")
public void sortAddsASortParametersThatSortsTheVertices() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY_1, "value1.2")).withVertex(v -> v.withTimId("id2").withProperty(PROPERTY_1, "value1.1")).withVertex(v -> v.withTimId("id3").withProperty(PROPERTY_1, "value1")).build().traversal().V();
    List<SortParameter> sortParameters = Lists.newArrayList(new SortParameter(SORT_FIELD_1, asc));
    instance.sort(traversal, sortParameters);
    List<Vertex> actual = traversal.toList();
    assertThat(actual, contains(likeVertex().withTimId("id3"), likeVertex().withTimId("id2"), likeVertex().withTimId("id1")));
}
Also used : Test(org.junit.Test) BuildableSortFieldDescription.newSortFieldDescription(nl.knaw.huygens.timbuctoo.search.description.sort.BuildableSortFieldDescription.newSortFieldDescription) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Direction.asc(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SortParameter.Direction.asc) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) List(java.util.List) Property.localProperty(nl.knaw.huygens.timbuctoo.search.description.Property.localProperty) Lists(com.google.common.collect.Lists) Matchers.contains(org.hamcrest.Matchers.contains) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) SortParameter(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SortParameter) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) SortParameter(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SortParameter) Test(org.junit.Test)

Example 2 with SortParameter

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

the class SortDescriptionTest method sortAddsASortParameterToTheSearchResultsForEachOfTheSortParameters.

@Test
@SuppressWarnings("unchecked")
public void sortAddsASortParameterToTheSearchResultsForEachOfTheSortParameters() {
    GraphTraversal<Vertex, Vertex> traversal = newGraph().withVertex(v -> v.withTimId("id1").withProperty(PROPERTY_1, "value1.2").withProperty(PROPERTY_2, "value2")).withVertex(v -> v.withTimId("id2").withProperty(PROPERTY_1, "value1").withProperty(PROPERTY_2, "value2.1")).withVertex(v -> v.withTimId("id3").withProperty(PROPERTY_1, "value1").withProperty(PROPERTY_2, "value2")).build().traversal().V();
    List<SortParameter> sortParameters = Lists.newArrayList(new SortParameter(SORT_FIELD_1, asc), new SortParameter(SORT_FIELD_2, asc));
    instance.sort(traversal, sortParameters);
    List<Vertex> actual = traversal.toList();
    assertThat(actual, contains(likeVertex().withTimId("id3"), likeVertex().withTimId("id2"), likeVertex().withTimId("id1")));
}
Also used : Test(org.junit.Test) BuildableSortFieldDescription.newSortFieldDescription(nl.knaw.huygens.timbuctoo.search.description.sort.BuildableSortFieldDescription.newSortFieldDescription) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Direction.asc(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SortParameter.Direction.asc) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) List(java.util.List) Property.localProperty(nl.knaw.huygens.timbuctoo.search.description.Property.localProperty) Lists(com.google.common.collect.Lists) Matchers.contains(org.hamcrest.Matchers.contains) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) SortParameter(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SortParameter) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) SortParameter(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SortParameter) Test(org.junit.Test)

Example 3 with SortParameter

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

the class SortDescriptionTest method sortIgnoresUnknownSortParameters.

@Test
@SuppressWarnings("unchecked")
public void sortIgnoresUnknownSortParameters() {
    GraphTraversal<Vertex, Vertex> traversal = mock(GraphTraversal.class);
    List<SortParameter> sortParameters = Lists.newArrayList(new SortParameter("unknownField", asc));
    instance.sort(traversal, sortParameters);
    verifyZeroInteractions(traversal);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) SortParameter(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SortParameter) Test(org.junit.Test)

Aggregations

SortParameter (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SortParameter)3 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 Test (org.junit.Test)3 Lists (com.google.common.collect.Lists)2 List (java.util.List)2 Property.localProperty (nl.knaw.huygens.timbuctoo.search.description.Property.localProperty)2 BuildableSortFieldDescription.newSortFieldDescription (nl.knaw.huygens.timbuctoo.search.description.sort.BuildableSortFieldDescription.newSortFieldDescription)2 Direction.asc (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.SortParameter.Direction.asc)2 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)2 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.contains (org.hamcrest.Matchers.contains)2 Before (org.junit.Before)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verifyZeroInteractions (org.mockito.Mockito.verifyZeroInteractions)2