Search in sources :

Example 6 with RegexBody

use of org.mockserver.model.RegexBody in project policies-ui-backend by RedHatInsights.

the class TestLifecycleManager method mockEngine.

private void mockEngine() {
    mockServerClient.when(request().withPath("/hawkular/alerts/triggers/c49e92c4-dead-beef-9200-245b31933e94/enable").withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(500).withReasonPhrase("Internal server error").withHeader("Content-Type", "application/json").withBody("{ \"errorMessage\" : \"something went wrong\" }"));
    // -------------------------------
    List<Trigger> triggers = new ArrayList<>();
    Trigger trigger = new Trigger();
    trigger.id = "bd0ee2ec-eec0-44a6-8bb1-29c4179fc21c";
    trigger.lifecycle = new ArrayList<>();
    Map<String, Object> ev = new HashMap<>();
    Calendar cal = getInstance();
    cal.set(2020, MAY, 8, 10, 0, 0);
    ev.put("status", "ALERT_GENERATE");
    ev.put("stime", cal.getTimeInMillis());
    trigger.lifecycle.add(ev);
    ev = new HashMap<>();
    cal.set(2020, MAY, 9, 10, 0, 0);
    ev.put("status", "ALERT_GENERATE");
    ev.put("stime", cal.getTimeInMillis());
    trigger.lifecycle.add(ev);
    ev = new HashMap<>();
    cal.set(2020, MAY, 10, 10, 0, 0);
    ev.put("status", "ALERT_GENERATE");
    ev.put("stime", cal.getTimeInMillis());
    trigger.lifecycle.add(ev);
    triggers.add(trigger);
    mockServerClient.when(request().withPath("/hawkular/alerts/triggers").withQueryStringParameter("triggerIds", "bd0ee2ec-eec0-44a6-8bb1-29c4179fc21c").withHeader("Hawkular-Tenant", "1234").withMethod("GET")).respond(response().withStatusCode(200).withHeader("Content-Type", "application/json").withBody(JsonBody.json(triggers)));
    // -------------------------------
    FullTrigger ft = new FullTrigger();
    ft.trigger.id = "00000000-0000-0000-0000-000000000001";
    JsonBody ftBody = JsonBody.json(ft);
    mockServerClient.when(request().withPath("/hawkular/alerts/triggers/trigger/00000000-0000-0000-0000-000000000001").withMethod("GET")).respond(response().withStatusCode(200).withHeader("Content-Type", "application/json").withBody(ftBody));
    mockServerClient.when(request().withPath("/hawkular/alerts/triggers/.*/enable").withMethod("PUT")).respond(response().withStatusCode(200));
    mockServerClient.when(request().withPath("/hawkular/alerts/triggers/.*/enable").withMethod("DELETE")).respond(response().withStatusCode(200));
    // Simulate internal engine issue
    mockServerClient.when(request().withPath("/hawkular/alerts/triggers/trigger").withBody(new RegexBody(".*-dead-beef-9200-.*")).withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(500).withHeader("Content-Type", "application/json").withBody("{ \"msg\" : \"ok\" }"));
    // ------------ status page
    mockServerClient.when(request().withPath("/hawkular/alerts/triggers").withQueryStringParameter("triggerIds", "dummy").withHeader("Hawkular-Tenant", "dummy")).respond(response().withStatusCode(200).withHeader("Content-Type", "application/json").withBody("[]"));
    mockServerClient.when(request().withPath("/apps")).respond(response().withBody("[]").withHeader("Content-Type", "application/json").withStatusCode(200));
    // ------------
    mockServerClient.when(request().withPath("/hawkular/alerts/triggers/trigger").withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(200).withHeader("Content-Type", "application/json").withBody("{ \"msg\" : \"ok\" }"));
    mockServerClient.when(request().withPath("/hawkular/alerts/triggers/c49e92c4-dead-beef-9200-245b31933e94").withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(500).withHeader("Content-Type", "application/json").withBody("{ \"errorMessage\" : \"something went wrong\" }"));
    mockServerClient.when(request().withPath("/hawkular/alerts/triggers/c49e92c4-764c-4163-9200-245b31933e94").withMethod("DELETE").withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(404).withHeader("Content-Type", "application/json").withBody("{ \"errorMessage\" : \"does not exist\" }"));
    mockServerClient.when(request().withPath("/hawkular/alerts/triggers/.*").withMethod("DELETE").withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(200).withHeader("Content-Type", "application/json").withBody("{ \"msg\" : \"ok\" }"));
    mockServerClient.when(request().withPath("/hawkular/alerts/triggers/trigger/.*").withMethod("PUT").withHeader("Hawkular-Tenant", "1234")).respond(response().withStatusCode(200).withHeader("Content-Type", "application/json").withBody("{ \"msg\" : \"ok\" }"));
}
Also used : HashMap(java.util.HashMap) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) FullTrigger(com.redhat.cloud.policies.app.model.engine.FullTrigger) JsonBody(org.mockserver.model.JsonBody) RegexBody(org.mockserver.model.RegexBody) FullTrigger(com.redhat.cloud.policies.app.model.engine.FullTrigger) Trigger(com.redhat.cloud.policies.app.model.engine.Trigger)

Aggregations

RegexBody (org.mockserver.model.RegexBody)6 Test (org.junit.Test)5 FullTrigger (com.redhat.cloud.policies.app.model.engine.FullTrigger)1 Trigger (com.redhat.cloud.policies.app.model.engine.Trigger)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 JsonBody (org.mockserver.model.JsonBody)1