use of org.mockserver.model.JsonBody in project strimzi by strimzi.
the class MockCruiseControl method setupCCBrokerDoesNotExist.
/**
* Setup broker doesn't exist error for add/remove broker response.
*/
public static void setupCCBrokerDoesNotExist(ClientAndServer ccServer, CruiseControlEndpoints endpoint) throws IOException, URISyntaxException {
// Add/remove broker response with no goal that returns an error
JsonBody jsonError = getJsonFromResource("CC-Broker-not-exist.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)).respond(response().withStatusCode(500).withBody(jsonError).withHeaders(header(CruiseControlApi.CC_REST_API_USER_ID_HEADER, BROKERS_NOT_EXIST_ERROR_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
}
use of org.mockserver.model.JsonBody in project strimzi 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));
}
use of org.mockserver.model.JsonBody in project strimzi-kafka-operator by strimzi.
the class MockCruiseControl method setupCCRebalanceBadGoalsError.
/**
* Setup responses for various bad goal configurations possible on a rebalance request.
*/
public static void setupCCRebalanceBadGoalsError(ClientAndServer ccServer, CruiseControlEndpoints endpoint) throws IOException, URISyntaxException {
// Response if the user has set custom goals which do not include all configured hard.goals
JsonBody jsonError = getJsonFromResource("CC-Rebalance-bad-goals-error.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(Parameter.param(CruiseControlParameters.GOALS.key, ".+")).withQueryStringParameter(Parameter.param(CruiseControlParameters.SKIP_HARD_GOAL_CHECK.key, "false")).withPath(endpoint.path).withHeader(AUTH_HEADER).withSecure(true)).respond(response().withBody(jsonError).withHeaders(header("User-Task-ID", REBALANCE_NO_GOALS_RESPONSE_UTID)).withStatusCode(500).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
// Response if the user has set custom goals which do not include all configured hard.goals
// Note: This uses the no-goals example response but the difference between custom goals and default goals is not tested here
JsonBody jsonSummary = 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|false")).withQueryStringParameter(Parameter.param(CruiseControlParameters.GOALS.key, ".+")).withQueryStringParameter(Parameter.param(CruiseControlParameters.SKIP_HARD_GOAL_CHECK.key, "true")).withPath(endpoint.path).withHeader(AUTH_HEADER).withSecure(true)).respond(response().withBody(jsonSummary).withHeaders(header("User-Task-ID", REBALANCE_NO_GOALS_RESPONSE_UTID)).withStatusCode(200).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
}
use of org.mockserver.model.JsonBody in project mockserver by mock-server.
the class JsonBodyDTOTest method shouldReturnValuesSetInConstructor.
@Test
public void shouldReturnValuesSetInConstructor() {
// when
JsonBodyDTO jsonBody = new JsonBodyDTO(new JsonBody("some_body"));
// then
assertThat(jsonBody.getJson(), is("some_body"));
assertThat(jsonBody.getType(), is(Body.Type.JSON));
assertThat(jsonBody.getMatchType(), is(ONLY_MATCHING_FIELDS));
assertThat(jsonBody.getContentType(), is("application/json; charset=utf-8"));
}
use of org.mockserver.model.JsonBody in project mockserver by mock-server.
the class JsonBodyDTOTest method shouldBuildCorrectObjectWithMatchTypeAndCharset.
@Test
public void shouldBuildCorrectObjectWithMatchTypeAndCharset() {
// when
JsonBody jsonBody = new JsonBodyDTO(new JsonBody("some_body", null, MediaType.create("application", "json").withCharset(StandardCharsets.UTF_16), STRICT)).buildObject();
// then
assertThat(jsonBody.getValue(), is("some_body"));
assertThat(jsonBody.getType(), is(Body.Type.JSON));
assertThat(jsonBody.getMatchType(), is(STRICT));
assertThat(jsonBody.getContentType(), is("application/json; charset=utf-16"));
assertThat(jsonBody.getRawBytes(), is("some_body".getBytes(StandardCharsets.UTF_16)));
}
Aggregations