Add test for duplicate creation
This commit is contained in:
+20
-5
@@ -37,7 +37,7 @@ public class FundsIntegrationTest {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().build();
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -48,10 +48,25 @@ public class FundsIntegrationTest {
|
||||
.build();
|
||||
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);
|
||||
}
|
||||
|
||||
@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
|
||||
public void testRetrieveFund() {
|
||||
FundsHelper fh = FundsHelper
|
||||
@@ -89,7 +104,7 @@ public class FundsIntegrationTest {
|
||||
|
||||
@Test
|
||||
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);
|
||||
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);
|
||||
|
||||
Assert.assertEquals(newName, fh2.getName());
|
||||
Assert.assertNull(fh2.getExternalId());
|
||||
Assert.assertEquals(newExternalId, 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);
|
||||
FundsHelper fh = FundsResourceHandler.updateFund(Long.MAX_VALUE, newName, newExternalId, this.requestSpec, this.responseSpec.statusCode(404));
|
||||
Assert.assertNull(fh);
|
||||
}
|
||||
|
||||
|
||||
+2
-9
@@ -46,15 +46,8 @@ public class FundsResourceHandler {
|
||||
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);
|
||||
FundsHelper fh = FundsHelper.create(newName).externalId(newExternalId).build();
|
||||
String updateJSON = new Gson().toJson(fh);
|
||||
|
||||
final String URL = FUNDS_URL + "/" + fundID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final HashMap<String, String> response = Utils.performServerPut(requestSpec, responseSpec, URL, updateJSON, "changes");
|
||||
|
||||
Reference in New Issue
Block a user