@Test public void testSorting() { context.request().setParameterMap(Collections.singletonMap("search_query", "glove")); searchResultsModel = context.request().adaptTo(SearchResultsImpl.class); SearchResultsSet resultSet = searchResultsModel.getSearchResultsSet(); Assert.assertNotNull(resultSet); Assert.assertTrue(resultSet.hasSorting()); Sorter sorter = resultSet.getSorter(); Assert.assertNotNull(sorter); SorterKey currentKey = sorter.getCurrentKey(); Assert.assertNotNull(currentKey); Assert.assertEquals("relevance", currentKey.getName()); Assert.assertEquals("Relevance", currentKey.getLabel()); Assert.assertEquals(Sorter.Order.DESC, currentKey.getOrder()); Assert.assertTrue(currentKey.isSelected()); Map<String, String> currentOrderParameters = currentKey.getCurrentOrderParameters(); Assert.assertNotNull(currentOrderParameters); Assert.assertEquals(resultSet.getAppliedQueryParameters().size() + 2, currentOrderParameters.size()); resultSet.getAppliedQueryParameters().forEach((key, value) -> Assert.assertEquals(value, currentOrderParameters.get(key))); Assert.assertEquals("relevance", currentOrderParameters.get(Sorter.PARAMETER_SORT_KEY)); Assert.assertEquals("desc", currentOrderParameters.get(Sorter.PARAMETER_SORT_ORDER)); Map<String, String> oppositeOrderParameters = currentKey.getOppositeOrderParameters(); Assert.assertNotNull(oppositeOrderParameters); Assert.assertEquals(resultSet.getAppliedQueryParameters().size() + 2, oppositeOrderParameters.size()); resultSet.getAppliedQueryParameters().forEach((key, value) -> Assert.assertEquals(value, oppositeOrderParameters.get(key))); Assert.assertEquals("relevance", oppositeOrderParameters.get(Sorter.PARAMETER_SORT_KEY)); Assert.assertEquals("asc", oppositeOrderParameters.get(Sorter.PARAMETER_SORT_ORDER)); List<SorterKey> keys = sorter.getKeys(); Assert.assertNotNull(keys); Assert.assertEquals(3, keys.size()); SorterKey defaultKey = keys.get(0); Assert.assertEquals(currentKey.getName(), defaultKey.getName()); SorterKey otherKey = keys.get(1); Assert.assertEquals("price", otherKey.getName()); Assert.assertEquals("Price", otherKey.getLabel()); Assert.assertEquals(Sorter.Order.ASC, otherKey.getOrder()); otherKey = keys.get(2); Assert.assertEquals("name", otherKey.getName()); Assert.assertEquals("Product Name", otherKey.getLabel()); Assert.assertEquals(Sorter.Order.ASC, otherKey.getOrder()); }
@Nonnull @Override public SearchResultsSet getSearchResultsSet() { if (searchResultsSet == null) { searchResultsSet = searchResultsService.performSearch(searchOptions, resource, productPage, request); } return searchResultsSet; }
SearchResultsImpl extends ProductCollectionImpl implements SearchResults { @Nonnull @Override public SearchResultsSet getSearchResultsSet() { if (searchResultsSet == null) { searchResultsSet = searchResultsService.performSearch(searchOptions, resource, productPage, request); } return searchResultsSet; } }
SearchResultsImpl extends ProductCollectionImpl implements SearchResults { @Nonnull @Override public SearchResultsSet getSearchResultsSet() { if (searchResultsSet == null) { searchResultsSet = searchResultsService.performSearch(searchOptions, resource, productPage, request); } return searchResultsSet; }  }
SearchResultsImpl extends ProductCollectionImpl implements SearchResults { @Nonnull @Override public SearchResultsSet getSearchResultsSet() { if (searchResultsSet == null) { searchResultsSet = searchResultsService.performSearch(searchOptions, resource, productPage, request); } return searchResultsSet; }  @Nonnull @Override Collection<ProductListItem> getProducts(); @Nonnull @Override SearchResultsSet getSearchResultsSet(); }
SearchResultsImpl extends ProductCollectionImpl implements SearchResults { @Nonnull @Override public SearchResultsSet getSearchResultsSet() { if (searchResultsSet == null) { searchResultsSet = searchResultsService.performSearch(searchOptions, resource, productPage, request); } return searchResultsSet; }  @Nonnull @Override Collection<ProductListItem> getProducts(); @Nonnull @Override SearchResultsSet getSearchResultsSet();  }