Office Integration Office Modification

This commit is contained in:
Anthony Liu
2015-01-15 01:53:05 -05:00
parent f477a190a7
commit a7ddb1a70f
3 changed files with 210 additions and 2 deletions
@@ -0,0 +1,52 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.integrationtests;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mifosplatform.integrationtests.common.OfficeDomain;
import org.mifosplatform.integrationtests.common.OfficeHelper;
import org.mifosplatform.integrationtests.common.Utils;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.builder.ResponseSpecBuilder;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
public class OfficeIntegrationTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
@Before
public void setup() {
Utils.initializeRESTAssured();
this.requestSpec = new RequestSpecBuilder().setContentType(
ContentType.JSON).build();
this.requestSpec
.header("Authorization",
"Basic "
+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
.build();
}
@Test
public void testOfficeModification() {
OfficeHelper oh = new OfficeHelper(requestSpec, responseSpec);
int officeId = oh.createOffice("01 July 2007");
OfficeDomain oldOffice = oh.retrieveOfficeByID(officeId);
oh.updateOffice(officeId, Utils.randomNameGenerator("New_Office_", 4),
"02 July 2007");
OfficeDomain newOffice = oh.retrieveOfficeByID(officeId);
Assert.assertTrue(oldOffice.getName().equals(newOffice.getName()));
Assert.assertTrue(oldOffice.getOpeningDate().equals(
newOffice.getOpeningDate()));
}
}
@@ -0,0 +1,140 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.mifosplatform.integrationtests.common;
import com.google.gson.Gson;
public class OfficeDomain {
public static class Builder {
private int id;
private String name;
private String nameDecorated;
private String externalId;
private String[] openingDate;
private String hierarchy;
private Builder(final int id, final String name,
final String nameDecorated, final String externalId,
final String[] openingDate, final String hierarchy) {
this.id = id;
this.name = name;
this.nameDecorated = nameDecorated;
this.externalId = externalId;
this.openingDate = openingDate;
this.hierarchy = hierarchy;
}
public OfficeDomain build() {
return new OfficeDomain(this.id, this.name, this.nameDecorated,
this.externalId, this.openingDate, this.hierarchy);
}
}
private int id;
private String name;
private String nameDecorated;
private String externalId;
private String[] openingDate;
private String hierarchy;
OfficeDomain() {
super();
}
private OfficeDomain(final int id, final String name,
final String nameDecorated, final String externalId,
final String[] openingDate, final String hierarchy) {
super();
this.id = id;
this.name = name;
this.nameDecorated = nameDecorated;
this.externalId = externalId;
this.openingDate = openingDate;
this.hierarchy = hierarchy;
}
public String toJSON() {
return new Gson().toJson(this);
}
public static OfficeDomain fromJSON(final String jsonData) {
return new Gson().fromJson(jsonData, OfficeDomain.class);
}
public static Builder create(final int id, final String name,
final String nameDecorated, final String externalId,
final String[] openingDate, final String hierarchy) {
return new Builder(id, name, nameDecorated, externalId, openingDate,
hierarchy);
}
public int getId() {
return this.id;
}
public String getName() {
return this.name;
}
public String getNameDecorated() {
return this.nameDecorated;
}
public String getExternalId() {
return this.externalId;
}
public String[] getOpeningDate() {
return this.openingDate;
}
public String getHierarchy() {
return this.hierarchy;
}
@Override
public int hashCode() {
int hash = 1;
if (this.id > 0)
hash += this.id;
if (this.name != null)
hash += this.name.hashCode();
if (this.nameDecorated != null)
hash += this.nameDecorated.hashCode();
if (this.externalId != null)
hash += this.externalId.hashCode();
if (this.openingDate != null)
hash += this.openingDate.hashCode();
if (this.hierarchy != null)
hash += this.hierarchy.hashCode();
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof OfficeDomain))
return false;
OfficeDomain od = (OfficeDomain) obj;
if (this.id == od.getId() && this.name.equals(od.getName())
&& this.nameDecorated.equals(od.getName())
&& this.externalId.equals(od.getExternalId())
&& this.openingDate.equals(od.getOpeningDate())
&& this.hierarchy.equals(od.getHierarchy()))
return true;
return false;
}
}
@@ -7,11 +7,11 @@ package org.mifosplatform.integrationtests.common;
import java.util.HashMap;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
public class OfficeHelper {
private static final String OFFICE_URL = "/mifosng-provider/api/v1/offices";
@@ -23,13 +23,29 @@ public class OfficeHelper {
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 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);
System.out.println("map : " + map);
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");