Skip to content
Snippets Groups Projects
Unverified Commit a04ecaf7 authored by Georgi Michev's avatar Georgi Michev
Browse files

add task list tests

parent 3d3a00d0
No related branches found
No related tags found
1 merge request!22refactor step definitions
Showing with 305 additions and 38 deletions
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
...@@ -17,17 +17,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -17,17 +17,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package api.test.rest; package api.test.rest;
import api.test.rest.pojo.Member; import java.util.List;
public class RestSessionContainer { public class RestSessionContainer {
private String taskID; 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() { public String getTaskID() {
return taskID; return taskID;
} }
public String getTaskListID() {
return taskListID;
}
public void setTaskID(String taskID) { public void setTaskID(String taskID) {
this.taskID = taskID; this.taskID = taskID;
} }
}
public void setTaskListID(String taskListID) {
this.taskListID= taskListID;
}
}
\ No newline at end of file
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"taskListID": {
"type": "string"
}
},
"required": [
"taskListID"
]
}
\ No newline at end of file
{
"$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
...@@ -10,6 +10,8 @@ import cucumber.api.java.en.Given; ...@@ -10,6 +10,8 @@ import cucumber.api.java.en.Given;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.util.List;
public class TaskStepDefinitions extends BaseStepDefinitions{ public class TaskStepDefinitions extends BaseStepDefinitions{
private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName()); private static final Logger logger = LogManager.getLogger(RestGeneralStepDefinitions.class.getSimpleName());
RestSessionContainer restSessionContainer; RestSessionContainer restSessionContainer;
...@@ -49,9 +51,36 @@ public class TaskStepDefinitions extends BaseStepDefinitions{ ...@@ -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 \\{(.*)\\}$") @And("^I get the Task result with key \\{(.*)\\}$")
public void iGetTheTaskResultWithKey(String suffix) { public void iGetTheTaskResultWithKey(String suffix) {
currentRequest.setPath("v1/taskResult/"+ suffix); currentRequest.setPath("v1/"+ suffix);
Response response = RestClient.get(currentRequest); Response response = RestClient.get(currentRequest);
addRequest(currentRequest); addRequest(currentRequest);
...@@ -61,6 +90,18 @@ public class TaskStepDefinitions extends BaseStepDefinitions{ ...@@ -61,6 +90,18 @@ public class TaskStepDefinitions extends BaseStepDefinitions{
@And("^I get the current Task Result via TSA Task API$") @And("^I get the current Task Result via TSA Task API$")
public void iGetTheCurrentTaskResultTSATaskAPI() { public void iGetTheCurrentTaskResultTSATaskAPI() {
String currentTask = restSessionContainer.getTaskID(); 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));
} }
} }
#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"]}
#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}
...@@ -30,16 +30,8 @@ Feature: API -TSA - Task - v1/task GET ...@@ -30,16 +30,8 @@ Feature: API -TSA - Task - v1/task GET
Background: Background:
Given we are testing the TSA Task Api Given we are testing the TSA Task Api
Scenario: TSA - Executing Task with DID resolver and checking the Task Results - Positive Scenario: TSA - Executing Task with DID resolver - Positive
#Execute Task
When I load the REST request {Policy.json} with profile {did_key} When I load the REST request {Policy.json} with profile {did_key}
And I execute the Task {didResolve} via TSA Task API And I execute the Task {didResolve} via TSA Task API
Then the status code should be {200} Then the status code should be {200}
And the response is valid according to the {Task_Execute_schema.json} REST schema And the response is valid according to the {Task_Execute_schema.json} REST schema
#GET Task Result \ No newline at end of file
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
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment