diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest new file mode 100644 index 000000000..118e6d854 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/OfficeIntegrationsTest @@ -0,0 +1,37 @@ +/** + * 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 static org.hamcrest.Matchers.*; +import static org.junit.Assert.assertEquals; + +import com.google.gson.Gson; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +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; + +import java.util.*; +public class OfficeIntegrationsTest { + + private ResponseSpecification statusOkResponseSpec; + 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.statusOkResponseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + } +} + diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/OfficeHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/OfficeHelper.java index 31562c2c5..1045343f7 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/OfficeHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/OfficeHelper.java @@ -3,7 +3,8 @@ * 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; +package org.mifosplatform.integrationtests.common.office; + import java.util.HashMap; diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper new file mode 100644 index 000000000..02368d7ea --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeHelper @@ -0,0 +1,103 @@ +package org.mifosplatform.integrationtests.common.office; + +import com.google.gson.Gson; + +public class OfficeHelper { + + public static class Builder { + + private String name; + private String externalId; + private Long id; + private String nameDecorated; + private int openingDate[] = new int[3]; + private String hierarchy; + + + private Builder(final String name) { + this.name = name; + } + + public Builder externalId(final String externalId) { + this.externalId = externalId; + return this; + } + + + public Builder nameDecorated(final String nameDecorated) { + this.nameDecorated = nameDecorated; + } + + public Builder openingDate(final int[] openingDate) { + this.openingDate = openingDate; + } + + public Builder hierarchy(final String hierarchy) { + this.hierarchy = hierarchy; + } + public OfficeHelper build() { + return new OfficeHelper(this.name, this.externalId, this.id, this.nameDecorated, this.openingDate, this.hierarchy); + } + + } + + + + private String name; + private String externalId; + private Long id; + private String nameDecorated; + + + OfficeHelper() { + super(); + } + + private OfficeHelper(final String name, final String externalId, final String nameDecorated, final String hierarchy, final int[] openingDate) { + super(); + this.name = name; + this.externalId = externalId; + this.nameDecorated = nameDecorated; + this.hierarchy = hierarchy; + this.openingDate = openingDate; + } + + + } + + public String toJSON() { + return new Gson().toJson(this); + } + + public static OfficeHelper fromJSON(final String jsonData) { + return new Gson().fromJson(jsonData, OfficeHelper.class); + } + + public String getName() { + return this.name; + } + + public Long getId() { + return this.id; + } + + public String getNameDecorated() + { return this.nameDecorated; } + + public String getHierarchy() + { return this.hierarchy; } + + + public String getExternalId() { + return this.externalId; + } + + public int openingDate() { + return this.openingDate; + } + + + +} + + diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler new file mode 100644 index 000000000..bc79caf88 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/office/OfficeResourceHandler @@ -0,0 +1,28 @@ +package org.mifosplatform.integrationtests.common.office; + +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; +import org.mifosplatform.integrationtests.common.Utils; + +import java.util.HashMap; +import java.util.List; + +public class OfficeResourceHandler { + + private static final String OFFICES_URL = "/mifosng-provider/api/v1/offices"; + private static final String CREATE_OFFICES_URL = OFFICES_URL + "?" + Utils.TENANT_IDENTIFIER; + + public static Integer createFund(final String fundJSON, + final RequestSpecification requestSpec, + final ResponseSpecification responseSpec) { + return Utils.performServerPost(requestSpec, responseSpec, CREATE_FUNDS_URL, fundJSON, "resourceId"); + } + + 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); + } +}