diff --git a/cukes-core/src/main/java/lv/ctco/cukes/core/api/CoreSteps.java b/cukes-core/src/main/java/lv/ctco/cukes/core/api/CoreSteps.java
new file mode 100644
index 00000000..b365c2a3
--- /dev/null
+++ b/cukes-core/src/main/java/lv/ctco/cukes/core/api/CoreSteps.java
@@ -0,0 +1,93 @@
+package lv.ctco.cukes.core.api;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import cucumber.api.java.en.And;
+import lv.ctco.cukes.core.CukesDocs;
+import lv.ctco.cukes.core.facade.RandomGeneratorFacade;
+import lv.ctco.cukes.core.facade.VariableFacade;
+import lv.ctco.cukes.core.internal.context.InflateContext;
+import org.apache.commons.lang3.RandomStringUtils;
+
+import java.text.SimpleDateFormat;
+
+@Singleton
+@InflateContext
+public class CoreSteps {
+
+ @Inject
+ private VariableFacade variableFacade;
+ @Inject
+ private RandomGeneratorFacade randomGeneratorFacade;
+
+ @And("^variable \"([^\"]+)\" is \"([^\"]+)\"$")
+ @CukesDocs("Assigns value to the variable")
+ public void createVariableSetToValue(String varName, String value) {
+ this.variableFacade.setVariable(varName, value);
+ }
+
+ @And("^variable \"([^\"]+)\" is random UUID$")
+ @CukesDocs("Generates random UUID and assigns it to a variable")
+ public void createVariableSetToRandomUUID(String varName) {
+ this.variableFacade.setUUIDToVariable(varName);
+ }
+
+ @And("^variable \"(\\S+)\" is random password by matching pattern \"([Aa0]+)\"$")
+ @CukesDocs("Generates random password by given pattern. Pattern may contain symbils a,A,0. " +
+ "So A is replaced with random capital letter, a - with random letter and 0 - with random number")
+ public void createVariableSetToRandomPasswordByPattern(String variableName, String pattern) {
+ this.variableFacade.setVariable(variableName, this.randomGeneratorFacade.byPattern(pattern));
+ }
+
+ @And("^variable \"(\\S+)\" is random password with length (\\d+)$")
+ @CukesDocs("Generates random password with given length")
+ public void createVariableSetToRandomPasswordByLength(String variableName, int length) {
+ this.variableFacade.setVariable(variableName, this.randomGeneratorFacade.withLength(length));
+ }
+
+ @And("^variable \"([^\"]+)\" is current timestamp$")
+ @CukesDocs("Assigns current timestamp to a variable")
+ public void createVariableSetToCurrentTimestamp(String varName) {
+ this.variableFacade.setCurrentTimestampToVariable(varName);
+ }
+
+ @And("^variable \"([^\"]+)\" is current time in format \"([^\"]+)\"$")
+ @CukesDocs("Assigns current timestamp in a defined format to a variable")
+ public void createVariableSetToTodayDate(String varName, String format) {
+ String value = new SimpleDateFormat(format).format(System.currentTimeMillis());
+ this.variableFacade.setVariable(varName, value);
+ }
+
+ @And("^variable \"([^\"]+)\" is \"([^\"]*)\" with (\\d+) random characters?$")
+ @CukesDocs("Generates random character line of required length and adds it to a variable value")
+ public void createVariableSetToValueWithRandomCharsPostfix(String varName, String value, int length) {
+ value += this.randomGeneratorFacade.withLength(length);
+ this.variableFacade.setVariable(varName, value);
+ }
+
+ @And("^variable \"([^\"]+)\" is \"([^\"]*)\" with (\\d+) chars? long random string$")
+ @CukesDocs("Generates random alphabetic character line of required length and adds it to a variable value")
+ public void createVariableSetToValueWithRandomStringPostfix(String varName, String value, int length) {
+ value += RandomStringUtils.randomAlphabetic(length);
+ this.variableFacade.setVariable(varName, value);
+ }
+
+ @And("^variable \"([^\"]+)\" is \"([^\"]*)\" with (\\d+) digits? long random number$")
+ @CukesDocs("Generates random digit line of required length and adds it to a variable value")
+ public void createVariableSetToValueWithRandomNumberPostfix(String varName, String value, int length) {
+ value += RandomStringUtils.randomNumeric(length);
+ this.variableFacade.setVariable(varName, value);
+ }
+
+ @And("^variable \"([^\"]+)\" is \"([^\"]*)\" set to lower case$")
+ @CukesDocs("Assigns value set to lower case to the variable")
+ public void createVariableSetToLowerCase(String varName, String value) {
+ this.variableFacade.setVariable(varName, value.toLowerCase());
+ }
+
+ @And("^variable \"([^\"]+)\" is \"([^\"]*)\" set to upper case$")
+ @CukesDocs("Assigns value set to upper case to the variable")
+ public void createVariableSetToUpperCase(String varName, String value) {
+ this.variableFacade.setVariable(varName, value.toUpperCase());
+ }
+}
diff --git a/cukes-http/pom.xml b/cukes-http/pom.xml
index 33b4a918..e89a2a03 100644
--- a/cukes-http/pom.xml
+++ b/cukes-http/pom.xml
@@ -37,6 +37,13 @@
awaitility
1.7.0
+
+
+
+ org.assertj
+ assertj-core
+ 3.8.0
+
diff --git a/cukes-http/src/main/java/lv/ctco/cukes/http/HttpMethod.java b/cukes-http/src/main/java/lv/ctco/cukes/http/HttpMethod.java
index 97a8238a..74d38b61 100644
--- a/cukes-http/src/main/java/lv/ctco/cukes/http/HttpMethod.java
+++ b/cukes-http/src/main/java/lv/ctco/cukes/http/HttpMethod.java
@@ -31,6 +31,6 @@ public Response doRequest(RequestSpecification when, String url) {
case HEAD: return when.head(url);
case PATCH: return when.patch(url);
}
- throw new CukesRuntimeException("This Http Method is nos supported");
+ throw new CukesRuntimeException("This Http Method is not supported");
}
}
diff --git a/cukes-http/src/main/java/lv/ctco/cukes/http/api/HttpSteps.java b/cukes-http/src/main/java/lv/ctco/cukes/http/api/HttpSteps.java
new file mode 100644
index 00000000..0de101fb
--- /dev/null
+++ b/cukes-http/src/main/java/lv/ctco/cukes/http/api/HttpSteps.java
@@ -0,0 +1,216 @@
+package lv.ctco.cukes.http.api;
+
+import com.google.inject.Inject;
+import cucumber.api.java.en.And;
+import cucumber.api.java.en.Then;
+import groovy.lang.Singleton;
+import groovy.util.logging.Slf4j;
+import io.restassured.http.ContentType;
+import io.restassured.response.Response;
+import lv.ctco.cukes.core.CukesDocs;
+import lv.ctco.cukes.core.internal.context.ContextInflater;
+import lv.ctco.cukes.core.internal.context.GlobalWorldFacade;
+import lv.ctco.cukes.core.internal.context.InflateContext;
+import lv.ctco.cukes.http.facade.HttpAssertionFacade;
+import lv.ctco.cukes.http.facade.HttpRequestFacade;
+import lv.ctco.cukes.http.facade.HttpResponseFacade;
+import lv.ctco.cukes.http.json.JsonParser;
+import org.assertj.core.api.SoftAssertions;
+import org.junit.Assert;
+
+import java.util.List;
+import java.util.Map;
+
+@Singleton
+@Slf4j
+@InflateContext
+public class HttpSteps {
+
+ @Inject
+ private HttpRequestFacade httpRequestFacade;
+ @Inject
+ private HttpResponseFacade httpResponseFacade;
+ @Inject
+ private HttpAssertionFacade httpAssertionFacade;
+ @Inject
+ private JsonParser jsonParser;
+ @Inject
+ private ContextInflater inflater;
+ @Inject
+ private GlobalWorldFacade world;
+
+
+ @And("^HTTP response (header|property) \"([^\"]+)\" value is saved to variable \"([^\"]+)\"$")
+ @CukesDocs("Save response property or header value to variable")
+ public void saveHttpResponseHeaderToAVariable(String headerOrProperty, String attributeName, String varName) {
+ if (headerOrProperty.equals("header")) {
+ httpAssertionFacade.varAssignedFromHeader(varName, attributeName);
+ } else {
+ httpAssertionFacade.varAssignedFromProperty(varName, attributeName);
+ }
+ }
+
+ @And("^variable \"([^\"]+)\" is HTTP response (header|property) \"([^\"]+)\" value$")
+ @CukesDocs("Save response property or header value to variable")
+ public void setVariableToHttpResponseHeaderValue(String varName, String headerOrProperty, String attributeName) {
+ if (headerOrProperty.equals("header")) {
+ httpAssertionFacade.varAssignedFromHeader(varName, attributeName);
+ } else {
+ httpAssertionFacade.varAssignedFromProperty(varName, attributeName);
+ }
+ }
+
+ @And("^HTTP content type is \"([^\"]+)\"$")
+ @CukesDocs("Setup content type for http request")
+ public void setContentType(String contentType) {
+ httpRequestFacade.contentType(contentType);
+ }
+
+ @And("^HTTP content type is (ANY|TEXT|JSON|XML|HTML|URLENC|BINARY)$")
+ @CukesDocs("Select content type for http request")
+ public void setContentTypeJson(ContentType contentType) {
+ httpRequestFacade.contentType(contentType.toString());
+ }
+
+ @And("^HTTP \"(GET|POST|PUT|DELETE|OPTIONS|HEAD|PATCH)\" request is sent to \"(.+)\"$")
+ @CukesDocs("Send http request")
+ public void performHttpRequest(String httpMethod, String url) throws Throwable {
+ httpResponseFacade.setResponsePrefix("");
+ httpResponseFacade.doRequest(httpMethod, url);
+ }
+
+ //ASSERT
+ @Then("^HTTP response status code should( not|) be (\\d+)$")
+ @CukesDocs("Check http response status code")
+ public void checkHttpRsponseStatusCode(String condition, int expectedStatusCode) {
+ int actualStatusCode = httpResponseFacade.response().statusCode();
+ boolean shouldBeEqual = condition.isEmpty();
+ boolean isEqual = actualStatusCode == expectedStatusCode;
+ Assert.assertTrue(
+ "Status code should" + condition + " be " + expectedStatusCode + " but was " + actualStatusCode +
+ "\nAnd response body is:\n" + httpResponseFacade.response().body().prettyPrint(),
+ isEqual == shouldBeEqual);
+ }
+
+ @Then("^HTTP response property \"([^\"]+)\" value should( not|) be equal to \"([^\"]*)\"$")
+ @CukesDocs("Check http response property")
+ public void checkHttpResponsePropertyEquals(String path, String condition, String value) {
+ boolean shouldBeEqual = condition.isEmpty();
+ if (shouldBeEqual) {
+ httpAssertionFacade.bodyContainsPathWithValue(path, value);
+ } else {
+ httpAssertionFacade.bodyContainsPathWithOtherValue(path, value);
+ }
+ }
+
+ @Then("^HTTP response header \"([^\"]+)\" value should( not|) be equal to \"([^\"]+)\"$")
+ @CukesDocs("Check http response header")
+ public void checkHttpResponseHeaderEquals(String headerName, String condition, String value) {
+ boolean shouldBeEqual = condition.isEmpty();
+ if (shouldBeEqual) {
+ httpAssertionFacade.headerContains(headerName, value);
+ } else {
+ httpAssertionFacade.headerDoesNotContain(headerName, value);
+ }
+ }
+
+ @Then("^HTTP response should contain properties from json:$")
+ @CukesDocs("Check http response contains properties from certain json")
+ public void checkHttpResponseContainsProperty(String json) {
+// httpAssertionFacade.bodyContainsPropertiesFromJson(json);
+ Response response = httpResponseFacade.response();
+ SoftAssertions softly = new SoftAssertions();
+ Map stringStringMap = jsonParser.parsePathToValueMap(json);
+ for (Map.Entry entry : stringStringMap.entrySet()) {
+ String path = entry.getKey();
+ String expectedValue = entry.getValue();
+ Object actualValue = response.body().path(path);
+ softly
+ .assertThat(actualValue)
+ .as("Value of property by path '%s'", path)
+ .isEqualTo(expectedValue);
+ }
+ if(!softly.wasSuccess()) {
+ softly.fail("Response was: \n" + response.body().prettyPrint());
+ }
+ softly.assertAll();
+ }
+
+ @Then("^HTTP response properties should match:$")
+ @CukesDocs("Check http response contains properties from table")
+ public void checkHttpResponsePropertiesMatch(List