Create test cases to cover funds modifications, covering faulty behaviour
This commit is contained in:
+46
-1
@@ -40,6 +40,18 @@ public class FundsIntegrationTest {
|
|||||||
this.responseSpec = new ResponseSpecBuilder().build();
|
this.responseSpec = new ResponseSpecBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateFaultyFund() {
|
||||||
|
FundsHelper fh = FundsHelper
|
||||||
|
.create(Utils.randomNameGenerator("", 120))
|
||||||
|
.externalId(Utils.randomNameGenerator("fund-", 120))
|
||||||
|
.build();
|
||||||
|
String jsonData = fh.toJSON();
|
||||||
|
|
||||||
|
final Long fundID = createFund(jsonData, this.requestSpec, this.responseSpec);
|
||||||
|
Assert.assertNull(fundID);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRetrieveFund() {
|
public void testRetrieveFund() {
|
||||||
FundsHelper fh = FundsHelper
|
FundsHelper fh = FundsHelper
|
||||||
@@ -82,10 +94,43 @@ public class FundsIntegrationTest {
|
|||||||
assertEquals(map.get("userMessageGlobalisationCode"), "error.msg.resource.not.found");
|
assertEquals(map.get("userMessageGlobalisationCode"), "error.msg.resource.not.found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateFund() {
|
||||||
|
FundsHelper fh = FundsHelper
|
||||||
|
.create(Utils.randomNameGenerator("", 10))
|
||||||
|
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||||
|
.build();
|
||||||
|
String jsonData = fh.toJSON();
|
||||||
|
|
||||||
|
final Long fundID = createFund(jsonData, this.requestSpec, this.responseSpec);
|
||||||
|
Assert.assertNotNull(fundID);
|
||||||
|
|
||||||
|
String newName = Utils.randomNameGenerator("", 10);
|
||||||
|
String newExternalId = Utils.randomNameGenerator("fund-", 5);
|
||||||
|
FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, newName, newExternalId, this.requestSpec, this.responseSpec);
|
||||||
|
|
||||||
|
Assert.assertEquals(newName, fh2.getName());
|
||||||
|
Assert.assertNull(fh2.getExternalId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateUnknownFund() {
|
||||||
|
String newName = Utils.randomNameGenerator("", 10);
|
||||||
|
String newExternalId = Utils.randomNameGenerator("fund-", 5);
|
||||||
|
FundsHelper fh = FundsResourceHandler.updateFund(Long.MAX_VALUE, newName, newExternalId, this.requestSpec, this.responseSpec);
|
||||||
|
Assert.assertNull(fh);
|
||||||
|
}
|
||||||
|
|
||||||
private Long createFund(final String fundJSON,
|
private Long createFund(final String fundJSON,
|
||||||
final RequestSpecification requestSpec,
|
final RequestSpecification requestSpec,
|
||||||
final ResponseSpecification responseSpec) {
|
final ResponseSpecification responseSpec) {
|
||||||
return new Long(String.valueOf(FundsResourceHandler.createFund(fundJSON, requestSpec, responseSpec)));
|
String fundId = String.valueOf(FundsResourceHandler.createFund(fundJSON, requestSpec, responseSpec));
|
||||||
|
if (fundId.equals("null")) {
|
||||||
|
// Invalid JSON data parameters
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Long(fundId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-3
@@ -29,7 +29,7 @@ public class FundsResourceHandler {
|
|||||||
final ResponseSpecification responseSpec) {
|
final ResponseSpecification responseSpec) {
|
||||||
final String URL = FUNDS_URL + "?" + Utils.TENANT_IDENTIFIER;
|
final String URL = FUNDS_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||||
List<HashMap<String, Object>> list = Utils.performServerGet(requestSpec, responseSpec, URL, "");
|
List<HashMap<String, Object>> list = Utils.performServerGet(requestSpec, responseSpec, URL, "");
|
||||||
String jsonData = new Gson().toJson(list);
|
final String jsonData = new Gson().toJson(list);
|
||||||
return new Gson().fromJson(jsonData, new TypeToken<List<FundsHelper>>(){}.getType());
|
return new Gson().fromJson(jsonData, new TypeToken<List<FundsHelper>>(){}.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,8 +37,29 @@ public class FundsResourceHandler {
|
|||||||
final RequestSpecification requestSpec,
|
final RequestSpecification requestSpec,
|
||||||
final ResponseSpecification responseSpec) {
|
final ResponseSpecification responseSpec) {
|
||||||
final String URL = FUNDS_URL + "/" + fundID + "?" + Utils.TENANT_IDENTIFIER;
|
final String URL = FUNDS_URL + "/" + fundID + "?" + Utils.TENANT_IDENTIFIER;
|
||||||
HashMap map = Utils.performServerGet(requestSpec, responseSpec, URL, "");
|
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "");
|
||||||
return new Gson().toJson(map);
|
return new Gson().toJson(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FundsHelper updateFund(final Long fundID,
|
||||||
|
final String newName,
|
||||||
|
final String newExternalId,
|
||||||
|
final RequestSpecification requestSpec,
|
||||||
|
final ResponseSpecification responseSpec) {
|
||||||
|
final HashMap<String, String> map = new HashMap<>();
|
||||||
|
if (!newName.isEmpty()) {
|
||||||
|
map.put("name", newName);
|
||||||
|
} else if (!newExternalId.isEmpty()) {
|
||||||
|
// to test that the externalId cannot be updated
|
||||||
|
map.put("externalId", newExternalId);
|
||||||
|
}
|
||||||
|
|
||||||
|
String updateJSON = new Gson().toJson(map);
|
||||||
|
|
||||||
|
final String URL = FUNDS_URL + "/" + fundID + "?" + Utils.TENANT_IDENTIFIER;
|
||||||
|
final HashMap<String, String> response = Utils.performServerPut(requestSpec, responseSpec, URL, updateJSON, "changes");
|
||||||
|
final String jsonData = new Gson().toJson(response);
|
||||||
|
return new Gson().fromJson(jsonData, FundsHelper.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user