Search in sources :

Example 16 with JsonBody

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

the class MockCruiseControl method setupCCUserTasksCompletedWithError.

/**
 * Setup response of task completed with error.
 */
public static void setupCCUserTasksCompletedWithError(ClientAndServer ccServer) throws IOException, URISyntaxException {
    // This simulates asking for the status of a task that has Complete with error and fetch_completed_task=true
    JsonBody compWithErrorJson = getJsonFromResource("CC-User-task-status-completed-with-error.json");
    ccServer.when(request().withMethod("GET").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.FETCH_COMPLETE.key, "true")).withPath(CruiseControlEndpoints.USER_TASKS.path).withHeader(AUTH_HEADER).withSecure(true)).respond(response().withBody(compWithErrorJson).withStatusCode(200).withHeaders(header("User-Task-ID", USER_TASK_REBALANCE_NO_GOALS_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
}
Also used : JsonBody(org.mockserver.model.JsonBody)

Example 17 with JsonBody

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

the class MockCruiseControl method setupCCStateResponse.

/**
 * Setup state responses in mock server.
 */
public static void setupCCStateResponse(ClientAndServer ccServer) throws IOException, URISyntaxException {
    // Non-verbose response
    JsonBody jsonProposalNotReady = getJsonFromResource("CC-State-proposal-not-ready.json");
    ccServer.when(request().withMethod("GET").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true|false")).withQueryStringParameter(Parameter.param(CruiseControlParameters.VERBOSE.key, "true|false")).withPath(CruiseControlEndpoints.STATE.path).withHeaders(header(CruiseControlApi.CC_REST_API_USER_ID_HEADER, STATE_PROPOSAL_NOT_READY), AUTH_HEADER).withSecure(true)).respond(response().withBody(jsonProposalNotReady).withHeaders(header("User-Task-ID", STATE_PROPOSAL_NOT_READY_RESPONSE)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
    // Non-verbose response
    JsonBody json = getJsonFromResource("CC-State.json");
    ccServer.when(request().withMethod("GET").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.VERBOSE.key, "false")).withPath(CruiseControlEndpoints.STATE.path).withHeader(AUTH_HEADER).withSecure(true)).respond(response().withBody(json).withHeaders(header("User-Task-ID", "cruise-control-state")).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
    // Verbose response
    JsonBody jsonVerbose = getJsonFromResource("CC-State-verbose.json");
    ccServer.when(request().withMethod("GET").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")).withQueryStringParameter(Parameter.param(CruiseControlParameters.VERBOSE.key, "true")).withPath(CruiseControlEndpoints.STATE.path).withHeader(AUTH_HEADER).withSecure(true)).respond(response().withBody(jsonVerbose).withHeaders(header("User-Task-ID", "cruise-control-state-verbose")).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
}
Also used : JsonBody(org.mockserver.model.JsonBody)

Example 18 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, CruiseControlEndpoints endpoint) 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")).withQueryStringParameter(buildBrokerIdParameter(endpoint)).withPath(endpoint.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")).withQueryStringParameter(buildBrokerIdParameter(endpoint)).withPath(endpoint.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")).withQueryStringParameter(buildBrokerIdParameter(endpoint)).withPath(endpoint.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 19 with JsonBody

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

the class MockCruiseControl method setupCCStopResponse.

/**
 * Setup response of task being stopped.
 */
public static void setupCCStopResponse(ClientAndServer ccServer) throws IOException, URISyntaxException {
    JsonBody jsonStop = getJsonFromResource("CC-Stop.json");
    ccServer.when(request().withMethod("POST").withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true|false")).withPath(CruiseControlEndpoints.STOP.path).withHeader(AUTH_HEADER).withSecure(true)).respond(response().withBody(jsonStop).withHeaders(header("User-Task-ID", "stopped")).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
}
Also used : JsonBody(org.mockserver.model.JsonBody)

Example 20 with JsonBody

use of org.mockserver.model.JsonBody in project mockserver by mock-server.

the class JsonBodyDTOTest method shouldHandleEmptyByteArray.

@Test
public void shouldHandleEmptyByteArray() {
    // given
    String body = "";
    // when
    JsonBody jsonBody = new JsonBodyDTO(new JsonBody(body)).buildObject();
    // then
    assertThat(jsonBody.getValue(), is(""));
    assertThat(jsonBody.getType(), is(Body.Type.JSON));
}
Also used : JsonBody(org.mockserver.model.JsonBody) Test(org.junit.Test)

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