Search in sources :

Example 6 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class SortInfoTest method shouldParseSimpleDescendingRSQL.

@Test
public void shouldParseSimpleDescendingRSQL() throws Exception {
    // given
    String sorting = "sort=desc=id";
    // when
    SortInfo testedSorting = defaultSortInfoProducer.getSortInfo(sorting);
    // then
    assertThat(testedSorting.getFields()).containsExactly("id");
    assertThat(testedSorting.getDirection()).isEqualTo(SortInfo.SortingDirection.DESC);
}
Also used : SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Test(org.junit.Test)

Example 7 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class SortInfoTest method shouldParseComplicatedAscendingRSQL.

@Test
public void shouldParseComplicatedAscendingRSQL() throws Exception {
    // given
    String sorting = "sort=asc=(id,name)";
    // when
    SortInfo testedSorting = defaultSortInfoProducer.getSortInfo(sorting);
    // then
    assertThat(testedSorting.getFields()).containsExactly("id", "name");
    assertThat(testedSorting.getDirection()).isEqualTo(SortInfo.SortingDirection.ASC);
}
Also used : SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Test(org.junit.Test)

Example 8 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class SortInfoTest method shouldCreateProperComparatorAndSortDescending.

@Test
public void shouldCreateProperComparatorAndSortDescending() throws Exception {
    // given
    String sorting = "=desc=(field1)";
    List<SortTester> tester = new ArrayList<>();
    tester.add(new SortTester("a", "b"));
    tester.add(new SortTester("b", "a"));
    // when
    SortInfo testedSorting = defaultSortInfoProducer.getSortInfo(sorting);
    List<String> sorted = tester.stream().sorted(testedSorting.getComparator()).map(SortTester::getField1).collect(Collectors.toList());
    // then
    assertThat(sorted).containsExactly("b", "a");
}
Also used : ArrayList(java.util.ArrayList) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Test(org.junit.Test)

Example 9 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class SortInfoTest method shouldParseComplicatedDescendingRSQL.

@Test
public void shouldParseComplicatedDescendingRSQL() throws Exception {
    // given
    String sorting = "sort=desc=(id,name)";
    // when
    SortInfo testedSorting = defaultSortInfoProducer.getSortInfo(sorting);
    // then
    assertThat(testedSorting.getFields()).containsExactly("id", "name");
    assertThat(testedSorting.getDirection()).isEqualTo(SortInfo.SortingDirection.DESC);
}
Also used : SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Test(org.junit.Test)

Example 10 with SortInfo

use of org.jboss.pnc.spi.datastore.repositories.api.SortInfo in project pnc by project-ncl.

the class SortInfoTest method shouldCreateProperComparator.

@Test
public void shouldCreateProperComparator() throws Exception {
    // given
    String sorting = "=asc=(field1)";
    List<SortTester> tester = new ArrayList<>();
    tester.add(new SortTester("b", "b"));
    tester.add(new SortTester("a", "b"));
    // when
    SortInfo testedSorting = defaultSortInfoProducer.getSortInfo(sorting);
    List<String> sorted = tester.stream().sorted(testedSorting.getComparator()).map(SortTester::getField1).collect(Collectors.toList());
    // then
    assertThat(sorted).containsExactly("a", "b");
}
Also used : ArrayList(java.util.ArrayList) SortInfo(org.jboss.pnc.spi.datastore.repositories.api.SortInfo) Test(org.junit.Test)

Aggregations

SortInfo (org.jboss.pnc.spi.datastore.repositories.api.SortInfo)20 BuildRecord (org.jboss.pnc.model.BuildRecord)9 Test (org.junit.Test)9 PageInfo (org.jboss.pnc.spi.datastore.repositories.api.PageInfo)8 DefaultPageInfo (org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultPageInfo)7 DefaultSortInfo (org.jboss.pnc.spi.datastore.repositories.api.impl.DefaultSortInfo)5 ArrayList (java.util.ArrayList)3 Build (org.jboss.pnc.dto.Build)3 Page (org.jboss.pnc.dto.response.Page)3 BuildPageInfo (org.jboss.pnc.facade.providers.api.BuildPageInfo)2 Predicate (org.jboss.pnc.spi.datastore.repositories.api.Predicate)2 Node (cz.jirutka.rsql.parser.ast.Node)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 EmptySortInfo (org.jboss.pnc.datastore.limits.rsql.EmptySortInfo)1 MergeIterator (org.jboss.pnc.facade.util.MergeIterator)1 BuildRecordPredicates.temporaryBuild (org.jboss.pnc.spi.datastore.predicates.BuildRecordPredicates.temporaryBuild)1 BuildRecordRepository (org.jboss.pnc.spi.datastore.repositories.BuildRecordRepository)1