* TODO: Need to be check why.
*/
@Test
public void testCreateAndGetAllApi() {
// GetAll step
BasicResponse response = given()
.contentType("application/xml")
.expect()
.statusCode(200)
.rootPath("response")
.body("status", equalTo("SUCCESS"))
.log().ifError()
.when()
.get("/")
.andReturn()
.as(BasicResponse.class, ObjectMapper.JAXB);
Assert.assertNotNull(response);
Assert.assertNotNull(response.getIds());
for(String idToDelete : response.getIds()) {
// Delete step
BasicResponse deleteResponse = given()
.contentType("application/xml")
.expect()
.statusCode(200)
.rootPath("response")
.body("status", equalTo("SUCCESS"))
.log().ifError()
.when()
.delete("/" + idToDelete)
.andReturn()
.as(BasicResponse.class, ObjectMapper.JAXB);
Assert.assertNotNull(deleteResponse);
Assert.assertEquals("SUCCESS", deleteResponse.getStatus());
}
List<String> createdApis = new ArrayList<String>();
Api data;
for(int i=0; i<2; i++) {
data = newApi();
String apiID = ""+(new Random().nextLong());
createdApis.add(apiID);
data.setId(apiID);
// Create step
BasicResponse createResponse = given()
.contentType("application/xml")
.body(data, ObjectMapper.JAXB)
.expect()
.statusCode(200)
.rootPath("response")
.body("status", equalTo("SUCCESS"))
.body("id", notNullValue())
.log().ifError()
.when()
.post("")
.andReturn()
.as(BasicResponse.class, ObjectMapper.JAXB);
String apiIDReturned = createResponse.getId();
Assert.assertNotNull(createResponse);
Assert.assertNotNull(apiIDReturned);
Assert.assertEquals(apiID, apiIDReturned);
Assert.assertEquals("SUCCESS", createResponse.getStatus());
}
// GetAll step
BasicResponse getAllResponse = given()
.contentType("application/xml")
.expect()
.statusCode(200)
.rootPath("response")
.body("status", equalTo("SUCCESS"))
.log().ifError()
.when()
.get("/")
.andReturn()
.as(BasicResponse.class, ObjectMapper.JAXB);
Assert.assertNotNull(getAllResponse);
Assert.assertNotNull(getAllResponse.getIds());
// sometimes other junits create apis
Assert.assertTrue(createdApis.size() <= getAllResponse.getIds().size());
for(int i=0; i<createdApis.size(); i++) {
String idReturned = createdApis.get(i);
Assert.assertTrue(getAllResponse.getIds().contains(idReturned));
}
}