Search in sources :

Example 36 with JsonBody

use of org.mockserver.model.JsonBody in project strimzi-kafka-operator by strimzi.

the class MockCruiseControl method setupCCRebalanceResponse.

/**
 * Setup rebalance response.
 */
public static void setupCCRebalanceResponse(ClientAndServer ccServer, int pendingCalls, int responseDelay) throws IOException, URISyntaxException {
    // Rebalance in progress response with no goals set - non-verbose
    JsonBody pendingJson = getJsonFromResource("CC-Rebalance-no-goals-in-progress.json");
    ccServer.when(request().withMethod("POST").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.DRY_RUN.key, "true|false")).withQueryStringParameter(Parameter.param(CruiseControlParameters.VERBOSE.key, "true|false")).withPath(CruiseControlEndpoints.REBALANCE.path).withHeader(AUTH_HEADER).withSecure(true), Times.exactly(pendingCalls)).respond(response().withBody(pendingJson).withHeaders(header("User-Task-ID", REBALANCE_NO_GOALS_RESPONSE_UTID)).withStatusCode(202).withDelay(TimeUnit.SECONDS, responseDelay));
    // Rebalance response with no goals set - non-verbose
    JsonBody json = getJsonFromResource("CC-Rebalance-no-goals.json");
    ccServer.when(request().withMethod("POST").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.DRY_RUN.key, "true|false")).withQueryStringParameter(Parameter.param(CruiseControlParameters.VERBOSE.key, "false")).withPath(CruiseControlEndpoints.REBALANCE.path).withHeader(AUTH_HEADER).withSecure(true), Times.unlimited()).respond(response().withBody(json).withHeaders(header("User-Task-ID", REBALANCE_NO_GOALS_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, responseDelay));
    // Rebalance response with no goals set - verbose
    JsonBody jsonVerbose = getJsonFromResource("CC-Rebalance-no-goals-verbose.json");
    ccServer.when(request().withMethod("POST").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.DRY_RUN.key, "true|false")).withQueryStringParameter(Parameter.param(CruiseControlParameters.VERBOSE.key, "true")).withPath(CruiseControlEndpoints.REBALANCE.path).withHeader(AUTH_HEADER).withSecure(true)).respond(response().withBody(jsonVerbose).withHeaders(header("User-Task-ID", REBALANCE_NO_GOALS_VERBOSE_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, responseDelay));
}
Also used : JsonBody(org.mockserver.model.JsonBody)

Example 37 with JsonBody

use of org.mockserver.model.JsonBody 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

JsonBody (org.mockserver.model.JsonBody)37 Test (org.junit.Test)12 IOException (java.io.IOException)2 URI (java.net.URI)2 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 RegexBody (org.mockserver.model.RegexBody)1