Add test cases for funds retrieval
This commit is contained in:
+52
-1
@@ -5,8 +5,15 @@
|
||||
*/
|
||||
package org.mifosplatform.integrationtests;
|
||||
|
||||
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 org.mifosplatform.integrationtests.common.funds.FundsHelper;
|
||||
import org.mifosplatform.integrationtests.common.funds.FundsResourceHandler;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
@@ -14,6 +21,10 @@ import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Funds Integration Test for checking Funds Application.
|
||||
*/
|
||||
@@ -27,7 +38,47 @@ public class FundsIntegrationTest {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.responseSpec = new ResponseSpecBuilder().build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveFund() {
|
||||
FundsHelper fh = FundsHelper.create(Utils.randomNameGenerator("", 10)).build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Integer fundID = createFund(jsonData, this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
|
||||
jsonData = FundsResourceHandler.retrieveFund(fundID, this.requestSpec, this.responseSpec);
|
||||
FundsHelper fh2 = FundsHelper.fromJSON(jsonData);
|
||||
|
||||
assertEquals(fh.getName(), fh2.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveAllFunds() {
|
||||
FundsHelper fh = FundsHelper.create(Utils.randomNameGenerator("", 10)).build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Integer fundID = createFund(jsonData, this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
|
||||
List<HashMap> list = FundsResourceHandler.retrieveAllFunds(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFundUnknown() {
|
||||
String jsonData = FundsResourceHandler.retrieveFund(Integer.MAX_VALUE, this.requestSpec, this.responseSpec);
|
||||
HashMap<String, String> map = new Gson().fromJson(jsonData, HashMap.class);
|
||||
assertEquals(map.get("userMessageGlobalisationCode"), "error.msg.resource.not.found");
|
||||
}
|
||||
|
||||
private Integer createFund(final String fundJSON,
|
||||
final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
System.out.println("------------------ CREATING NEW FUND ------------------");
|
||||
return FundsResourceHandler.createFund(fundJSON, requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-2
@@ -24,8 +24,9 @@ public class FundsHelper {
|
||||
}
|
||||
|
||||
private String name;
|
||||
private Integer resourceId;
|
||||
|
||||
FundsHelper() {
|
||||
public FundsHelper() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -38,6 +39,10 @@ public class FundsHelper {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Integer getResourceID() {
|
||||
return this.resourceId;
|
||||
}
|
||||
|
||||
public String toJSON() {
|
||||
return new Gson().toJson(this);
|
||||
}
|
||||
@@ -46,7 +51,7 @@ public class FundsHelper {
|
||||
return new Gson().fromJson(jsonData, FundsHelper.class);
|
||||
}
|
||||
|
||||
public Builder create(final String name) {
|
||||
public static Builder create(final String name) {
|
||||
return new Builder(name);
|
||||
}
|
||||
|
||||
|
||||
+26
@@ -5,11 +5,37 @@
|
||||
*/
|
||||
package org.mifosplatform.integrationtests.common.funds;
|
||||
|
||||
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 FundsResourceHandler {
|
||||
|
||||
private static final String FUNDS_URL = "/mifosng-provider/api/v1/funds";
|
||||
private static final String CREATE_FUNDS_URL = FUNDS_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 static List<HashMap> retrieveAllFunds(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String URL = FUNDS_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, URL, "");
|
||||
}
|
||||
|
||||
public static String retrieveFund(final Integer fundID,
|
||||
final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String URL = FUNDS_URL + "/" + fundID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
HashMap map = Utils.performServerGet(requestSpec, responseSpec, URL, "");
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user