VoTaxServiceImpl implements VoTaxService { @Override public VoSearchResult<VoTax> getFilteredTax(final VoSearchContext filter) throws Exception { final VoSearchResult<VoTax> result = new VoSearchResult<>(); final List<VoTax> results = new ArrayList<>(); result.setSearchContext(filter); result.setItems(results); final String shopCode = FilterSearchUtils.getStringFilter(filter.getParameters().get("shopCode")); final String currency = FilterSearchUtils.getStringFilter(filter.getParameters().get("currency")); if (federationFacade.isManageable(shopCode, ShopDTO.class) && StringUtils.isNotBlank(currency)) { final SearchContext searchContext = new SearchContext( filter.getParameters(), filter.getStart(), filter.getSize(), filter.getSortBy(), filter.isSortDesc(), "filter", "shopCode", "currency" ); final SearchResult<TaxDTO> batch = dtoTaxService.findTaxes(searchContext); if (!batch.getItems().isEmpty()) { results.addAll(voAssemblySupport.assembleVos(VoTax.class, TaxDTO.class, batch.getItems())); } result.setTotal(batch.getTotal()); } return result; } VoTaxServiceImpl(final DtoTaxService dtoTaxService,
                            final DtoTaxConfigService dtoTaxConfigService,
                            final ShopService shopService,
                            final FederationFacade federationFacade,
                            final VoAssemblySupport voAssemblySupport); @Override VoSearchResult<VoTax> getFilteredTax(final VoSearchContext filter); @Override VoTax getTaxById(final long id); @Override VoTax updateTax(final VoTax vo); @Override VoTax createTax(final VoTax vo); @Override void removeTax(final long id); @Override VoSearchResult<VoTaxConfig> getFilteredTaxConfig(final VoSearchContext filter); @Override VoTaxConfig getTaxConfigById(final long id); @Override VoTaxConfig createTaxConfig(final VoTaxConfig vo); @Override void removeTaxConfig(final long id);  }
@Test public void testGetTaxes() throws Exception { VoSearchContext ctxAny = new VoSearchContext(); ctxAny.setParameters(createSearchContextParams( "shopCode", "SHOIP1", "currency", "EUR" )); ctxAny.setSize(10); final List<VoTax> taxesNoFilter = voTaxService.getFilteredTax(ctxAny).getItems(); assertNotNull(taxesNoFilter); assertFalse(taxesNoFilter.isEmpty()); VoSearchContext ctxFind = new VoSearchContext(); ctxFind.setParameters(createSearchContextParams( "shopCode", "SHOIP1", "currency", "EUR", "filter", "VAT (CC_TEST1)" )); ctxFind.setSize(10); final List<VoTax> taxesFind = voTaxService.getFilteredTax(ctxFind).getItems(); assertNotNull(taxesFind); assertFalse(taxesFind.isEmpty()); assertEquals("VAT (CC_TEST1)", taxesFind.get(0).getCode()); VoSearchContext ctxExclusive = new VoSearchContext(); ctxExclusive.setParameters(createSearchContextParams( "shopCode", "SHOIP1", "currency", "EUR", "filter", "++" )); ctxExclusive.setSize(10); final List<VoTax> taxesExclusive = voTaxService.getFilteredTax(ctxExclusive).getItems(); assertNotNull(taxesExclusive); assertFalse(taxesExclusive.isEmpty()); assertTrue(taxesExclusive.get(0).isExclusiveOfPrice()); VoSearchContext ctxInclusive = new VoSearchContext(); ctxInclusive.setParameters(createSearchContextParams( "shopCode", "SHOIP1", "currency", "EUR", "filter", "--" )); ctxInclusive.setSize(10); final List<VoTax> taxesInclusive = voTaxService.getFilteredTax(ctxInclusive).getItems(); assertNotNull(taxesInclusive); assertFalse(taxesInclusive.isEmpty()); assertFalse(taxesInclusive.get(0).isExclusiveOfPrice()); VoSearchContext ctxRate = new VoSearchContext(); ctxRate.setParameters(createSearchContextParams( "shopCode", "SHOIP1", "currency", "EUR", "filter", "%5" )); ctxRate.setSize(10); final List<VoTax> taxesByRate = voTaxService.getFilteredTax(ctxRate).getItems(); assertNotNull(taxesByRate); assertFalse(taxesByRate.isEmpty()); assertTrue(taxesByRate.stream().allMatch(tax -> new BigDecimal(5).compareTo(tax.getTaxRate()) == 0)); }