Merge pull request #1257 from AJLiu/develop

Fixed Failing Test Case
This commit is contained in:
Vishwas Babu A J
2015-01-20 22:09:58 -08:00
2 changed files with 49 additions and 41 deletions
@@ -40,13 +40,14 @@ public class OfficeIntegrationTest {
public void testOfficeModification() {
OfficeHelper oh = new OfficeHelper(requestSpec, responseSpec);
int officeId = oh.createOffice("01 July 2007");
OfficeDomain oldOffice = oh.retrieveOfficeByID(officeId);
String name = Utils.randomNameGenerator("New_Office_", 4);
String date = "02 July 2007";
String[] dateArr = { "2007", "7", "2" };
oh.updateOffice(officeId, Utils.randomNameGenerator("New_Office_", 4),
"02 July 2007");
oh.updateOffice(officeId, name, date);
OfficeDomain newOffice = oh.retrieveOfficeByID(officeId);
Assert.assertTrue(oldOffice.getName().equals(newOffice.getName()));
Assert.assertTrue(oldOffice.getOpeningDate().equals(
newOffice.getOpeningDate()));
Assert.assertTrue(name.equals(newOffice.getName()));
Assert.assertArrayEquals(dateArr, newOffice.getOpeningDate());
}
}
@@ -14,46 +14,53 @@ import com.jayway.restassured.specification.ResponseSpecification;
public class OfficeHelper {
private static final String OFFICE_URL = "/mifosng-provider/api/v1/offices";
private final RequestSpecification requestSpec;
private final ResponseSpecification responseSpec;
private static final String OFFICE_URL = "/mifosng-provider/api/v1/offices";
private final RequestSpecification requestSpec;
private final ResponseSpecification responseSpec;
public OfficeHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
this.requestSpec = requestSpec;
this.responseSpec = responseSpec;
}
public OfficeHelper(final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) {
this.requestSpec = requestSpec;
this.responseSpec = responseSpec;
}
public OfficeDomain retrieveOfficeByID(int id) {
final String json = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, OFFICE_URL + "/" + id + "?"
+ Utils.TENANT_IDENTIFIER, ""));
return new Gson().fromJson(json, new TypeToken<OfficeDomain>() {}.getType());
}
public OfficeDomain retrieveOfficeByID(int id) {
final String json = new Gson().toJson(Utils.performServerGet(
requestSpec, responseSpec, OFFICE_URL + "/" + id + "?"
+ Utils.TENANT_IDENTIFIER, ""));
return new Gson().fromJson(json, new TypeToken<OfficeDomain>() {
}.getType());
}
public Integer createOffice(final String openingDate) {
String json = getAsJSON(openingDate);
return Utils.performServerPost(this.requestSpec, this.responseSpec, OFFICE_URL + "?" + Utils.TENANT_IDENTIFIER, json,
CommonConstants.RESPONSE_RESOURCE_ID);
}
public Integer createOffice(final String openingDate) {
String json = getAsJSON(openingDate);
return Utils.performServerPost(this.requestSpec, this.responseSpec,
OFFICE_URL + "?" + Utils.TENANT_IDENTIFIER, json,
CommonConstants.RESPONSE_RESOURCE_ID);
}
public Integer updateOffice(int id, String name, String openingDate) {
final HashMap map = new HashMap<>();
map.put("name", name);
map.put("openingDate", openingDate);
public Integer updateOffice(int id, String name, String openingDate) {
final HashMap map = new HashMap<>();
map.put("name", name);
map.put("dateFormat", "dd MMMM yyyy");
map.put("locale", "en");
map.put("openingDate", openingDate);
System.out.println("map : " + map);
System.out.println("map : " + map);
return Utils.performServerPut(requestSpec, responseSpec, OFFICE_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER,
new Gson().toJson(map), "resourceId");
}
return Utils.performServerPut(requestSpec, responseSpec, OFFICE_URL
+ "/" + id + "?" + Utils.TENANT_IDENTIFIER,
new Gson().toJson(map), "resourceId");
}
public static String getAsJSON(final String openingDate) {
final HashMap<String, String> map = new HashMap<>();
map.put("parentId", "1");
map.put("name", Utils.randomNameGenerator("Office_", 4));
map.put("dateFormat", "dd MMMM yyyy");
map.put("locale", "en");
map.put("openingDate", openingDate);
System.out.println("map : " + map);
return new Gson().toJson(map);
}
public static String getAsJSON(final String openingDate) {
final HashMap<String, String> map = new HashMap<>();
map.put("parentId", "1");
map.put("name", Utils.randomNameGenerator("Office_", 4));
map.put("dateFormat", "dd MMMM yyyy");
map.put("locale", "en");
map.put("openingDate", openingDate);
System.out.println("map : " + map);
return new Gson().toJson(map);
}
}