}
@Test
public void testCreateSubscriptionApi() {
Api newApi = newApi();
String apiID = "Subscription"+(new Random().nextLong());
newApi.setId(apiID);
newApi.setNotificationFormat(NotificationFormat.HEADER);
// Testing we can't have NotificationFormat tag on Non Notification type APIs
BasicResponse response = given()
.contentType("application/xml")
.body(newApi, ObjectMapper.JAXB)
.expect()
.statusCode(500)
//.rootPath("response")
//.body("status", equalTo("SUCCESS"))
//.body("id", notNullValue())
.log().ifError()
.when()
.post("")
.andReturn()
.as(BasicResponse.class, ObjectMapper.JAXB);
Assert.assertNotNull("No error message", response.getError());
Assert.assertNotNull("No error message", response.getError().getErrorText());
Assert.assertTrue("Wrong errorMsg value", response.getError().getErrorText().contains("can't have NotificationFormat"));
// Testing Wrong : Subscription + Notification Format
newApi.setSubscriptionStep(SubscriptionStep.SUBSCRIPTION);
response = given()
.contentType("application/xml")
.body(newApi, ObjectMapper.JAXB)
.expect()
.statusCode(500)
//.rootPath("response")
//.body("status", equalTo("SUCCESS"))
//.body("id", notNullValue())
.log().ifError()
.when()
.post("")
.andReturn()
.as(BasicResponse.class, ObjectMapper.JAXB);
Assert.assertNotNull("No error message", response.getError());
Assert.assertNotNull("No error message", response.getError().getErrorText());
Assert.assertTrue("Wrong errorMsg value", response.getError().getErrorText().contains("can't have a NotificationFormat in Subscription step mode"));
// Testing Wrong : Notification + NotificationFormat + Target hosts
newApi.setSubscriptionStep(SubscriptionStep.NOTIFICATION);
response = given()
.contentType("application/xml")
.body(newApi, ObjectMapper.JAXB)
.expect()
.statusCode(500)
//.rootPath("response")
//.body("status", equalTo("SUCCESS"))
//.body("id", notNullValue())
.log().ifError()
.when()
.post("")
.andReturn()
.as(BasicResponse.class, ObjectMapper.JAXB);
Assert.assertNotNull("No error message", response.getError());
Assert.assertNotNull("No error message", response.getError().getErrorText());
Assert.assertTrue("Wrong errorMsg value", response.getError().getErrorText().contains("Notification step can't have any target host"));
// Testing Wrong : Notification - NotificationFormat - TargetHost
for (ApiContext apiCtx : newApi.getContexts())
apiCtx.setTargetHosts(null);
newApi.setNotificationFormat(null);
response = given()
.contentType("application/xml")
.body(newApi, ObjectMapper.JAXB)
.expect()
.statusCode(500)
//.rootPath("response")
//.body("status", equalTo("SUCCESS"))
//.body("id", notNullValue())
.log().ifError()
.when()
.post("")
.andReturn()
.as(BasicResponse.class, ObjectMapper.JAXB);
Assert.assertNotNull("No error message", response.getError());
Assert.assertNotNull("No error message", response.getError().getErrorText());
Assert.assertTrue("Wrong errorMsg value", response.getError().getErrorText().contains("Notification must have a NotificationFormat"));
// SUCCESS : Notification + NotificationFormat - TargetHost
newApi.setNotificationFormat(NotificationFormat.HEADER);
response = given()
.contentType("application/xml")
.body(newApi, ObjectMapper.JAXB)
.expect()
.statusCode(200)
.rootPath("response")
.body("status", equalTo("SUCCESS"))
.body("id", notNullValue())
.body("id", equalTo(newApi.getId()))
.log().ifError()
.when()
.post("")
.andReturn()
.as(BasicResponse.class, ObjectMapper.JAXB);