diff --git a/src/main/java/core/JsonUtils.java b/src/main/java/core/JsonUtils.java index ccbbd08330ffe29addff35b3be5f114cdd93f835..2bc24bde1aea336ed99ea2abf37f700241a11908 100644 --- a/src/main/java/core/JsonUtils.java +++ b/src/main/java/core/JsonUtils.java @@ -233,7 +233,15 @@ public class JsonUtils { * @return the uri */ public static String getTSAPolicy() { - return System.getProperty("baseUrl") + "/policy"; + return System.getProperty("baseUrl") + ":8081/policy"; + } + + /** + * Get the url for "TSA Cache" + * @return the uri + */ + public static String getTSACache() { + return System.getProperty("baseUrl") + ":8083/v1/cache"; } /** diff --git a/src/main/resources/REST/json/Cache.json b/src/main/resources/REST/json/Cache.json new file mode 100644 index 0000000000000000000000000000000000000000..3e6d6c88f6bd09741c5635abcba33ee950386e44 --- /dev/null +++ b/src/main/resources/REST/json/Cache.json @@ -0,0 +1,5 @@ +{ + "successful_set": { + "msg": "successful setting the cache" + } +} \ No newline at end of file diff --git a/src/main/resources/REST/schemas/Cache_negative_schema.json b/src/main/resources/REST/schemas/Cache_negative_schema.json new file mode 100644 index 0000000000000000000000000000000000000000..2bb8c406d714067ca7ceb26e548c69aa0b82fc79 --- /dev/null +++ b/src/main/resources/REST/schemas/Cache_negative_schema.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "kind": { + "type": "integer" + }, + "message": { + "type": "string" + } + }, + "required": [ + "id", + "kind", + "message" + ] +} \ No newline at end of file diff --git a/src/test/java/api/test/core/GeneralStepDefinitions.java b/src/test/java/api/test/core/GeneralStepDefinitions.java index 71bb3a94a6d8b83e5c56e022a55c051f47806003..884f3822cac104194fbf185240d9c1ab8d734365 100644 --- a/src/test/java/api/test/core/GeneralStepDefinitions.java +++ b/src/test/java/api/test/core/GeneralStepDefinitions.java @@ -603,15 +603,6 @@ public class GeneralStepDefinitions extends BaseStepDefinitions { } } - @When("^I send the current request as GET to endpoint \\{(.*?)\\}$") - public void iSendTheCurrentRequestAsGETToEndpoint(String endpoint) throws Throwable { - currentRequest.setPath(endpoint); - Response response = RestClient.get(currentRequest); - - addRequest(currentRequest); - addResponse(response); - } - /** * Compares the values of a json array with the supplied cucumber table * diff --git a/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java b/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java new file mode 100644 index 0000000000000000000000000000000000000000..b83261988ec1e571b31f41bf0e5690b7bf7a2029 --- /dev/null +++ b/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java @@ -0,0 +1,35 @@ +package api.test.rest.tsa.cache; + +import api.test.core.BaseStepDefinitions; +import api.test.rest.RestGeneralStepDefinitions; +import api.test.rest.RestSessionContainer; +import core.DataContainer; +import core.JsonUtils; +import core.Request; +import core.RestClient; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class CacheStepDefinitions extends BaseStepDefinitions { + private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName()); + RestSessionContainer restSessionContainer; + Request currentRequest; + + public CacheStepDefinitions(RestSessionContainer restSessionContainer, Request currentRequest, DataContainer dataContainer) { + super(dataContainer); + this.restSessionContainer = restSessionContainer; + this.currentRequest = currentRequest; + } + + @Given("we are testing the TSA Cache Api") + public void weAreTestingTheTSACacheApi() { + RestClient.setDefaultEncoding("UTF8"); + RestClient.setBaseURI(JsonUtils.getTSACache()); + RestClient.appendDefaultContentCharsetToContentTypeIfUndefined(false); + currentRequest.clear(); + currentRequest.getHeaders().put("X-Client-UserAgent", "test framework"); + currentRequest.setContentType("application/json"); + } +} diff --git a/src/test/resources/features/tsa/v1/cache/POST.feature b/src/test/resources/features/tsa/v1/cache/POST.feature new file mode 100644 index 0000000000000000000000000000000000000000..0189919fcf2c17e62a8f2b9e7ab67fd525e5d62a --- /dev/null +++ b/src/test/resources/features/tsa/v1/cache/POST.feature @@ -0,0 +1,51 @@ +#Copyright (c) 2018 Vereign AG [https://www.vereign.com] +# +#This is free software: you can redistribute it and/or modify +#it under the terms of the GNU Affero General Public License as +#published by the Free Software Foundation, either version 3 of the +#License, or (at your option) any later version. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU Affero General Public License for more details. +# +#You should have received a copy of the GNU Affero General Public License +#along with this program. If not, see <http://www.gnu.org/licenses/>. + +#http://localhost:8083/v1/cache +#Author: Georgi Michev georgi.michev@vereign.com + +@rest @all @tsa @cache +Feature: API -TSA - Cache - v1/cache POST + As policy administrator + I want to have distributed cache feature provided + So I am able to use cache functionality in my custom policies + + Acceptance criteria: + - The plugin for rego language to get/set values is ready to use + - The working example how to use the plugin + - Green test based on example committed to the system + + Background: + Given we are testing the TSA Cache Api + + Scenario: TSA - Working with Cache - Positive + Given I load the REST request {Cache.json} with profile {successful_set} + And I store key {key_positive} with value {test} in the data container + And I load object with key {key_positive} from DataContainer into currentRequest HEADER {x-cache-key} + And I send the current request as POST to endpoint {} + And the status code should be {201} + Then I clear the request body + And I send the current request as GET to endpoint {} + Then the status code should be {200} + And the field {msg} has the value {successful setting the cache} + + @negative + Scenario: TSA - Access non existing Cache - Negative + And I store key {key_negative} with value {test} in the data container + And I load object with key {key_negative} from DataContainer into currentRequest HEADER {x-cache-key} + Given I send the current request as GET to endpoint {} + Then the status code should be {404} + And the response is valid according to the {Cache_negative_schema.json} REST schema + And the field {message} has the value {key not found in cache}