Skip to content

Commit

Permalink
Merge pull request #16 from lucasponce/REST-UI-TESTS
Browse files Browse the repository at this point in the history
Fix for REST endpoint
  • Loading branch information
lucasponce committed Feb 16, 2015
2 parents b6c2c47 + 7a07f5d commit 3671345
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void findAllNotifiersByType(@Suspended final AsyncResponse response,
responseClass = "Map<String, Strin>",
notes = "Notifier properties are variable and depends on the notifier type. " +
"A user needs to request previously NotifierType API to get the list of properties to fill " +
"for a specific type. All notifier should have notifierId and NotifierType as mandatory " +
"for a specific type. All notifier should have NotifierId and NotifierType as mandatory " +
"properties")
public void createNotifier(@Suspended final AsyncResponse response,
@ApiParam(value = "Notifier properties. Properties depend of specific NotifierType.",
Expand Down Expand Up @@ -191,7 +191,7 @@ public void getNotifier(@Suspended final AsyncResponse response,
responseClass = "void",
notes = "Notifier properties are variable and depends on the notifier type. " +
"A user needs to request previously NotifierType API to get the list of properties to fill " +
"for a specific type. All notifier should have notifierId and NotifierType as mandatory " +
"for a specific type. All notifier should have NotifierId and NotifierType as mandatory " +
"properties")
public void updateNotifier(@Suspended final AsyncResponse response,
@ApiParam(value = "Notifier id to be updated",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -159,27 +160,30 @@ public void getTrigger(@Suspended final AsyncResponse response,
@Path("/{triggerId}/conditions")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Get a map with all conditions id an specific trigger.",
responseClass = "Map<String, String>",
notes = "This is a helper for the UI to get all id of the conditions with specific type ")
responseClass = "Collection<Map<String, String>>",
notes = "This is a helper for the UI to get all id of the conditions with specific type. " +
"It returns a collection of {conditionId: \"value\", className: \"value\" }")
public void getTriggerConditions(@Suspended final AsyncResponse response,
@ApiParam(value = "Trigger definition id to be retrieved",
required = true)
@PathParam("triggerId") final String triggerId) {
try {
Collection<Condition> conditionsList = definitions.getConditions(triggerId);
Map<String, String> conditionsType = new HashMap<String, String>();

Collection<Map<String, String>> conditions = new ArrayList<>();
for (Condition cond : conditionsList) {
conditionsType.put(cond.getConditionId(), cond.getClass().getSimpleName());
Map<String, String> conditionsType = new HashMap<String, String>();
conditionsType.put("conditionId", cond.getConditionId());
conditionsType.put("className", cond.getClass().getSimpleName());
conditions.add(conditionsType);
}
if (conditionsType.isEmpty()) {
if (conditions.isEmpty()) {
log.debugf("GET - getTriggerConditions - Empty");
response.resume(Response.status(Response.Status.NO_CONTENT).type(APPLICATION_JSON_TYPE).build());
} else {
log.debugf("GET - getTriggerConditions - %s conditions ", conditionsType.size());
log.debugf("GET - getTriggerConditions - %s conditions ", conditions.size());

response.resume(Response.status(Response.Status.OK)
.entity(conditionsType).type(APPLICATION_JSON_TYPE).build());
.entity(conditions).type(APPLICATION_JSON_TYPE).build());
}
} catch (Exception e) {
log.debugf(e.getMessage(), e);
Expand All @@ -188,10 +192,8 @@ public void getTriggerConditions(@Suspended final AsyncResponse response,
response.resume(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(errors).type(APPLICATION_JSON_TYPE).build());
}

}


@PUT
@Path("/{triggerId}")
@Consumes(APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* Copyright 2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.alerts.rest

import org.hawkular.alerts.api.model.trigger.Trigger
import org.jboss.logging.Logger
import org.junit.Test

import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue

/**
* These tests are intended to reproduce scenarios based on UI flows.
*
* Alerts UI should have two main areas:
* - Dashboard == queries about specific alerts
* - Definitions == CRUD operations about Triggers/Conditions/Dampenings/Notifiers
*
* A Trigger definition, from UI perspective can have:
* - Specific properties for the trigger definition itself.
* - A maximum of 4 conditions associated with it.
* - Dampening informacion.
* - A list of notifiers associated with this definition.
*
* @author Lucas Ponce
*/
class FlowUITest extends AbstractTestBase {
private static final Logger log = Logger.getLogger(FlowUITest.class);

String getRESTPrefix(String conditionClass) {
if (conditionClass == null && conditionClass.isEmpty()) return ""

if (conditionClass.equals("AvailabilityCondition")) {
return "conditions/availability"
} else if (conditionClass.equals("CompareCondition")) {
return "conditions/compare"
} else if (conditionClass.equals("StringCondition")) {
return "conditions/string"
} else if (conditionClass.equals("ThresholdCondition")) {
return "conditions/threshold"
} else if (conditionClass.equals("ThresholdRangeCondition")) {
return "conditions/range"
} else {
return ""
}
}

@Test
void flowBrowseDefinitions() {
/*
Enter in the Alerts UI - Go the list of the triggers
*/
def resp = client.get(path: "triggers")
assertEquals(200, resp.status)

def triggers = resp.data
assert triggers.size() > 0

for (int i = 0; i < triggers.size(); i++) {
Trigger t = triggers[i]
log.info(t.toString())

/*
Get all conditions for a trigger
*/
resp = client.get(path: "triggers/" + t.getId() + "/conditions")
assertEquals(200, resp.status)
log.info("Conditions for " + t.getId());
def conditions = resp.data
for (int j = 0; j < conditions.size(); j++) {
def prefix = getRESTPrefix(conditions[j].className)
resp = client.get(path: prefix + "/" + conditions[j].conditionId);
assertEquals(200, resp.status)
def conditionsProperties = resp.data;
log.info("Condition: " + conditionsProperties)
}
/*
Get all dampenings for a trigger
*/
try {
resp = client.get(path: "trigger/dampening/" + t.getId())
def dampening = resp.data;
log.info("Dampening: " + dampening)
} catch (e) {
log.info("No dampening found")
}
/*
Get all notifiers for a trigger
*/
log.info("Notifiers: " + t.getNotifiers())
for (String notifierId : t.getNotifiers()) {
resp = client.get(path: "notifiers/" + notifierId)
def notifier = resp.data
log.info("Notifier: " + notifier)
}
}
}

}

0 comments on commit 3671345

Please sign in to comment.