Skip to content

Commit

Permalink
Merge branch 'master' into '662-stock-sync-post'
Browse files Browse the repository at this point in the history
  • Loading branch information
rehammuzzamil committed Jan 12, 2021
2 parents cbc77cc + 2f38855 commit e65fcf7
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 32 deletions.
Empty file modified Dockerfile
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<artifactId>opensrp-server-web</artifactId>
<packaging>war</packaging>
<version>2.4.10-SNAPSHOT</version>
<version>2.4.12-SNAPSHOT</version>
<name>opensrp-server-web</name>
<description>OpenSRP Server Web Application</description>
<url>https://github.com/OpenSRP/opensrp-server-web</url>
Expand All @@ -26,7 +26,7 @@
<redis.lettuce.version>5.2.2.RELEASE</redis.lettuce.version>
<opensrp.updatePolicy>always</opensrp.updatePolicy>
<nexus-staging-maven-plugin.version>1.5.1</nexus-staging-maven-plugin.version>
<opensrp.core.version>2.8.11-SNAPSHOT</opensrp.core.version>
<opensrp.core.version>2.8.15-SNAPSHOT</opensrp.core.version>
<opensrp.connector.version>2.2.0-SNAPSHOT</opensrp.connector.version>
<opensrp.common.version>2.0.3-SNAPSHOT</opensrp.common.version>
<opensrp.interface.version>2.0.1-SNAPSHOT</opensrp.interface.version>
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/opensrp/web/rest/TaskResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -292,16 +294,17 @@ public ResponseEntity<ModelMap> countAll(@RequestParam(value = SERVER_VERSION) l
public ResponseEntity<String> getOptionalTasksWithCount(@Valid TaskSearchBean taskSearchBean) {

HttpHeaders headers = RestUtils.getJSONUTF8Headers();
Map<String, Object> response = new HashMap<>();
int taskCount = taskService.findTaskCountBySearchBean(taskSearchBean);
headers.add(TOTAL_RECORDS, String.valueOf(taskCount));
List<Task> tasks;
if (taskSearchBean != null && taskSearchBean.isReturnTaskCountOnly()) {
tasks = new ArrayList<>();
} else {
tasks = taskService.getTasksBySearchBean(taskSearchBean);
}

return new ResponseEntity<>(gson.toJson(tasks), headers, HttpStatus.OK);
response.put("tasks", tasks);
response.put(TOTAL_RECORDS, taskCount);
return new ResponseEntity<>(gson.toJson(response), headers, HttpStatus.OK);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/opensrp/web/rest/SearchResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void setUp() {

searchService = Mockito.spy(new SearchService(searchRepository));
clientService = Mockito.spy(new ClientService(clientRepository));
eventService = Mockito.spy(new EventService(eventsRepository, clientService,taskGenerator,planRepository));
eventService = Mockito.spy(new EventService(eventsRepository, clientService,taskGenerator,planRepository, null));

}

Expand Down
5 changes: 1 addition & 4 deletions src/test/java/org/opensrp/web/rest/SettingResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
Expand Down Expand Up @@ -222,7 +221,7 @@ public void testValidValue() {
public void testPostSaveSetting() throws Exception {
String SETTINGS_JSON = "{\"settingConfigurations\":[\"Client1\"]}";

when(settingService.saveSetting(Matchers.any(String.class))).thenReturn("ID-12345");
when(settingService.saveSetting(any(String.class))).thenReturn("ID-12345");
MvcResult mvcResult = this.mockMvc.perform(
post(BASE_URL + "/sync").contentType(MediaType.APPLICATION_JSON).content(SETTINGS_JSON.getBytes())
.accept(MediaType.APPLICATION_JSON))
Expand Down Expand Up @@ -267,7 +266,6 @@ public void testSaveSetting() {

verify(settingRepository, Mockito.times(1)).addSettings(settingConfigurationArgumentCaptor.capture());
verify(settingRepository, Mockito.times(1)).get(documentId);
verify(settingRepository).getNextServerVersion();
verifyNoMoreInteractions(settingRepository);
}

Expand All @@ -290,7 +288,6 @@ public void testUpdateSetting() throws JsonProcessingException {

verify(settingRepository, Mockito.times(1)).get(documentId);
verify(settingRepository, Mockito.times(1)).update(settingConfigurationArgumentCaptor.capture());
verify(settingRepository).getNextServerVersion();
verifyNoMoreInteractions(settingRepository);
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/opensrp/web/rest/StockResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public void testGetStockItemsByServicePoint() throws Exception {
}

assertEquals(1, response.size());
assertEquals(new Long(12345), response.get(0).getIdentifier());
assertEquals("12345", response.get(0).getIdentifier());

}

Expand Down Expand Up @@ -369,7 +369,7 @@ public void testImportInventoryDataWithErrors() throws Exception {

private Stock createStock() {
Stock stock = new Stock();
stock.setIdentifier(12345l);
stock.setIdentifier("12345");
stock.setId("ID-123");
return stock;
}
Expand Down
18 changes: 13 additions & 5 deletions src/test/java/org/opensrp/web/rest/TaskResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.AssertionErrors.fail;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
Expand All @@ -23,6 +24,8 @@
import java.util.Collections;
import java.util.List;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.tuple.Pair;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -99,6 +102,8 @@ public class TaskResourceTest {
private DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HHmm");

private org.opensrp.web.rest.v2.TaskResource taskResourceV2 = new org.opensrp.web.rest.v2.TaskResource();

protected ObjectMapper mapper = new ObjectMapper();

@Before
public void setUp() {
Expand Down Expand Up @@ -473,7 +478,7 @@ public void testGetTasksByPlanAndOwnerWithReturnCount() throws Exception {
public void testGetOptionalTasksWithCount() throws Exception {
List<Task> tasks = new ArrayList<>();
tasks.add(getTask());
int totalRecords = 5;
int totalRecords = 1;
when(taskService.getTasksBySearchBean(any(TaskSearchBean.class))).thenReturn(tasks);
when(taskService.findTaskCountBySearchBean(any(TaskSearchBean.class))).thenReturn(totalRecords);
MvcResult result = mockMvc.perform(get(BASE_URL + "/search")
Expand All @@ -483,10 +488,13 @@ public void testGetOptionalTasksWithCount() throws Exception {
verify(taskService, times(1)).getTasksBySearchBean(any(TaskSearchBean.class));
verify(taskService, times(1)).findTaskCountBySearchBean(any(TaskSearchBean.class));
verifyNoMoreInteractions(taskService);
JSONArray jsonreponse = new JSONArray(result.getResponse().getContentAsString());
assertEquals(1, jsonreponse.length());
int actualTotalRecords = Integer.parseInt(result.getResponse().getHeader("total_records"));
assertEquals(totalRecords, actualTotalRecords);
String responseString = result.getResponse().getContentAsString();
if (responseString.isEmpty()) {
fail("Test case failed");
}
JsonNode actualObj = mapper.readTree(responseString);
assertEquals(1, actualObj.get("total_records").asInt());
assertEquals(1, actualObj.get("tasks").size());
}

}
28 changes: 14 additions & 14 deletions src/test/java/org/opensrp/web/rest/it/StockResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void testStockClassHasAllTheRequiredField() {
@Test
@Ignore
public void shouldFindByProviderId() throws Exception {
Stock expectedStock = new Stock(200l, "vaccineTypeId", "transactionType", "providerId", 3,
Stock expectedStock = new Stock("200", "vaccineTypeId", "transactionType", "providerId", 3,
new DateTime(0l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(0l, DateTimeZone.UTC).getMillis(),
223l);
addObjectToRepository(Collections.singletonList(expectedStock), allStocks);
Expand All @@ -83,7 +83,7 @@ public void shouldFindByProviderId() throws Exception {

@Test
public void shouldNotFindStock() throws Exception {
Stock expectedStock = new Stock(200l, "vaccineTypeId", "transactionType", "providerId", 3,
Stock expectedStock = new Stock("200", "vaccineTypeId", "transactionType", "providerId", 3,
new DateTime(0l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(0l, DateTimeZone.UTC).getMillis(),
223l);
addObjectToRepository(Collections.singletonList(expectedStock), allStocks);
Expand All @@ -95,13 +95,13 @@ public void shouldNotFindStock() throws Exception {
@Test
public void shouldGetAllStocks() throws Exception {
String url = BASE_URL + "/getall";
Stock expectedStock1 = new Stock(200l, "vaccineTypeId", "transactionType", "providerId", 3,
Stock expectedStock1 = new Stock("200", "vaccineTypeId", "transactionType", "providerId", 3,
new DateTime(0l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(0l, DateTimeZone.UTC).getMillis(),
223l);
Stock expectedStock2 = new Stock(300l, "vaccineTypeId", "transactionType", "providerId1", 3,
Stock expectedStock2 = new Stock("300", "vaccineTypeId", "transactionType", "providerId1", 3,
new DateTime(10l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(10l, DateTimeZone.UTC).getMillis(),
223l);
Stock expectedStock3 = new Stock(400l, "vaccineTypeId", "transactionType", "providerId2", 3,
Stock expectedStock3 = new Stock("400", "vaccineTypeId", "transactionType", "providerId2", 3,
new DateTime(100l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(100l, DateTimeZone.UTC).getMillis(),
223l);
List<Stock> expectedStocks = asList(expectedStock1, expectedStock2, expectedStock3);
Expand All @@ -118,7 +118,7 @@ public void shouldGetAllStocks() throws Exception {
@Test
@Ignore
public void shouldCreateValidStock() throws Exception {
Stock expectedStock = new Stock(200l, "vaccineTypeId", "transactionType", "providerId", 3,
Stock expectedStock = new Stock("200", "vaccineTypeId", "transactionType", "providerId", 3,
new DateTime(0l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(0l, DateTimeZone.UTC).getMillis(),
223l);
String postData = mapper.writeValueAsString(expectedStock);
Expand All @@ -131,7 +131,7 @@ public void shouldCreateValidStock() throws Exception {

@Test(expected = NestedServletException.class)
public void shouldFailCreateStockWithOutProviderId() throws Exception {
Stock expectedStock = new Stock(200l, "vaccineTypeId", "transactionType", "providerId", 3,
Stock expectedStock = new Stock("200", "vaccineTypeId", "transactionType", "providerId", 3,
new DateTime(0l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(0l, DateTimeZone.UTC).getMillis(),
223l);
expectedStock.setProviderid(null);
Expand All @@ -143,7 +143,7 @@ public void shouldFailCreateStockWithOutProviderId() throws Exception {
//TODO: `Stock.class` doesn't have a field call `timestamp`
/*@Test(expected = NestedServletException.class)
public void shouldFailCreateStockWithOutTimestamp() throws Exception{
Stock expectedStock = new Stock(200l, "vaccineTypeId", "transactionType", "providerId", 3,
Stock expectedStock = new Stock("200", "vaccineTypeId", "transactionType", "providerId", 3,
new DateTime(0l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(0l, DateTimeZone.UTC).getMillis(),
223l);
expectedStock.setProviderid(null);
Expand All @@ -154,13 +154,13 @@ public void shouldFailCreateStockWithOutTimestamp() throws Exception{

@Test
public void shouldCreateValidStockUsingAddUrl() throws Exception {
Stock expectedStock1 = new Stock(200l, "vaccineTypeId", "transactionType", "providerId", 3,
Stock expectedStock1 = new Stock("200", "vaccineTypeId", "transactionType", "providerId", 3,
new DateTime(0l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(0l, DateTimeZone.UTC).getMillis(),
223l);
Stock expectedStock2 = new Stock(300l, "vaccineTypeId", "transactionType", "providerId1", 3,
Stock expectedStock2 = new Stock("300", "vaccineTypeId", "transactionType", "providerId1", 3,
new DateTime(10l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(10l, DateTimeZone.UTC).getMillis(),
223l);
Stock expectedStock3 = new Stock(400l, "vaccineTypeId", "transactionType", "providerId2", 3,
Stock expectedStock3 = new Stock("400", "vaccineTypeId", "transactionType", "providerId2", 3,
new DateTime(100l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(100l, DateTimeZone.UTC).getMillis(),
223l);
List<Stock> expectedStocks = asList(expectedStock1, expectedStock2, expectedStock3);
Expand All @@ -178,13 +178,13 @@ public void shouldCreateValidStockUsingAddUrl() throws Exception {
@Test
@Ignore
public void shouldUpdateExistingStockUsingAddUrl() throws Exception {
Stock expectedStock = new Stock(200l, "vaccineTypeId", "transactionType", "providerId", 3,
Stock expectedStock = new Stock("200", "vaccineTypeId", "transactionType", "providerId", 3,
new DateTime(0l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(0l, DateTimeZone.UTC).getMillis(),
223l);
Stock unchangedStock = new Stock(300l, "vaccineTypeId", "transactionType", "providerId1", 3,
Stock unchangedStock = new Stock("300", "vaccineTypeId", "transactionType", "providerId1", 3,
new DateTime(10l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(10l, DateTimeZone.UTC).getMillis(),
223l);
Stock unchangedStock2 = new Stock(400l, "vaccineTypeId", "transactionType", "providerId2", 3,
Stock unchangedStock2 = new Stock("400", "vaccineTypeId", "transactionType", "providerId2", 3,
new DateTime(100l, DateTimeZone.UTC).getMillis(), "toFrom", new DateTime(100l, DateTimeZone.UTC).getMillis(),
223l);
List<Stock> stocks = asList(expectedStock, unchangedStock, unchangedStock2);
Expand Down

0 comments on commit e65fcf7

Please sign in to comment.