DiscoverConfigurationConverter implements DSpaceConverter<DiscoveryConfiguration, SearchConfigurationRest> { @Override public SearchConfigurationRest convert(DiscoveryConfiguration configuration, Projection projection) { SearchConfigurationRest searchConfigurationRest = new SearchConfigurationRest(); searchConfigurationRest.setProjection(projection); if (configuration != null) { addSearchFilters(searchConfigurationRest, configuration.getSearchFilters(), configuration.getSidebarFacets()); addSortOptions(searchConfigurationRest, configuration.getSearchSortConfiguration()); setDefaultSortOption(configuration, searchConfigurationRest); } return searchConfigurationRest; }  @Override SearchConfigurationRest convert(DiscoveryConfiguration configuration, Projection projection); @Override Class<DiscoveryConfiguration> getModelClass(); void addSearchFilters(SearchConfigurationRest searchConfigurationRest,
                                 List<DiscoverySearchFilter> searchFilterList,
                                 List<DiscoverySearchFilterFacet> facetList);  }
@Test public void testReturnType() throws Exception { populateDiscoveryConfigurationWithEmptyList(); searchConfigurationRest = discoverConfigurationConverter.convert(discoveryConfiguration, Projection.DEFAULT); assertTrue(searchConfigurationRest.getFilters().isEmpty()); assertEquals(SearchConfigurationRest.class, searchConfigurationRest.getClass()); }
@Test public void testConvertWithNullParamter() throws Exception { assertNotNull(discoverConfigurationConverter.convert(null, Projection.DEFAULT)); }
@Test public void testNoSearchSortConfigurationReturnObjectNotNull() throws Exception { discoveryConfiguration.setSearchFilters(new LinkedList<>()); searchConfigurationRest = discoverConfigurationConverter.convert(discoveryConfiguration, Projection.DEFAULT); assertTrue(discoveryConfiguration.getSearchFilters().isEmpty()); assertTrue(searchConfigurationRest.getFilters().isEmpty()); assertNotNull(searchConfigurationRest); }
@Test public void testNoSearchFilterReturnObjectNotNull() throws Exception { discoveryConfiguration.setSearchSortConfiguration(new DiscoverySortConfiguration()); searchConfigurationRest = discoverConfigurationConverter.convert(discoveryConfiguration, Projection.DEFAULT); assertTrue(searchConfigurationRest.getFilters().isEmpty()); assertNotNull(searchConfigurationRest); }
@Test public void testNoSearchSortConfigurationAndNoSearchFilterReturnObjectNotNull() throws Exception { searchConfigurationRest = discoverConfigurationConverter.convert(discoveryConfiguration, Projection.DEFAULT); assertNotNull(searchConfigurationRest); }
@Test public void testCorrectSortOptionsAfterConvert() throws Exception { populateDiscoveryConfigurationWithEmptyList(); DiscoverySortFieldConfiguration discoverySortFieldConfiguration = new DiscoverySortFieldConfiguration(); discoverySortFieldConfiguration.setMetadataField("title"); discoverySortFieldConfiguration.setType("text"); DiscoverySortFieldConfiguration discoverySortFieldConfiguration1 = new DiscoverySortFieldConfiguration(); discoverySortFieldConfiguration1.setMetadataField("author"); discoverySortFieldConfiguration1.setType("text"); LinkedList<DiscoverySortFieldConfiguration> mockedList = new LinkedList<>(); mockedList.add(discoverySortFieldConfiguration); mockedList.add(discoverySortFieldConfiguration1); when(discoveryConfiguration.getSearchSortConfiguration()).thenReturn(discoverySortConfiguration); when(discoverySortConfiguration.getSortFields()).thenReturn(mockedList); searchConfigurationRest = discoverConfigurationConverter.convert(discoveryConfiguration, Projection.DEFAULT); int counter = 0; for (SearchConfigurationRest.SortOption sortOption : searchConfigurationRest.getSortOptions()) { assertEquals(mockedList.get(counter).getMetadataField(), sortOption.getName()); assertEquals(mockedList.get(counter).getType(), sortOption.getActualName()); counter++; } assertFalse(searchConfigurationRest.getSortOptions().isEmpty()); }
@Test public void testEmptySortOptionsAfterConvertWithConfigurationWithEmptySortFields() throws Exception { populateDiscoveryConfigurationWithEmptyList(); searchConfigurationRest = discoverConfigurationConverter.convert(discoveryConfiguration, Projection.DEFAULT); assertEquals(0, searchConfigurationRest.getSortOptions().size()); }
@Test public void testEmptySortOptionsAfterConvertWithConfigurationWithNullSortFields() throws Exception { populateDiscoveryConfigurationWithEmptyList(); when(discoveryConfiguration.getSearchSortConfiguration()).thenReturn(null); searchConfigurationRest = discoverConfigurationConverter.convert(discoveryConfiguration, Projection.DEFAULT); assertEquals(0, searchConfigurationRest.getSortOptions().size()); }
@Test public void testCorrectSearchFiltersAfterConvert() throws Exception { populateDiscoveryConfigurationWithEmptyList(); LinkedList<DiscoverySearchFilter> mockedList = new LinkedList(); DiscoverySearchFilter discoverySearchFilter = new DiscoverySearchFilter(); discoverySearchFilter.setIndexFieldName("title"); DiscoverySearchFilter discoverySearchFilter1 = new DiscoverySearchFilter(); discoverySearchFilter1.setIndexFieldName("title2"); mockedList.add(discoverySearchFilter); mockedList.add(discoverySearchFilter1); when(discoveryConfiguration.getSearchFilters()).thenReturn(mockedList); searchConfigurationRest = discoverConfigurationConverter.convert(discoveryConfiguration, Projection.DEFAULT); int counter = 0; for (SearchConfigurationRest.Filter filter : searchConfigurationRest.getFilters()) { DiscoverySearchFilter searchFilter = mockedList.get(counter); assertEquals(searchFilter.getIndexFieldName(), filter.getFilter()); SearchConfigurationRest.Filter.Operator operator = new SearchConfigurationRest.Filter.Operator("testing"); filter.addOperator(operator); assertEquals(filter.getOperators().get(filter.getOperators().size() - 1), operator); counter++; } assertTrue(!(searchConfigurationRest.getFilters().isEmpty())); }
@Test public void testEmptySearchFilterAfterConvertWithConfigurationWithEmptySearchFilters() throws Exception { populateDiscoveryConfigurationWithEmptyList(); searchConfigurationRest = discoverConfigurationConverter.convert(discoveryConfiguration, Projection.DEFAULT); assertEquals(0, searchConfigurationRest.getFilters().size()); }
@Test public void testEmptySearchFiltersAfterConvertWithConfigurationWithNullSearchFilters() throws Exception { populateDiscoveryConfigurationWithEmptyList(); when(discoveryConfiguration.getSearchFilters()).thenReturn(null); searchConfigurationRest = discoverConfigurationConverter.convert(discoveryConfiguration, Projection.DEFAULT); assertEquals(0, searchConfigurationRest.getFilters().size()); }