Center Integration Retrieval

This commit is contained in:
Anthony Liu
2015-01-04 02:24:21 -05:00
parent f5aa3f88e9
commit f082ac40a6
5 changed files with 80 additions and 16 deletions
@@ -6,6 +6,8 @@
package org.mifosplatform.integrationtests;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import org.junit.Assert;
@@ -46,6 +48,7 @@ public class CenterIntegrationTest {
int resourceId = CenterHelper.createCenter(name, officeId, requestSpec, responseSpec);
CenterDomain center = CenterHelper.retrieveByID(resourceId, requestSpec, responseSpec);
Assert.assertNotNull(center);
Assert.assertTrue(center.getName().equals(name));
Assert.assertTrue(center.getOfficeId() == officeId);
Assert.assertTrue(center.isActive() == false);
@@ -76,10 +79,50 @@ public class CenterIntegrationTest {
int resourceId = CenterHelper.createCenter(name, officeId, externalId, staffId, groupMembers, requestSpec, responseSpec);
CenterDomain center = CenterHelper.retrieveByID(resourceId, requestSpec, responseSpec);
Assert.assertNotNull(center);
Assert.assertTrue(center.getName().equals(name));
Assert.assertTrue(center.getOfficeId() == officeId);
Assert.assertTrue(center.getExternalId().equals(externalId));
Assert.assertTrue(center.getStaffId() == staffId);
Assert.assertTrue(center.isActive() == false);
int[] groupMemberList = new int[center.getGroupMembers().size()];
for (int i = 0; i < groupMemberList.length; i++) {
groupMemberList[i] = ((Double) center.getGroupMembers().get(i).get("id")).intValue();
}
Assert.assertArrayEquals(groupMemberList, groupMembers);
}
@Test
public void testListCenters() {
ArrayList<CenterDomain> paginatedList = CenterHelper.paginatedListCenters(requestSpec, responseSpec);
ArrayList<CenterDomain> list = CenterHelper.listCenters(requestSpec, responseSpec);
Assert.assertNotNull(paginatedList);
Assert.assertNotNull(list);
Assert.assertTrue(Arrays.equals(paginatedList.toArray(new CenterDomain[paginatedList.size()]),
list.toArray(new CenterDomain[list.size()])));
}
@Test
public void testCenterRetrieval() {
int id = CenterHelper.listCenters(requestSpec, responseSpec).get(0).getId();
Assert.assertTrue(id > 0);
CenterDomain center = CenterHelper.retrieveByID(id, requestSpec, responseSpec);
Assert.assertNotNull(center);
Assert.assertNotNull(center.getName());
Assert.assertNotNull(center.getHierarchy());
Assert.assertNotNull(center.getOfficeName());
}
@Test
public void testVoidCenterRetrieval() {
ArrayList<CenterDomain> arr = CenterHelper.listCenters(requestSpec, responseSpec);
int id = arr.get(arr.size() - 1).getId() + 1;
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(404).build();
CenterDomain center = CenterHelper.retrieveByID(id, requestSpec, responseSpec);
Assert.assertNotNull(center);
}
}
@@ -10,7 +10,6 @@ import java.util.Collections;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mifosplatform.integrationtests.common.CurrenciesHelper;
import org.mifosplatform.integrationtests.common.CurrencyDomain;
@@ -52,8 +51,6 @@ public class CurrenciesTest {
}
@Test
// TODO: fix failing test case
@Ignore
public void testUpdateCurrencySelection() {
// Test updation
@@ -5,6 +5,7 @@
*/
package org.mifosplatform.integrationtests.common;
import java.util.ArrayList;
import java.util.HashMap;
import com.google.gson.Gson;
@@ -22,10 +23,11 @@ public class CenterDomain {
private int officeId;
private String officeName;
private String hierarchy;
private ArrayList<HashMap> groupMembers;
private Builder(final int id, final int statusid, final String statuscode, final String statusvalue, final boolean active,
final String name, final String externalId, final int staffId, final int officeID, final String officeName,
final String hierarchy) {
final String hierarchy, final ArrayList<HashMap> groupMembers) {
this.id = id;
this.status = new HashMap();
this.status.put("id", statusid);
@@ -38,12 +40,13 @@ public class CenterDomain {
this.officeId = officeID;
this.officeName = officeName;
this.hierarchy = hierarchy;
this.groupMembers = groupMembers;
}
public CenterDomain build() {
return new CenterDomain(this.id, (int) this.status.get("id"), (String) this.status.get("code"),
(String) this.status.get("value"), this.active, this.name, this.externalId, this.staffId, this.officeId,
this.officeName, this.hierarchy);
this.officeName, this.hierarchy, groupMembers);
}
}
@@ -56,6 +59,7 @@ public class CenterDomain {
private int officeId;
private String officeName;
private String hierarchy;
private ArrayList<HashMap> groupMembers;
CenterDomain() {
super();
@@ -63,7 +67,7 @@ public class CenterDomain {
private CenterDomain(final int id, final int statusid, final String statuscode, final String statusvalue, final boolean active,
final String name, final String externalId, final int staffId, final int officeID, final String officeName,
final String hierarchy) {
final String hierarchy, final ArrayList<HashMap> groupMembers) {
this.id = id;
this.status = new HashMap();
this.status.put("id", statusid);
@@ -76,6 +80,7 @@ public class CenterDomain {
this.officeId = officeID;
this.officeName = officeName;
this.hierarchy = hierarchy;
this.groupMembers = groupMembers;
}
public String toJSON() {
@@ -88,8 +93,9 @@ public class CenterDomain {
public static Builder create(final int id, final int statusid, final String statuscode, final String statusvalue, final boolean active,
final String name, final String externalId, final int staffId, final int officeID, final String officeName,
final String hierarchy) {
return new Builder(id, statusid, statuscode, statusvalue, active, name, externalId, staffId, officeID, officeName, hierarchy);
final String hierarchy, final ArrayList<HashMap> groupMembers) {
return new Builder(id, statusid, statuscode, statusvalue, active, name, externalId, staffId, officeID, officeName, hierarchy,
groupMembers);
}
public String getExternalId() {
@@ -128,13 +134,17 @@ public class CenterDomain {
return this.hierarchy;
}
public ArrayList<HashMap> getGroupMembers() {
return this.groupMembers;
}
@Override
public int hashCode() {
int hash = 1;
if (this.id >= 0) hash += this.id;
if (this.status != null) {
if ((int) this.status.get("id") >= 0) hash += (int) this.status.get("id");
if ((Double) this.status.get("id") >= 0) hash += (Double) this.status.get("id");
if ((String) this.status.get("code") != null) hash += this.status.get("code").hashCode();
if ((String) this.status.get("value") != null) hash += this.status.get("value").hashCode();
}
@@ -142,6 +152,7 @@ public class CenterDomain {
if (this.officeId >= 0) hash += this.officeId;
if (this.officeName != null) hash += this.officeName.hashCode();
if (this.hierarchy != null) hash += this.hierarchy.hashCode();
if (this.groupMembers != null) hash += this.groupMembers.hashCode();
return hash;
}
@@ -5,6 +5,7 @@
*/
package org.mifosplatform.integrationtests.common;
import java.util.ArrayList;
import java.util.HashMap;
import com.google.common.reflect.TypeToken;
@@ -18,13 +19,27 @@ public class CenterHelper {
private static final String CENTERS_URL = "/mifosng-provider/api/v1/centers";
public static CenterDomain retrieveByID(int id, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
final String GET_CENTER_BY_ID_URL = CENTERS_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER;
final String GET_CENTER_BY_ID_URL = CENTERS_URL + "/" + id + "?associations=groupMembers&" + Utils.TENANT_IDENTIFIER;
System.out.println("------------------------ RETRIEVING CENTER AT " + id + "-------------------------");
final String jsonData = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, GET_CENTER_BY_ID_URL, ""));
System.out.print(jsonData);
return new Gson().fromJson(jsonData, new TypeToken<CenterDomain>() {}.getType());
}
public static ArrayList<CenterDomain> paginatedListCenters(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) {
final String GET_CENTER = CENTERS_URL + "?paged=true&" + Utils.TENANT_IDENTIFIER;
System.out.println("------------------------ RETRIEVING CENTERS-------------------------");
final String jsonData = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, GET_CENTER, "pageItems"));
return new Gson().fromJson(jsonData, new TypeToken<ArrayList<CenterDomain>>() {}.getType());
}
public static ArrayList<CenterDomain> listCenters(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
final String GET_CENTER = CENTERS_URL + "?" + Utils.TENANT_IDENTIFIER;
System.out.println("------------------------ RETRIEVING CENTERS-------------------------");
final String jsonData = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, GET_CENTER, ""));
return new Gson().fromJson(jsonData, new TypeToken<ArrayList<CenterDomain>>() {}.getType());
}
public static int createCenter(final String name, final int officeId, final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) {
return createCenter(name, officeId, null, -1, null, null, requestSpec, responseSpec);
@@ -52,15 +52,13 @@ public class CurrenciesHelper {
final ResponseSpecification responseSpec, final ArrayList<String> currencies) {
final String CURRENCIES_UPDATE_URL = CURRENCIES_URL + "?" + Utils.TENANT_IDENTIFIER;
System.out.println("---------------------------------UPDATE SELECTED CURRENCIES LIST---------------------------------------------");
return (ArrayList<String>) Utils.performServerPut(requestSpec, responseSpec, CURRENCIES_UPDATE_URL, currenciesToJSON(currencies),
"currencies");
HashMap hash = Utils.performServerPut(requestSpec, responseSpec, CURRENCIES_UPDATE_URL, currenciesToJSON(currencies), "changes");
return (ArrayList<String>) hash.get("currencies");
}
private static String currenciesToJSON(final ArrayList<String> currencies) {
HashMap map = new HashMap<>();
for (String e : currencies) {
map.put("currencies", e);
}
map.put("currencies", currencies);
System.out.println("map : " + map);
return new Gson().toJson(map);
}