@Test
public void testNewFullDefinitionPlusRemovals() throws Exception {
int definitionId = 0;
try {
AlertDefinition alertDefinition = new AlertDefinition();
alertDefinition.setName("-x-test-full-definition2");
alertDefinition.setEnabled(false);
alertDefinition.setPriority("HIGH");
AlertNotification notification = new AlertNotification("Direct Emails");
notification.getConfig().put("emailAddress","enoch@root.org");
alertDefinition.getNotifications().add(notification);
AlertCondition condition = new AlertCondition("AVAILABILITY", "AVAIL_GOES_DOWN");
alertDefinition.getConditions().add(condition);
AlertDefinition result =
given()
.contentType(ContentType.JSON)
.header(acceptJson)
.body(alertDefinition)
.queryParam("resourceId", _platformId)
.expect()
.statusCode(201)
.body("priority", is("HIGH"))
.body("conditions", iterableWithSize(1))
.body("notifications", iterableWithSize(1))
.body("name", is("-x-test-full-definition2"))
.log().everything()
.when()
.post("/alert/definitions")
.as(AlertDefinition.class);
assert result != null;
definitionId = result.getId();
System.out.println("Definition id: " + definitionId);
// Now retrieve the condition and notification individually
given()
.header(acceptJson)
.pathParam("id",result.getNotifications().get(0).getId())
.expect()
.statusCode(204)
.log().ifError()
.when()
.delete("/alert/notification/{id}");
//retrieve definition again to see if notification is really gone
AlertDefinition result2 =
given()
.contentType(ContentType.JSON)
.header(acceptJson)
.pathParam("did", definitionId)
.queryParam("full", true)
.expect()
.statusCode(200)
.body("conditions", iterableWithSize(1))
.body("notifications", iterableWithSize(0))
.body("name",is("-x-test-full-definition2"))
.body("priority",is("HIGH"))
.log().everything()
.when()
.get("/alert/definition/{did}")
.as(AlertDefinition.class);
assert result2.getId() == result.getId();
// Now also remove the condition
int conditionId = result2.getConditions().get(0).getId(); //
System.out.println("Condition id " + conditionId + " result-> " + result.getConditions().get(0).getId());
given()
.header(acceptJson)