diff --git a/src/main/java/org/opensrp/web/rest/ProductCatalogueResource.java b/src/main/java/org/opensrp/web/rest/ProductCatalogueResource.java index fbf89ebe8..e69fae4a7 100644 --- a/src/main/java/org/opensrp/web/rest/ProductCatalogueResource.java +++ b/src/main/java/org/opensrp/web/rest/ProductCatalogueResource.java @@ -66,8 +66,8 @@ public List getAll( return productCatalogueService.getProductCatalogues(productCatalogueSearchBean, baseUrl); - } + @GetMapping(produces = { MediaType.APPLICATION_JSON_VALUE }, params = "limit") public List getAll( @RequestParam(value = "productName", defaultValue = "", required = false) String productName @@ -76,7 +76,6 @@ public List getAll( @RequestParam(value = "limit") String limit) { final String baseUrl = ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString(); - Long lastSyncedServerVersion = null; if (serverVersion != null) { lastSyncedServerVersion = Long.parseLong(serverVersion); @@ -87,10 +86,11 @@ public List getAll( productCatalogueSearchBean.setUniqueId(uniqueId); productCatalogueSearchBean.setServerVersion(lastSyncedServerVersion); - if(StringUtils.isBlank(limit)){ - return productCatalogueService.getProductCatalogues(productCatalogueSearchBean, Integer.MAX_VALUE,baseUrl); + if (StringUtils.isBlank(limit)) { + return productCatalogueService.getProductCatalogues(productCatalogueSearchBean, Integer.MAX_VALUE, baseUrl); } else { - return productCatalogueService.getProductCatalogues(productCatalogueSearchBean, Integer.parseInt(limit), baseUrl); + return productCatalogueService + .getProductCatalogues(productCatalogueSearchBean, Integer.parseInt(limit), baseUrl); } } @@ -100,7 +100,8 @@ public ResponseEntity create(@RequestPart(required = false) MultipartFil try { productCatalogueService.add(productCatalogue); - ProductCatalogue createdProductCatalogue = productCatalogueService.getProductCatalogueByName(productCatalogue.getProductName()); + ProductCatalogue createdProductCatalogue = productCatalogueService + .getProductCatalogueByName(productCatalogue.getProductName()); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String userName = authentication.getName(); @@ -136,7 +137,7 @@ public ResponseEntity update(@PathVariable("id") Long uniqueId, @RequestPart ProductCatalogue productCatalogue) { try { - if(file != null) { + if (file != null) { productCatalogue.setPhotoURL(DOWNLOAD_PHOTO_END_POINT + productCatalogue.getUniqueId()); } diff --git a/src/test/java/org/opensrp/web/rest/ProductCatalogueResourceTest.java b/src/test/java/org/opensrp/web/rest/ProductCatalogueResourceTest.java index ce27fed5b..4db8c0fef 100644 --- a/src/test/java/org/opensrp/web/rest/ProductCatalogueResourceTest.java +++ b/src/test/java/org/opensrp/web/rest/ProductCatalogueResourceTest.java @@ -35,6 +35,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.Mockito; + import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyLong; @@ -43,6 +44,7 @@ import static org.mockito.Mockito.when; import static org.mockito.Mockito.times; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; + import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -103,7 +105,8 @@ public void testGetAll() throws Exception { .andExpect(status().isOk()) .andReturn(); - List response = (List) result.getModelAndView().getModel().get("productCatalogueList"); + List response = (List) result.getModelAndView().getModel() + .get("productCatalogueList"); if (response.size() == 0) { fail("Test case failed"); @@ -121,13 +124,15 @@ public void testGetAllWithLimitParam() throws Exception { productCatalogue.setUniqueId(1l); List productCatalogues = new ArrayList<>(); productCatalogues.add(productCatalogue); - when(productCatalogueService.getProductCatalogues(any(ProductCatalogueSearchBean.class), any(Integer.class),anyString())) + when(productCatalogueService + .getProductCatalogues(any(ProductCatalogueSearchBean.class), any(Integer.class), anyString())) .thenReturn(productCatalogues); - MvcResult result = mockMvc.perform(get(BASE_URL+"?limit=10")) + MvcResult result = mockMvc.perform(get(BASE_URL + "?limit=10")) .andExpect(status().isOk()) .andReturn(); - List response = (List) result.getModelAndView().getModel().get("productCatalogueList"); + List response = (List) result.getModelAndView().getModel() + .get("productCatalogueList"); if (response.size() == 0) { fail("Test case failed"); @@ -159,9 +164,9 @@ public void testCreate() throws Exception { when(multipartFile.getContentType()).thenReturn(""); when(multipartFile.getBytes()).thenReturn(bytes); when(multipartFile.getOriginalFilename()).thenReturn("Midwifery kit image"); - when(multimediaService.saveFile(any(MultimediaDTO.class),any(byte[].class),anyString())).thenReturn("Success"); + when(multimediaService.saveFile(any(MultimediaDTO.class), any(byte[].class), anyString())).thenReturn("Success"); - productCatalogueResource.create(multipartFile,productCatalogue); + productCatalogueResource.create(multipartFile, productCatalogue); verify(productCatalogueService).add(argumentCaptor.capture()); @@ -199,9 +204,9 @@ public void testUpdate() throws Exception { when(multipartFile.getContentType()).thenReturn(""); when(multipartFile.getBytes()).thenReturn(bytes); when(multipartFile.getOriginalFilename()).thenReturn("Midwifery kit image"); - when(multimediaService.saveFile(any(MultimediaDTO.class),any(byte[].class),anyString())).thenReturn("Success"); + when(multimediaService.saveFile(any(MultimediaDTO.class), any(byte[].class), anyString())).thenReturn("Success"); - productCatalogueResource.update(1l,multipartFile,productCatalogue); + productCatalogueResource.update(1l, multipartFile, productCatalogue); verify(productCatalogueService).update(argumentCaptor.capture()); @@ -246,7 +251,6 @@ public void testDelete() throws Exception { assertEquals(argumentCaptor.getValue().longValue(), 1); } - private ProductCatalogue createProductCatalog() { ProductCatalogue productCatalogue = new ProductCatalogue(); productCatalogue.setProductName("Scale");