Package org.rhq.modules.integrationTests.restApi.d

Examples of org.rhq.modules.integrationTests.restApi.d.AlertDefinition


    @Test
    public void testNewFullDefinition2() throws Exception {

        int definitionId = 0;
        try {
            AlertDefinition alertDefinition = new AlertDefinition();
            alertDefinition.setName("-x-test-full-definition");
            alertDefinition.setEnabled(false);
            alertDefinition.setPriority("HIGH");

            AlertNotification notification = new AlertNotification("Direct Emails");
            notification.getConfig().put("emailAddress","enoch@root.org");
            alertDefinition.getNotifications().add(notification);

            List<AlertCondition> conditions = alertDefinition.getConditions();

            AlertCondition condition = new AlertCondition("AVAILABILITY", "AVAIL_GOES_DOWN");
            conditions.add(condition);

            condition = new AlertCondition("AVAIL_DURATION","AVAIL_DURATION_DOWN");
            condition.setOption("300"); // seconds
            conditions.add(condition);

            AlertDefinition result =
            given()
                .contentType(ContentType.JSON)
                .header(acceptJson)
                .body(alertDefinition)
                .log().everything()
                .queryParam("resourceId", _platformId)
            .expect()
                .statusCode(201)
                .log().ifError()
            .when()
                .post("/alert/definitions")
            .as(AlertDefinition.class);

            assert result != null;
            definitionId = result.getId();

            int numberConditions = result.getConditions().size();
            assert numberConditions ==2 : "Expected 2 conditions but got " + numberConditions;
            assert result.getNotifications().size()==1;

            // Now retrieve the condition and notification individually

            given()
                .header(acceptJson)
                .pathParam("id",result.getNotifications().get(0).getId())
            .expect()
                .statusCode(200)
                .body("id",is(result.getNotifications().get(0).getId()))
                .body("senderName",is(result.getNotifications().get(0).getSenderName()))
                .log().ifError()
            .when()
                .get("/alert/notification/{id}");

            given()
                .header(acceptJson)
                .pathParam("id",result.getConditions().get(0).getId())
            .expect()
                .statusCode(200)
                .body("id",is(result.getConditions().get(0).getId()))
                .body("name",is(result.getConditions().get(0).getName()))
                .log().ifError()
            .when()
                .get("/alert/condition/{id}");

View Full Code Here


    @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)
View Full Code Here

    @Test
    public void testUpdateDefinition() throws Exception {

        int definitionId = createEmptyAlertDefinition(false);
        try {
            AlertDefinition definition =
            given()
                .header(acceptJson)
                .pathParam("did",definitionId)
            .expect()
                .statusCode(200)
            .when()
                .get("/alert/definition/{did}")
            .as(AlertDefinition.class);

            definition.setEnabled(true);
            definition.setDampeningCategory("ONCE");

            given()
                .contentType(ContentType.JSON)
                .header(acceptJson)
                .body(definition)
View Full Code Here

    @Test
    public void testUpdateDefinitionWithBadRecoveryId() throws Exception {

        int definitionId = createEmptyAlertDefinition(false);
        try {
            AlertDefinition definition =
            given()
                .header(acceptJson)
                .pathParam("did",definitionId)
            .expect()
                .statusCode(200)
            .when()
                .get("/alert/definition/{did}")
            .as(AlertDefinition.class);

            definition.setRecoveryId(43);

            given()
                .contentType(ContentType.XML)
                .header(acceptJson)
                .body(definition)
View Full Code Here

    public void testCreateDefinitionForResourceAndGroup() throws Exception {

        // This is supposed to fail, as we specify both a resource and a group
        // to work on

        AlertDefinition alertDefinition = new AlertDefinition();
        alertDefinition.setName("-x-test-definition");

        given()
            .header(acceptJson)
            .contentType(ContentType.JSON)
            .body(alertDefinition)
View Full Code Here

        int groupId = Integer.parseInt(groupUri.substring(groupUri.lastIndexOf("/")+1));

        int definitionId = 0;
        try {
            AlertDefinition alertDefinition = new AlertDefinition();
            alertDefinition.setName("-x-test-definition");

            alertDefinition =
            given()
                .header(acceptJson)
                .contentType(ContentType.JSON)
                .body(alertDefinition)
                .queryParam("groupId", groupId)
            .expect()
                .statusCode(201)
                .log().ifError()
            .when()
                .post("/alert/definitions")
            .as(AlertDefinition.class);

            definitionId = alertDefinition.getId();
        } finally {
            cleanupDefinition(definitionId);
            delete(groupUri);
        }
    }
View Full Code Here

    public void testCreateDefinitionForResourceType() throws Exception {

        // This is supposed to fail, as we specify both a resource and a group
        // to work on

        AlertDefinition alertDefinition = new AlertDefinition();
        alertDefinition.setName("-x-test-definition");

        AlertDefinition result =
        given()
            .header(acceptJson)
            .contentType(ContentType.JSON)
            .body(alertDefinition)
            .queryParam("resourceTypeId",_platformTypeId)
        .expect()
            .statusCode(201)
            .log().ifError()
        .when()
            .post("/alert/definitions")
        .as(AlertDefinition.class);

        cleanupDefinition(result.getId());
    }
View Full Code Here

        .when()
            .delete("/alert/definition/{id}");
    }

    private int createEmptyAlertDefinition(boolean enabled) {
        AlertDefinition alertDefinition = new AlertDefinition();
        alertDefinition.setName("-x-test-definition");
        alertDefinition.setEnabled(enabled);
        alertDefinition.setPriority("LOW");
        alertDefinition.setDampeningCategory("NONE");

        Response response =
        given()
            .header(acceptJson)
            .contentType(ContentType.JSON)
            .body(alertDefinition)
            .queryParam("resourceId", _platformId)
        .expect()
            .statusCode(201)
            .log().ifError()
        .when()
            .post("/alert/definitions");

        AlertDefinition result = response.as(AlertDefinition.class);

        assert result.getConditions()==null || result.getConditions().size()==0;

        return result.getId();
    }
View Full Code Here

TOP

Related Classes of org.rhq.modules.integrationTests.restApi.d.AlertDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.