Search in sources :

Example 1 with JsonBody

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

the class MockCruiseControl method setupCCRebalanceNotEnoughDataError.

/**
 * Setup NotEnoughValidWindows error rebalance response.
 */
public static void setupCCRebalanceNotEnoughDataError(ClientAndServer ccServer) throws IOException, URISyntaxException {
    // Rebalance response with no goal that returns an error
    JsonBody jsonError = getJsonFromResource("CC-Rebalance-NotEnoughValidWindows-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")).withPath(CruiseControlEndpoints.REBALANCE.path).withHeader(AUTH_HEADER).withSecure(true)).respond(response().withStatusCode(500).withBody(jsonError).withHeaders(header(CruiseControlApi.CC_REST_API_USER_ID_HEADER, REBALANCE_NOT_ENOUGH_VALID_WINDOWS_ERROR_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
}
Also used : JsonBody(org.mockserver.model.JsonBody)

Example 2 with JsonBody

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) 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(CruiseControlEndpoints.REBALANCE.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(CruiseControlEndpoints.REBALANCE.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));
}
Also used : JsonBody(org.mockserver.model.JsonBody)

Example 3 with JsonBody

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) 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 4 with JsonBody

use of org.mockserver.model.JsonBody in project strimzi 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) 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(CruiseControlEndpoints.REBALANCE.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(CruiseControlEndpoints.REBALANCE.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));
}
Also used : JsonBody(org.mockserver.model.JsonBody)

Example 5 with JsonBody

use of org.mockserver.model.JsonBody in project strimzi by strimzi.

the class MockCruiseControl method setupCCRebalanceNotEnoughDataError.

/**
 * Setup NotEnoughValidWindows error rebalance response.
 */
public static void setupCCRebalanceNotEnoughDataError(ClientAndServer ccServer) throws IOException, URISyntaxException {
    // Rebalance response with no goal that returns an error
    JsonBody jsonError = getJsonFromResource("CC-Rebalance-NotEnoughValidWindows-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")).withPath(CruiseControlEndpoints.REBALANCE.path).withHeader(AUTH_HEADER).withSecure(true)).respond(response().withStatusCode(500).withBody(jsonError).withHeaders(header(CruiseControlApi.CC_REST_API_USER_ID_HEADER, REBALANCE_NOT_ENOUGH_VALID_WINDOWS_ERROR_RESPONSE_UTID)).withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC));
}
Also used : JsonBody(org.mockserver.model.JsonBody)

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