diff --git a/src/test/java/api/test/rest/RestGeneralStepDefinitions.java b/src/test/java/api/test/rest/RestGeneralStepDefinitions.java index 2abd57cf9097a61dbbb6c3356829f3ddfc6e10c3..961c5ee48e828be53698f10235080684a7eb0e0c 100644 --- a/src/test/java/api/test/rest/RestGeneralStepDefinitions.java +++ b/src/test/java/api/test/rest/RestGeneralStepDefinitions.java @@ -56,6 +56,16 @@ public class RestGeneralStepDefinitions extends BaseStepDefinitions { } + @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"); + } + @Given("^we are testing the TSA Policy Api") public void we_are_testing_the_Policy_api() throws Throwable { RestClient.setDefaultEncoding("UTF8"); @@ -66,6 +76,26 @@ public class RestGeneralStepDefinitions extends BaseStepDefinitions { currentRequest.setContentType("application/json"); } + @Given("we are testing the TSA Signer Api") + public void weAreTestingTheTSASignerApi() { + RestClient.setDefaultEncoding("UTF8"); + RestClient.setBaseURI(JsonUtils.getTSASigner()); + RestClient.appendDefaultContentCharsetToContentTypeIfUndefined(false); + currentRequest.clear(); + currentRequest.getHeaders().put("X-Client-UserAgent", "test framework"); + currentRequest.setContentType("application/json"); + } + + @Given("we are testing the TSA Task Api") + public void weAreTestingTheTSATaskApi() { + RestClient.setDefaultEncoding("UTF8"); + RestClient.setBaseURI(JsonUtils.getTSATask()); + RestClient.appendDefaultContentCharsetToContentTypeIfUndefined(false); + currentRequest.clear(); + currentRequest.getHeaders().put("X-Client-UserAgent", "test framework"); + currentRequest.setContentType("application/json"); + } + @Given("^I load the REST request \\{(.*)\\} with profile \\{(.*)\\}$") public void I_load_the_REST_request__with_profile_(String jsonName, String profileName) throws Throwable { logger.info("Loading REST json into current request body. Json file= [{}] , profile= [{}]", jsonName, profileName); diff --git a/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java b/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java index b92245e65d927a2b5148568f3bc1872e9d7e2a4b..352cef90a30e5a0819d0004bc0f02557e98144f9 100644 --- a/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/cache/CacheStepDefinitions.java @@ -20,15 +20,6 @@ public class CacheStepDefinitions extends BaseStepDefinitions { 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"); - } @And("^I send the Cache (POST|GET) request via TSA Cache API$") public void iSendTheCachePOSTRequest(String method) { currentRequest.setPath("/v1/cache"); diff --git a/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java b/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java index 7c9241536308b072edb847372f6076fd02d33734..fc374d82f53e608dc95737db2d7832c3ed6f7f31 100644 --- a/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/policy/PolicyStepDefinitions.java @@ -40,40 +40,25 @@ public class PolicyStepDefinitions extends BaseStepDefinitions { this.currentRequest = currentRequest; } - @Given("^I load the body of my Policy request with \\{(.*)\\} from \\{(.*)\\}$") - public void iLoadTheBodyOfMyPolicyRequestWithDataFromFile(String profileName, String jsonName) throws Throwable { - logger.info("Loading REST json into current request body. Json file= [{}] , profile= [{}]", jsonName, profileName); - String loadedProfileData = JsonUtils.getProfileFromJson("/REST/json/" + jsonName, profileName); - if (!loadedProfileData.equals("null")) { - currentRequest.setBody(loadedProfileData); - logger.info("SUCCESS - profile loaded."); - } else { - throw new RAFException(String.format("Profile loading FAILED. Value is \"null\". File= [%s] , profile= [%s]", - jsonName, - profileName) - , RestGeneralStepDefinitions.class); - } - } - - @And("^I execute the Policy \\{(.*)\\} via TSA Policy API$") - public void iExecuteThePolicyTSAPolicyAPI(String path) throws Throwable { - currentRequest.setPath("/policy/example/" + path + "/1.0/evaluation"); + @And("^I execute the Policy group \\{(.*)\\} name \\{(.*)\\} version \\{(.*)\\} via TSA Policy API$") + public void iExecuteThePolicyGroupNameVersionTSAPolicyAPI(String group, String name, String version) throws Throwable { + currentRequest.setPath("/policy/" + group + "/" + name + "/" + version + "/evaluation"); Response response = RestClient.post(currentRequest); addRequest(currentRequest); addResponse(response); } - @When("^I lock the policy \\{(.*)\\}$") - public void iLockThePolicy(String path) throws Throwable { - currentRequest.setPath("/policy/example/" + path + "/1.0/lock"); + @When("^I lock the Policy group \\{(.*)\\} name \\{(.*)\\} version \\{(.*)\\}$") + public void iLockThePolicyGroupNameVersion(String group, String name, String version) throws Throwable { + currentRequest.setPath("/policy/" + group + "/" + name + "/" + version + "/lock"); Response response = RestClient.post(currentRequest); addRequest(currentRequest); addResponse(response); } - @When("^I unlock the policy \\{(.*)\\}$") - public void iUnlockThePolicy(String path) throws Throwable { - currentRequest.setPath("/policy/example/" + path + "/1.0/lock"); + @When("^I unlock the policy group \\{(.*)\\} name \\{(.*)\\} version \\{(.*)\\}$") + public void iUnlockThePolicy(String group, String name, String version) throws Throwable { + currentRequest.setPath("/policy/" + group + "/" + name + "/" + version + "/lock"); Response response = RestClient.delete(currentRequest); addRequest(currentRequest); addResponse(response); diff --git a/src/test/java/api/test/rest/tsa/signer/SignerStepDefinitions.java b/src/test/java/api/test/rest/tsa/signer/SignerStepDefinitions.java index c3b2463970862a4bcde5bf0e1c0d70b7960cb2de..fb87712776e8d22c677ca9d043434c65bb59478f 100644 --- a/src/test/java/api/test/rest/tsa/signer/SignerStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/signer/SignerStepDefinitions.java @@ -20,16 +20,6 @@ public class SignerStepDefinitions extends BaseStepDefinitions { this.currentRequest = currentRequest; } - @Given("we are testing the TSA Signer Api") - public void weAreTestingTheTSASignerApi() { - RestClient.setDefaultEncoding("UTF8"); - RestClient.setBaseURI(JsonUtils.getTSASigner()); - RestClient.appendDefaultContentCharsetToContentTypeIfUndefined(false); - currentRequest.clear(); - currentRequest.getHeaders().put("X-Client-UserAgent", "test framework"); - currentRequest.setContentType("application/json"); - } - @When("I get all keys via TSA Signer API") public void iGetAllKeysViaTSASignerAPI() { currentRequest.setPath("/v1/keys"); diff --git a/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java b/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java index 9b612de5949cb16eb85f13cb03126f118a2055f5..6c5033e456c389f11b0faa324337b416d366f120 100644 --- a/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java @@ -3,7 +3,10 @@ package api.test.rest.tsa.task; import api.test.core.BaseStepDefinitions; import api.test.rest.RestGeneralStepDefinitions; import api.test.rest.RestSessionContainer; +import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.JsonPath; +import com.jayway.jsonpath.Option; +import com.jayway.jsonpath.ReadContext; import core.*; import cucumber.api.java.en.And; import cucumber.api.java.en.Given; @@ -12,6 +15,9 @@ import org.apache.logging.log4j.Logger; import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + public class TaskStepDefinitions extends BaseStepDefinitions{ private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName()); RestSessionContainer restSessionContainer; @@ -23,16 +29,6 @@ public class TaskStepDefinitions extends BaseStepDefinitions{ this.currentRequest = currentRequest; } - @Given("we are testing the TSA Task Api") - public void weAreTestingTheTSATaskApi() { - RestClient.setDefaultEncoding("UTF8"); - RestClient.setBaseURI(JsonUtils.getTSATask()); - RestClient.appendDefaultContentCharsetToContentTypeIfUndefined(false); - currentRequest.clear(); - currentRequest.getHeaders().put("X-Client-UserAgent", "test framework"); - currentRequest.setContentType("application/json"); - } - @And("^I execute the Task \\{(.*)\\} via TSA Task API$") public void iExecuteTheTaskTSATaskAPI(String path) throws Throwable { currentRequest.setPath("/v1/task/" + path); @@ -68,19 +64,9 @@ public class TaskStepDefinitions extends BaseStepDefinitions{ } } - @And("^I get tasks IDs via TSA Task API$") - public void iGetTasksIdsTSATaskAPI() throws Throwable { - if (getLastResponse().getStatusCode() == 200) { - String responseBody = getLastResponse().getBody(); - - List<String> taskResult = JsonPath.read(responseBody, "$..tasks..id"); - restSessionContainer.setGroupTaskIDs(taskResult); - } - } - @And("^I get the Task result with key \\{(.*)\\}$") public void iGetTheTaskResultWithKey(String suffix) { - currentRequest.setPath("v1/"+ suffix); + currentRequest.setPath("v1/taskResult/"+ suffix); Response response = RestClient.get(currentRequest); addRequest(currentRequest); @@ -90,18 +76,46 @@ public class TaskStepDefinitions extends BaseStepDefinitions{ @And("^I get the current Task Result via TSA Task API$") public void iGetTheCurrentTaskResultTSATaskAPI() { String currentTask = restSessionContainer.getTaskID(); - iGetTheTaskResultWithKey("taskResult/"+ currentTask); + iGetTheTaskResultWithKey(currentTask); } @And("^I get the current taskList Status via TSA Task API$") public void iGetTheCurrentTaskListStatusTSATaskAPI() { String currentTask = restSessionContainer.getTaskListID(); - iGetTheTaskResultWithKey("taskListStatus/"+ currentTask); + currentRequest.setPath("v1/taskListStatus/"+ currentTask); + + Response response = RestClient.get(currentRequest); + addRequest(currentRequest); + addResponse(response); + + if (getLastResponse().getStatusCode() == 200) { + String responseBody = getLastResponse().getBody(); + + List<String> taskResult = JsonPath.read(responseBody, "$..tasks..id"); + restSessionContainer.setGroupTaskIDs(taskResult); + } } @And("^I get the result of Task \\{(\\d+)\\}$") public void iGetTheResultOfTask(int id) { - String currentTask = restSessionContainer.getTaskID(); - iGetTheTaskResultWithKey("taskResult/"+ restSessionContainer.getGroupTaskIDs().get(id)); + iGetTheTaskResultWithKey( restSessionContainer.getGroupTaskIDs().get(id)); + } + + @And("^the field \\{(.*?)\\} has one of the values$") + public static void theFieldHasOneOfTheValues(String jsonPath, List<String> expectedResultAsList) throws Throwable { + + Configuration conf = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build(); + ReadContext responseContext = JsonPath.using(conf).parse(getLastResponse().getBody()); + + Object parsedResult = responseContext.read(jsonPath); + String actualResultAsString = String.valueOf(parsedResult); + + for(String x: expectedResultAsList) { + if (x.equals(actualResultAsString)){ + return; + } + } + + assertEquals("Both of the expected values doesn't match actual: ", expectedResultAsList, actualResultAsString); } -} +} \ No newline at end of file diff --git a/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/evaluation/POST.feature b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/evaluation/POST.feature index 91b9b41b9520ea3170b53313976f369c29c357cf..ae395f1a4ddf16f9b40c3111e5088b0447ef411f 100644 --- a/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/evaluation/POST.feature +++ b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/evaluation/POST.feature @@ -32,14 +32,14 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST Scenario: TSA - Evaluate policy synchronously - Positive When I load the REST request {Policy.json} with profile {successful_message} - And I execute the Policy {test} via TSA Policy API + And I execute the Policy group {example} name {test} version {1.0} via TSA Policy API Then the status code should be {200} And the response is valid according to the {Policy_Evaluate_schema.json} REST schema And the field {allow} has the value {true} Scenario: TSA - DID resolution - Positive When I load the REST request {Policy.json} with profile {did_key} - And I execute the Policy {resolve} via TSA Policy API + And I execute the Policy group {example} name {resolve} version {1.0} via TSA Policy API Then the status code should be {200} And the response is valid according to the {Policy_EvaluateDID_schema.json} REST schema And the field {data.didDocument.id} has the value {did:key:z6Mkfriq1MqLBoPWecGoDLjguo1sB9brj6wT3qZ5BxkKpuP6} @@ -47,14 +47,14 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST @negative Scenario: TSA - Evaluate policy with incorrect value - Negative When I load the REST request {Policy.json} with profile {incorrect_message} - And I execute the Policy {test} via TSA Policy API + And I execute the Policy group {example} name {test} version {1.0} via TSA Policy API Then the status code should be {200} And the response is valid according to the {Policy_Evaluate_schema.json} REST schema And the field {allow} has the value {false} @negative Scenario: TSA - Evaluate policy with missing body- Negative - Given I execute the Policy {test} via TSA Policy API + And I execute the Policy group {example} name {test} version {1.0} via TSA Policy API Then the status code should be {200} And the response is valid according to the {Policy_Evaluate_schema.json} REST schema And the field {allow} has the value {false} @@ -62,7 +62,7 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST @negative Scenario: TSA - Evaluate missing policy - Negative When I load the REST request {Policy.json} with profile {successful_message} - Given I execute the Policy {missing} via TSA Policy API + And I execute the Policy group {example} name {missing} version {1.0} via TSA Policy API Then the status code should be {404} And the response is valid according to the {Policy_Evaluate_negative_schema.json} REST schema And the field {message} has the value {error evaluating policy} @@ -70,7 +70,7 @@ Feature: API -TSA - Policy - :group/:name/:version/evaluation POST @negative Scenario: TSA - DID resolution with incorrect did - Negative When I load the REST request {Policy.json} with profile {did_missing_method} - And I execute the Policy {resolve} via TSA Policy API + And I execute the Policy group {example} name {resolve} version {1.0} via TSA Policy API Then the status code should be {200} And the response is valid according to the {Policy_EvaluateDID_negative_schema.json} REST schema And the field {data.didResolutionMetadata.error} has the value {notFound} diff --git a/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/DELETE.feature b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/DELETE.feature index a152ed77d9fea883e838b6e61219caadfddab1c4..e1a91103e0f969ad41eecfc7a3b7ea9439119e50 100644 --- a/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/DELETE.feature +++ b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/DELETE.feature @@ -26,16 +26,16 @@ Feature: API - TSA - Policy - :group/:name/:version/lock DELETE Given we are testing the TSA Policy Api Scenario: TSA - Unlock policy - Positive - When I lock the policy {test} - And I unlock the policy {test} + When I lock the Policy group {example} name {test} version {1.0} + And I unlock the policy group {example} name {test} version {1.0} And the status code should be {200} # Check if the policy can be executed - When I load the body of my Policy request with {successful_message} from {Policy.json} - And I execute the Policy {test} via TSA Policy API + When I load the REST request {Policy.json} with profile {successful_message} + And I execute the Policy group {example} name {test} version {1.0} via TSA Policy API Then the status code should be {200} @negative Scenario: TSA - Unlock none existing policy - Negative - When I unlock the policy {non_existing} + And I unlock the policy group {example} name {non_existing} version {1.0} And the status code should be {404} And the field {message} has the value {policy not found} diff --git a/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/POST.feature b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/POST.feature index 19f22214f9c5960f94770d800a48e985688b996b..6b904c34f57db71442a7545a1c27bd8167867d2b 100644 --- a/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/POST.feature +++ b/src/test/resources/features/tsa/policy/policy/{group}/{name}/{version}/lock/POST.feature @@ -31,18 +31,18 @@ Feature: API - TSA -Policy - :group/:name/:version/lock POST Given we are testing the TSA Policy Api Scenario: TSA - Lock policy - Positive - When I lock the policy {test} + When I lock the Policy group {example} name {test} version {1.0} Then the status code should be {200} - Then I load the body of my Policy request with {successful_message} from {Policy.json} - And I execute the Policy {test} via TSA Policy API + When I load the REST request {Policy.json} with profile {successful_message} + And I execute the Policy group {example} name {test} version {1.0} via TSA Policy API Then the status code should be {403} And the field {message} has the value {error evaluating policy} - And I unlock the policy {test} + And I unlock the policy group {example} name {test} version {1.0} @negative Scenario: TSA - Lock already locked policy - Negative - When I lock the policy {test} - And I lock the policy {test} + When I lock the Policy group {example} name {test} version {1.0} + When I lock the Policy group {example} name {test} version {1.0} And the status code should be {403} And the field {message} has the value {policy is already locked} - And I unlock the policy {test} + And I unlock the policy group {example} name {test} version {1.0} diff --git a/src/test/resources/features/tsa/task/v1/task/taskListStatus/GET.feature b/src/test/resources/features/tsa/task/v1/task/taskListStatus/GET.feature index 1c05885320f27c52953956c19ad83bd1a976484d..2db90670c7efcab07bc76b0912becd8b0ecf9a27 100644 --- a/src/test/resources/features/tsa/task/v1/task/taskListStatus/GET.feature +++ b/src/test/resources/features/tsa/task/v1/task/taskListStatus/GET.feature @@ -33,7 +33,6 @@ Feature: API -TSA - Task - v1/taskList GET And I wait for {1000} mseconds Then I get the current taskList Status via TSA Task API Then the status code should be {200} - And I get tasks IDs via TSA Task API Then I get the current taskList Status via TSA Task API And the response is valid according to the {TaskList_Status_schema.json} REST schema And the field {status} has the value {done} @@ -47,7 +46,6 @@ Feature: API -TSA - Task - v1/taskList GET And I wait for {1000} mseconds Then I get the current taskList Status via TSA Task API Then the status code should be {207} - And I get tasks IDs via TSA Task API Then I get the current taskList Status via TSA Task API And the response is valid according to the {TaskList_Status_schema.json} REST schema And the field {status} has the value {failed} @@ -61,8 +59,8 @@ Feature: API -TSA - Task - v1/taskList GET And I wait for {1000} mseconds Then I get the current taskList Status via TSA Task API Then the status code should be {207} - And I get tasks IDs via TSA Task API Then I get the current taskList Status via TSA Task API And the response is valid according to the {TaskList_Status_schema.json} REST schema And the field {status} has the value {failed} - And the field {$..tasks..status} has the value {["failed","done","done"]} + And the field {$..tasks..status} has one of the values + | ["done","failed","done"] | ["failed","done","done"] | \ No newline at end of file diff --git a/src/test/resources/features/tsa/task/v1/task/taskResult/GET.feature b/src/test/resources/features/tsa/task/v1/task/taskResult/GET.feature index 1b16afc32e9afb41d14a64d00f2e62b3dad6d4e6..fc627ff199bcef5bcbbd0c024bc470652bcf4c14 100644 --- a/src/test/resources/features/tsa/task/v1/task/taskResult/GET.feature +++ b/src/test/resources/features/tsa/task/v1/task/taskResult/GET.feature @@ -47,7 +47,6 @@ Feature: API -TSA - Task - v1/taskList GET And I wait for {1000} mseconds Then I get the current taskList Status via TSA Task API And the status code should be {200} - Then I get tasks IDs via TSA Task API And I get the result of Task {0} And the status code should be {200} And I get the result of Task {1}