Skip to content

Commit

Permalink
applied opensrp code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hilpitome committed Jun 4, 2021
1 parent 8d94506 commit 2cc88fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
15 changes: 8 additions & 7 deletions src/main/java/org/opensrp/web/rest/ProductCatalogueResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public List<ProductCatalogue> getAll(

return productCatalogueService.getProductCatalogues(productCatalogueSearchBean, baseUrl);


}

@GetMapping(produces = { MediaType.APPLICATION_JSON_VALUE }, params = "limit")
public List<ProductCatalogue> getAll(
@RequestParam(value = "productName", defaultValue = "", required = false) String productName
Expand All @@ -76,7 +76,6 @@ public List<ProductCatalogue> getAll(
@RequestParam(value = "limit") String limit) {
final String baseUrl = ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString();


Long lastSyncedServerVersion = null;
if (serverVersion != null) {
lastSyncedServerVersion = Long.parseLong(serverVersion);
Expand All @@ -87,10 +86,11 @@ public List<ProductCatalogue> 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);
}
}

Expand All @@ -100,7 +100,8 @@ public ResponseEntity<String> 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();
Expand Down Expand Up @@ -136,7 +137,7 @@ public ResponseEntity<String> update(@PathVariable("id") Long uniqueId,
@RequestPart ProductCatalogue productCatalogue) {

try {
if(file != null) {
if (file != null) {
productCatalogue.setPhotoURL(DOWNLOAD_PHOTO_END_POINT + productCatalogue.getUniqueId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -103,7 +105,8 @@ public void testGetAll() throws Exception {
.andExpect(status().isOk())
.andReturn();

List<ProductCatalogue> response = (List<ProductCatalogue>) result.getModelAndView().getModel().get("productCatalogueList");
List<ProductCatalogue> response = (List<ProductCatalogue>) result.getModelAndView().getModel()
.get("productCatalogueList");

if (response.size() == 0) {
fail("Test case failed");
Expand All @@ -121,13 +124,15 @@ public void testGetAllWithLimitParam() throws Exception {
productCatalogue.setUniqueId(1l);
List<ProductCatalogue> 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<ProductCatalogue> response = (List<ProductCatalogue>) result.getModelAndView().getModel().get("productCatalogueList");
List<ProductCatalogue> response = (List<ProductCatalogue>) result.getModelAndView().getModel()
.get("productCatalogueList");

if (response.size() == 0) {
fail("Test case failed");
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -246,7 +251,6 @@ public void testDelete() throws Exception {
assertEquals(argumentCaptor.getValue().longValue(), 1);
}


private ProductCatalogue createProductCatalog() {
ProductCatalogue productCatalogue = new ProductCatalogue();
productCatalogue.setProductName("Scale");
Expand Down

0 comments on commit 2cc88fe

Please sign in to comment.