Add test for duplicate creation

This commit is contained in:
Mohammed Nafees
2014-12-03 15:00:11 +05:30
parent eb8c7103ae
commit aaf7025d79
2 changed files with 22 additions and 14 deletions
@@ -37,7 +37,7 @@ public class FundsIntegrationTest {
Utils.initializeRESTAssured(); Utils.initializeRESTAssured();
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().build(); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
} }
@Test @Test
@@ -48,10 +48,25 @@ public class FundsIntegrationTest {
.build(); .build();
String jsonData = fh.toJSON(); String jsonData = fh.toJSON();
final Long fundID = createFund(jsonData, this.requestSpec, this.responseSpec); final Long fundID = createFund(jsonData, this.requestSpec, this.responseSpec.statusCode(400));
Assert.assertNull(fundID); Assert.assertNull(fundID);
} }
@Test
public void testDuplicates() {
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);
final Long fundID2 = createFund(jsonData, this.requestSpec, this.responseSpec.statusCode(403));
Assert.assertNull(fundID2);
}
@Test @Test
public void testRetrieveFund() { public void testRetrieveFund() {
FundsHelper fh = FundsHelper FundsHelper fh = FundsHelper
@@ -89,7 +104,7 @@ public class FundsIntegrationTest {
@Test @Test
public void testFundUnknown() { public void testFundUnknown() {
String jsonData = FundsResourceHandler.retrieveFund(Long.MAX_VALUE, this.requestSpec, this.responseSpec); String jsonData = FundsResourceHandler.retrieveFund(Long.MAX_VALUE, this.requestSpec, this.responseSpec.statusCode(404));
HashMap<String, String> map = new Gson().fromJson(jsonData, HashMap.class); HashMap<String, String> map = new Gson().fromJson(jsonData, HashMap.class);
assertEquals(map.get("userMessageGlobalisationCode"), "error.msg.resource.not.found"); assertEquals(map.get("userMessageGlobalisationCode"), "error.msg.resource.not.found");
} }
@@ -110,14 +125,14 @@ public class FundsIntegrationTest {
FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, newName, newExternalId, this.requestSpec, this.responseSpec); FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, newName, newExternalId, this.requestSpec, this.responseSpec);
Assert.assertEquals(newName, fh2.getName()); Assert.assertEquals(newName, fh2.getName());
Assert.assertNull(fh2.getExternalId()); Assert.assertEquals(newExternalId, fh2.getExternalId());
} }
@Test @Test
public void testUpdateUnknownFund() { public void testUpdateUnknownFund() {
String newName = Utils.randomNameGenerator("", 10); String newName = Utils.randomNameGenerator("", 10);
String newExternalId = Utils.randomNameGenerator("fund-", 5); String newExternalId = Utils.randomNameGenerator("fund-", 5);
FundsHelper fh = FundsResourceHandler.updateFund(Long.MAX_VALUE, newName, newExternalId, this.requestSpec, this.responseSpec); FundsHelper fh = FundsResourceHandler.updateFund(Long.MAX_VALUE, newName, newExternalId, this.requestSpec, this.responseSpec.statusCode(404));
Assert.assertNull(fh); Assert.assertNull(fh);
} }
@@ -46,15 +46,8 @@ public class FundsResourceHandler {
final String newExternalId, final String newExternalId,
final RequestSpecification requestSpec, final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) { final ResponseSpecification responseSpec) {
final HashMap<String, String> map = new HashMap<>(); FundsHelper fh = FundsHelper.create(newName).externalId(newExternalId).build();
if (!newName.isEmpty()) { String updateJSON = new Gson().toJson(fh);
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 String URL = FUNDS_URL + "/" + fundID + "?" + Utils.TENANT_IDENTIFIER;
final HashMap<String, String> response = Utils.performServerPut(requestSpec, responseSpec, URL, updateJSON, "changes"); final HashMap<String, String> response = Utils.performServerPut(requestSpec, responseSpec, URL, updateJSON, "changes");