LocationDaoImpl implements LocationDao { public SearchDTO addSortBy(SearchDTO searchDtO) { if (MapUtils.isNotEmpty(searchDtO.getAdditionalProperties()) && searchDtO.getAdditionalProperties().containsKey(JsonKey.FILTERS) && searchDtO.getAdditionalProperties().get(JsonKey.FILTERS) instanceof Map && ((Map<String, Object>) searchDtO.getAdditionalProperties().get(JsonKey.FILTERS)) .containsKey(JsonKey.TYPE)) { if (MapUtils.isEmpty(searchDtO.getSortBy())) { ProjectLogger.log( "LocationDaoImpl:search:addSortBy added sort type name attribute.", LoggerEnum.INFO.name()); searchDtO.getSortBy().put(JsonKey.NAME, DEFAULT_SORT_BY); } } return searchDtO; }  @Override Response create(Location location); @Override Response update(Location location); @Override Response delete(String locationId); @Override Response search(Map<String, Object> searchQueryMap); @Override Response read(String locationId); @Override Response getRecordByProperty(Map<String, Object> queryMap); SearchDTO addSortBy(SearchDTO searchDtO);  }
@Test public void addSortBySuccess() { LocationDaoImpl dao = new LocationDaoImpl(); SearchDTO searchDto = createSearchDtoObj(); searchDto = dao.addSortBy(searchDto); Assert.assertTrue(searchDto.getSortBy().size() == 1); }
@Test public void sortByNotAddedInCaseFilterWontHaveTypeKey() { LocationDaoImpl dao = new LocationDaoImpl(); SearchDTO searchDto = createSearchDtoObj(); ((Map<String, Object>) searchDto.getAdditionalProperties().get(JsonKey.FILTERS)) .remove(JsonKey.TYPE); searchDto = dao.addSortBy(searchDto); Assert.assertTrue(searchDto.getSortBy().size() == 0); }
@Test public void sortByNotAddedInCasePresent() { LocationDaoImpl dao = new LocationDaoImpl(); SearchDTO searchDto = createSearchDtoObj(); searchDto.getSortBy().put("some key", "DESC"); searchDto = dao.addSortBy(searchDto); Assert.assertTrue(searchDto.getSortBy().size() == 1); }