diff --git a/features/evaluatePolicyGroups.feature b/features/evaluatePolicyGroups.feature deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/features/executeTask.feature b/features/executeTask.feature deleted file mode 100644 index 933802a754cc5b519916eaafb38ae98456faedfa..0000000000000000000000000000000000000000 --- a/features/executeTask.feature +++ /dev/null @@ -1,24 +0,0 @@ -As user -I want to evaluate the policy asynchronously -So I am able to execute the developed Rego code in the future non-blocking - -Scenario: Execute the task during evaluating policy -Given long running policy is uploaded to the system -And the task template is uploaded to the system -When I evaluate the policy asynchronously -And the task template is specified as an input -When I get successful response -And the response contains taskId - -Scenario: Getting the result for the executed task -Given long running policy is executed -When I request the result of execution -And request contains the taskId -And the task has finished -Then I get successful response -And response contains the result of execution of the policy - -Acceptance criteria: -- HTTP endpoints to evaluate the policy asynchronously and get the result -- example of long-running policy committed to Git repo -- Green test based on example committed to the system diff --git a/src/main/java/api/test/rest/RestSessionContainer.java b/src/main/java/api/test/rest/RestSessionContainer.java index ce9202eec24b1d3dceb8276e7c4b4d7f4f936f47..b5e5261a2a684a1a7bc08dbcf3b3a596b1a33d6f 100644 --- a/src/main/java/api/test/rest/RestSessionContainer.java +++ b/src/main/java/api/test/rest/RestSessionContainer.java @@ -17,17 +17,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. package api.test.rest; -import api.test.rest.pojo.Member; +import java.util.List; public class RestSessionContainer { private String taskID; + private String taskListID; + private List<String> groupTaskIDs; + + public List<String> getGroupTaskIDs() { + return groupTaskIDs; + } + + public void setGroupTaskIDs(List<String> groupTaskIDs) { + this.groupTaskIDs = groupTaskIDs; + } public String getTaskID() { return taskID; } + public String getTaskListID() { + return taskListID; + } + public void setTaskID(String taskID) { this.taskID = taskID; } -} + public void setTaskListID(String taskListID) { + this.taskListID= taskListID; + } +} \ No newline at end of file diff --git a/src/main/resources/REST/schemas/TaskList_Execute_schema.json b/src/main/resources/REST/schemas/TaskList_Execute_schema.json new file mode 100644 index 0000000000000000000000000000000000000000..650a76d5d1db43da9c91706d7395d39ddf74dcdb --- /dev/null +++ b/src/main/resources/REST/schemas/TaskList_Execute_schema.json @@ -0,0 +1,12 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "taskListID": { + "type": "string" + } + }, + "required": [ + "taskListID" + ] +} \ No newline at end of file diff --git a/src/main/resources/REST/schemas/TaskList_Status_schema.json b/src/main/resources/REST/schemas/TaskList_Status_schema.json new file mode 100644 index 0000000000000000000000000000000000000000..a21feb97fe1b03f94144ae8700e64a7c99862c69 --- /dev/null +++ b/src/main/resources/REST/schemas/TaskList_Status_schema.json @@ -0,0 +1,73 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "status": { + "type": "string" + }, + "groups": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "status": { + "type": "string" + }, + "tasks": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "status": { + "type": "string" + } + }, + "required": [ + "id", + "status" + ] + }, + { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "status": { + "type": "string" + } + }, + "required": [ + "id", + "status" + ] + } + ] + } + }, + "required": [ + "id", + "status", + "tasks" + ] + } + ] + } + }, + "required": [ + "id", + "status", + "groups" + ] +} \ No newline at end of file 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 8e705f046791aff2c55b6db7c54b9895a2397567..9b612de5949cb16eb85f13cb03126f118a2055f5 100644 --- a/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java +++ b/src/test/java/api/test/rest/tsa/task/TaskStepDefinitions.java @@ -10,6 +10,8 @@ import cucumber.api.java.en.Given; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.List; + public class TaskStepDefinitions extends BaseStepDefinitions{ private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName()); RestSessionContainer restSessionContainer; @@ -49,9 +51,36 @@ public class TaskStepDefinitions extends BaseStepDefinitions{ } } + @And("^I execute the taskList \\{(.*)\\} via TSA Task API$") + public void iExecuteTheTaskListTSATaskAPI(String path) throws Throwable { + currentRequest.setPath("/v1/taskList/" + path); + + Response response = RestClient.post(currentRequest); + addRequest(currentRequest); + addResponse(response); + + if (getLastResponse().getStatusCode() == 200) { + String responseBody = getLastResponse().getBody(); + Object result = JsonPath.read(responseBody, "$.taskListID"); + String taskListId = result.toString(); + + restSessionContainer.setTaskListID(taskListId); + } + } + + @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/taskResult/"+ suffix); + currentRequest.setPath("v1/"+ suffix); Response response = RestClient.get(currentRequest); addRequest(currentRequest); @@ -61,6 +90,18 @@ public class TaskStepDefinitions extends BaseStepDefinitions{ @And("^I get the current Task Result via TSA Task API$") public void iGetTheCurrentTaskResultTSATaskAPI() { String currentTask = restSessionContainer.getTaskID(); - iGetTheTaskResultWithKey(currentTask); + iGetTheTaskResultWithKey("taskResult/"+ currentTask); + } + + @And("^I get the current taskList Status via TSA Task API$") + public void iGetTheCurrentTaskListStatusTSATaskAPI() { + String currentTask = restSessionContainer.getTaskListID(); + iGetTheTaskResultWithKey("taskListStatus/"+ currentTask); + } + + @And("^I get the result of Task \\{(\\d+)\\}$") + public void iGetTheResultOfTask(int id) { + String currentTask = restSessionContainer.getTaskID(); + iGetTheTaskResultWithKey("taskResult/"+ restSessionContainer.getGroupTaskIDs().get(id)); } } 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 new file mode 100644 index 0000000000000000000000000000000000000000..1c05885320f27c52953956c19ad83bd1a976484d --- /dev/null +++ b/src/test/resources/features/tsa/task/v1/task/taskListStatus/GET.feature @@ -0,0 +1,68 @@ +#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://gaiax.vereign.com/tsa/task/v1/taskListStatus +#Author: Georgi Michev georgi.michev@vereign.com + +@rest @all @tsa @task +Feature: API -TSA - Task - v1/taskList GET + As user + I want to execute the list of tasks + So I am able to bring the consistency to running multiple asynchronous tasks + + Background: + Given we are testing the TSA Task Api + + Scenario: TSA - Get status from Task List execution - Positive + When I load the REST request {Policy.json} with profile {did_key} + And I execute the taskList {testList} via TSA Task API + Then the status code should be {200} + And the response is valid according to the {TaskList_Execute_schema.json} REST schema + 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} + And the field {$..tasks..status} has the value {["done","done"]} + + Scenario: TSA - Get status from Task List with three synchronous tasks second fails - Negative + When I set the following request body {{}} + And I execute the taskList {failTestListSync} via TSA Task API + Then the status code should be {200} + And the response is valid according to the {TaskList_Execute_schema.json} REST schema + 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 {["done","failed","failed"]} + + Scenario: TSA - Get status from Task List with three asynchronous tasks second fails - Negative + When I set the following request body {{}} + And I execute the taskList {failTestListAsync} via TSA Task API + Then the status code should be {200} + And the response is valid according to the {TaskList_Execute_schema.json} REST schema + 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"]} 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 new file mode 100644 index 0000000000000000000000000000000000000000..1b16afc32e9afb41d14a64d00f2e62b3dad6d4e6 --- /dev/null +++ b/src/test/resources/features/tsa/task/v1/task/taskResult/GET.feature @@ -0,0 +1,56 @@ +#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://gaiax.vereign.com/tsa/task/v1/taskResult +#Author: Georgi Michev georgi.michev@vereign.com + +@rest @all @tsa @task +Feature: API -TSA - Task - v1/taskList GET + As user + I want to execute the list of tasks + So I am able to bring the consistency to running multiple asynchronous tasks + + Background: + Given we are testing the TSA Task Api + + Scenario: TSA - Executing Task with DID resolver and checking the Task Results - Positive + #Execute Task + When I load the REST request {Policy.json} with profile {did_key} + And I execute the Task {didResolve} via TSA Task API + Then the status code should be {200} + And the response is valid according to the {Task_Execute_schema.json} REST schema + #GET Task Result + Then I clear the request body + And I wait for {2000} mseconds + And I get the current Task Result via TSA Task API + Then the status code should be {200} + And the response is valid according to the {Task_ExecuteDID_schema.json} REST schema + And the field {data.didDocument.id} has the value {did:key:z6Mkfriq1MqLBoPWecGoDLjguo1sB9brj6wT3qZ5BxkKpuP6} + + Scenario: TSA - Get result from Task List with two synchronous tasks - Positive + When I set the following request body {{}} + And I execute the taskList {testList} via TSA Task API + Then the status code should be {200} + And the response is valid according to the {TaskList_Execute_schema.json} REST schema + 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} + And 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} diff --git a/src/test/resources/features/tsa/task/v1/task/{taskName}/GET.feature b/src/test/resources/features/tsa/task/v1/task/{taskName}/GET.feature index 42bf0143661334cfb695f3edb6ee96b976803bff..acab16840491af7aa94561b8a4ad0b7c2519dbbd 100644 --- a/src/test/resources/features/tsa/task/v1/task/{taskName}/GET.feature +++ b/src/test/resources/features/tsa/task/v1/task/{taskName}/GET.feature @@ -30,16 +30,8 @@ Feature: API -TSA - Task - v1/task GET Background: Given we are testing the TSA Task Api - Scenario: TSA - Executing Task with DID resolver and checking the Task Results - Positive - #Execute Task + Scenario: TSA - Executing Task with DID resolver - Positive When I load the REST request {Policy.json} with profile {did_key} And I execute the Task {didResolve} via TSA Task API Then the status code should be {200} - And the response is valid according to the {Task_Execute_schema.json} REST schema - #GET Task Result - Then I clear the request body - And I wait for {2000} mseconds - And I get the current Task Result via TSA Task API - Then the status code should be {200} - And the response is valid according to the {Task_ExecuteDID_schema.json} REST schema - And the field {data.didDocument.id} has the value {did:key:z6Mkfriq1MqLBoPWecGoDLjguo1sB9brj6wT3qZ5BxkKpuP6} \ No newline at end of file + And the response is valid according to the {Task_Execute_schema.json} REST schema \ No newline at end of file diff --git a/src/test/resources/features/tsa/task/v1/taskList/{listName}/POST.feature b/src/test/resources/features/tsa/task/v1/taskList/{listName}/POST.feature new file mode 100644 index 0000000000000000000000000000000000000000..5267ce919c2b9bea9ec7fa2f586deac8d9ebb4ec --- /dev/null +++ b/src/test/resources/features/tsa/task/v1/taskList/{listName}/POST.feature @@ -0,0 +1,32 @@ +#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://gaiax.vereign.com/tsa/task/v1/taskList +#Author: Georgi Michev georgi.michev@vereign.com + +@rest @all @tsa @task +Feature: API -TSA - Task - v1/taskList POST + As user + I want to execute the list of tasks + So I am able to bring the consistency to running multiple asynchronous tasks + + Background: + Given we are testing the TSA Task Api + + Scenario: TSA - Executing Task List with two synchronous tasks - Positive + When I load the REST request {Policy.json} with profile {did_key} + And I execute the taskList {testList} via TSA Task API + Then the status code should be {200} + And the response is valid according to the {TaskList_Execute_schema.json} REST schema \ No newline at end of file