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 SummaryFieldsModifier and TypeFieldDescription(package private) CukesContextprivate final ObjectMapperprivate Stringprivate IntegerUses 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 SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoida_REST_exception_is_thrown_with_message(String exceptionMessage) voidvoida_REST_exception_is_thrown_with_param_number_value(Integer pos, String message) voida_REST_exception_is_thrown_with_status_and_message_code(Integer errCode, Integer subErrCode) voida_REST_warning_must_be_thrown_that_says_with_code(String warningMessage, Integer errorNum) voida_REST_warning_must_be_thrown_that_says_with_code_and_http_status(String warningMessage, Integer subErrorCode, Integer httpStatus) voidvoidvoida_warning_must_be_thrown_that_has_field(String fieldValue) voidbefore()private GenericResponse<?>private Stringvoidi_construct_a_REST_request_with_header_and_value(String headerName, String headerValue) voidi_DELETE_REST_request_with_payload(String url, String docString) voidvoidi_PATCH_a_REST_request_to_URL(String url, String docString) voidi_POST_REST_request_with_payload(String url, String docString) voidi_PUT_a_REST_request_to_URL(String url, String docString) private voidinvokeHTTPMethod(io.restassured.http.Method method, String url, String docString) voidstore_from_response_to(String expression, String varName) private StringvoidvoidCheck if the success inGenericResponseis truevoidthat_varName_equals_varValue(String varName, String varValue) voidcheck if the number of errors returned match the expected valuevoidthe_http_status_code_is(Integer statusCode) Check status codes.voidthe_REST_response_contains_key(String string) voidvoidvoidthe_REST_response_key_is(String key, String value) voidthe_top_level_code_is(Integer code) voidthe_top_level_description_is(String description) voidvoidtheRESTResponseKeyContainsString(String key, String value) 
- 
Field Details- 
targetHost
- 
targetPort
- 
objectMapper
- 
contextCukesContext context
- 
varMapUses 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- 
RestCukesStepspublic RestCukesSteps()
 
- 
- 
Method Details- 
beforepublic 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_REST_request_with_payload@When("I DELETE a REST request to URL {string} with payload") public void i_DELETE_REST_request_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
 
- 
invokeHTTPMethodprivate void invokeHTTPMethod(io.restassured.http.Method method, String url, String docString) throws Exception - 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_trueCheck if the success inGenericResponseis 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
 
-