Package org.chenile.cucumber.rest
Class RestCukesSteps
java.lang.Object
org.chenile.cucumber.rest.RestCukesSteps
Cucumber steps to facilitate running tests using Spring MOCK MVC.
These steps are generic since they leverage the scripting language and JSON PATH etc. that are supported by Spring MVC.
See the methods below for the precise Gherkin language that has been created.
These steps are generic since they leverage the scripting language and JSON PATH etc. that are supported by Spring MVC.
See the methods below for the precise Gherkin language that has been created.
-
Field Summary
Modifier and TypeFieldDescription(package private) CukesContext
private MockMvc
private ObjectMapper
Uses a variable to store the results of a scenario so that it can be used in the next scenario.
For example, if we create an entity and want to retrieve the same entity by ID, then we can store the ID as a variable in the varMap. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
a_REST_exception_is_thrown_with_message
(String exceptionMessage) void
void
a_REST_exception_is_thrown_with_param_number_value
(Integer pos, String message) void
a_REST_exception_is_thrown_with_status_and_message_code
(Integer errCode, Integer subErrCode) void
a_REST_warning_must_be_thrown_that_says_with_code
(String warningMessage, Integer errorNum) void
a_REST_warning_must_be_thrown_that_says_with_code_and_http_status
(String warningMessage, Integer subErrorCode, Integer httpStatus) void
void
void
a_warning_must_be_thrown_that_has_field
(String fieldValue) void
before()
private GenericResponse<?>
private String
void
i_construct_a_REST_request_with_header_and_value
(String headerName, String headerValue) void
i_DELETE_A_REST_Request_To_URL_With_Payload
(String url, String docString) void
void
i_PATCH_a_REST_request_to_URL
(String url, String docString) void
i_POST_REST_request_with_payload
(String url, String docString) void
i_PUT_a_REST_request_to_URL
(String url, String docString) private void
invokeHTTPMethod
(HttpMethod method, String url, String docString) void
store_from_response_to
(String expression, String varName) private String
void
void
Check if the success inGenericResponse
is truevoid
that_varName_equals_varValue
(String varName, String varValue) void
check if the number of errors returned match the expected valuevoid
the_http_status_code_is
(Integer statusCode) Check status codes.void
the_REST_response_contains_key
(String string) void
void
void
the_REST_response_key_is
(String key, String value) void
the_top_level_code_is
(Integer code) void
the_top_level_description_is
(String description) void
void
theRESTResponseKeyContainsString
(String key, String value)
-
Field Details
-
mvc
-
objectMapper
-
context
CukesContext context -
varMap
Uses a variable to store the results of a scenario so that it can be used in the next scenario.
For example, if we create an entity and want to retrieve the same entity by ID, then we can store the ID as a variable in the varMap. We can use the ID to retrieve the object back in the next scenario
varMap spans scenarios and hence needs to be stored outside the context.
-
-
Constructor Details
-
RestCukesSteps
public RestCukesSteps()
-
-
Method Details
-
before
public void before() -
i_construct_a_REST_request_with_header_and_value
@When("I construct a REST request with header {string} and value {string}") public void i_construct_a_REST_request_with_header_and_value(String headerName, String headerValue) throws Exception - Throws:
Exception
-
i_POST_REST_request_with_payload
@When("I POST a REST request to URL {string} with payload") public void i_POST_REST_request_with_payload(String url, String docString) throws Exception - Throws:
Exception
-
i_DELETE_A_REST_Request_To_URL_With_Payload
@When("I DELETE a REST request to URL {string} with payload") public void i_DELETE_A_REST_Request_To_URL_With_Payload(String url, String docString) throws Exception - Throws:
Exception
-
i_GET_a_REST_request_to_URL
@When("I GET a REST request to URL {string}") public void i_GET_a_REST_request_to_URL(String url) throws Exception - Throws:
Exception
-
i_PUT_a_REST_request_to_URL
@When("I PUT a REST request to URL {string} with payload") public void i_PUT_a_REST_request_to_URL(String url, String docString) throws Exception - Throws:
Exception
-
i_PATCH_a_REST_request_to_URL
@When("I PATCH a REST request to URL {string} with payload") public void i_PATCH_a_REST_request_to_URL(String url, String docString) throws Exception - Throws:
Exception
-
invokeHTTPMethod
- Throws:
Exception
-
the_http_status_code_is
@Then("the http status code is {int}") public void the_http_status_code_is(Integer statusCode) throws Exception Check status codes.- Parameters:
statusCode
- check if the status code matches the passed one.- Throws:
Exception
- in case there is an error in interacting with the REST service.
-
success_is_true
Check if the success inGenericResponse
is true- Throws:
Exception
- if there is an error in retrieving the results
-
success_is_false
- Throws:
Exception
-
the_REST_response_is_null
- Throws:
Exception
-
the_REST_response_contains_key
@Then("the REST response contains key {string}") public void the_REST_response_contains_key(String string) throws Exception - Throws:
Exception
-
the_REST_response_key_is
@Then("the REST response key {string} is {string}") public void the_REST_response_key_is(String key, String value) throws Exception - Throws:
Exception
-
theRESTResponseKeyContainsString
@And("the REST response key {string} contains string {string}") public void theRESTResponseKeyContainsString(String key, String value) throws Exception - Throws:
Exception
-
the_REST_response_does_not_contain_key
@Then("the REST response does not contain key {string}") public void the_REST_response_does_not_contain_key(String key) throws Exception - Throws:
Exception
-
the_error_array_size_is
@Then("the error array size is {int}") public void the_error_array_size_is(Integer size) throws Exception check if the number of errors returned match the expected value- Throws:
Exception
-
the_top_level_code_is
@Then("the top level code is {int}") public void the_top_level_code_is(Integer code) throws Exception - Throws:
Exception
-
the_top_level_subErrorCode_is
@Then("the top level subErrorCode is {int}") public void the_top_level_subErrorCode_is(Integer code) throws Exception - Throws:
Exception
-
the_top_level_description_is
@Then("the top level description is {string}") public void the_top_level_description_is(String description) throws Exception - Throws:
Exception
-
a_REST_warning_must_be_thrown_that_says_with_code
@Then("a REST warning must be thrown that says {string} with code {int}") public void a_REST_warning_must_be_thrown_that_says_with_code(String warningMessage, Integer errorNum) throws Exception - Throws:
Exception
-
a_REST_warning_must_be_thrown_that_says_with_code_and_http_status
@Then("a REST warning must be thrown that says {string} with code {int} and http status {int}") public void a_REST_warning_must_be_thrown_that_says_with_code_and_http_status(String warningMessage, Integer subErrorCode, Integer httpStatus) throws Exception - Throws:
Exception
-
a_REST_warning_must_be_thrown_with_code
@Then("a REST warning must be thrown with code {int}") public void a_REST_warning_must_be_thrown_with_code(Integer errorNum) throws Exception - Throws:
Exception
-
a_REST_warning_must_be_thrown_with_param_number_value
@Then("a REST warning must be thrown with param number {int} value {string}") public void a_REST_warning_must_be_thrown_with_param_number_value(Integer pos, String message) throws Exception - Throws:
Exception
-
a_warning_must_be_thrown_that_has_field
@Then("a REST warning must be thrown that has field {string}") public void a_warning_must_be_thrown_that_has_field(String fieldValue) throws Exception - Throws:
Exception
-
a_REST_exception_is_thrown_with_status_and_message_code
@Then("a REST exception is thrown with status {int} and message code {int}") public void a_REST_exception_is_thrown_with_status_and_message_code(Integer errCode, Integer subErrCode) throws Exception - Throws:
Exception
-
a_REST_exception_is_thrown_with_message_code
@Then("a REST exception is thrown with message code {int}") public void a_REST_exception_is_thrown_with_message_code(Integer errorCode) throws Exception - Throws:
Exception
-
a_REST_exception_is_thrown_with_param_number_value
@Then("a REST exception is thrown with param number {int} value {string}") public void a_REST_exception_is_thrown_with_param_number_value(Integer pos, String message) throws Exception - Throws:
Exception
-
a_REST_exception_is_thrown_with_message
@Then("a REST exception is thrown with message {string}") public void a_REST_exception_is_thrown_with_message(String exceptionMessage) throws Exception - Throws:
Exception
-
extractGenericResponse
- Throws:
Exception
-
extractStringFromResponse
- Throws:
Exception
-
store_from_response_to
@Then("store {string} from response to {string}") public void store_from_response_to(String expression, String varName) throws Exception - Throws:
Exception
-
substituteVariables
-
that_varName_equals_varValue
-