diff --git a/.gitignore b/.gitignore index 9c26ff320caa448bed01cfc1a878c6db6d588551..2ccbd780b2355b4c7683909abf310eb7c80cd2bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .gradle .idea +build logs .classpath .project diff --git a/src/main/java/core/JsonUtils.java b/src/main/java/core/JsonUtils.java index 41702088b3c6c90ea944d2eac759035bb0941801..ccbbd08330ffe29addff35b3be5f114cdd93f835 100644 --- a/src/main/java/core/JsonUtils.java +++ b/src/main/java/core/JsonUtils.java @@ -229,55 +229,13 @@ public class JsonUtils { /** - * Get the url for "viam" + * Get the url for "TSA policy" * @return the uri */ - public static String getVIAM() { - return System.getProperty("baseUrl") + "/api"; + public static String getTSAPolicy() { + return System.getProperty("baseUrl") + "/policy"; } - /** - * Get the url for "cardDav" - * @return the uri - */ - public static String getCardDav() { - return System.getProperty("baseUrl") + "/carddav"; - } - - /** - * Get the url for "wopi" - * @return the uri - */ - public static String getWopi() { - return System.getProperty("baseUrl") + "/wopi"; - } - - /** - * Get the url for "webDav" - * @return the uri - */ - public static String getWebDav() { - return System.getProperty("baseUrl")+ "/webdav"; - } - - /** - * Get the url for "webDav" - * @return the uri - */ - public static String getJsProxy() { - return System.getProperty("baseUrl")+ "/proxy"; - } - - - /** - * Get the url for "Dashboard" - * @return the uri - */ - public static String getDashboard() { - return System.getProperty("baseUrl"); - } - - /** * UTF8 encodes a string * diff --git a/src/test/java/api/test/rest/RestGeneralStepDefinitions.java b/src/test/java/api/test/rest/RestGeneralStepDefinitions.java index 4f98fbc3f80b922fb615db3827ea2f9d6d8808f6..0f6ba368976a080161fa9db293d7a1bfce7ded40 100644 --- a/src/test/java/api/test/rest/RestGeneralStepDefinitions.java +++ b/src/test/java/api/test/rest/RestGeneralStepDefinitions.java @@ -52,63 +52,16 @@ public class RestGeneralStepDefinitions extends BaseStepDefinitions { } - @Given("^we are testing the VIAM Api") - public void we_are_testing_the_VIAM_api() throws Throwable { + @Given("^we are testing the TSA Policy Api") + public void we_are_testing_the_Policy_api() throws Throwable { RestClient.setDefaultEncoding("UTF8"); - RestClient.setBaseURI(JsonUtils.getVIAM()); + RestClient.setBaseURI(JsonUtils.getTSAPolicy()); RestClient.appendDefaultContentCharsetToContentTypeIfUndefined(false); currentRequest.clear(); currentRequest.getHeaders().put("X-Client-UserAgent", "test framework"); currentRequest.setContentType("application/json"); } - @Given("^we are testing the CardDav$") - public void we_are_testing_the_CardDav() throws Throwable { - RestClient.setDefaultEncoding("UTF8"); - RestClient.setBaseURI(JsonUtils.getCardDav()); - RestClient.appendDefaultContentCharsetToContentTypeIfUndefined(false); - currentRequest.clear(); - currentRequest.getHeaders().put("X-Client-UserAgent", "test framework"); - currentRequest.setContentType("application/xml"); - } - - @Given("^we are testing the WOPI") - public void we_are_testing_the_WOPI_service() throws Throwable { - RestClient.setDefaultEncoding("UTF8"); - RestClient.setBaseURI(JsonUtils.getWopi()); - RestClient.appendDefaultContentCharsetToContentTypeIfUndefined(false); - currentRequest.getHeaders().put("X-Client-UserAgent", "test framework"); - currentRequest.setContentType("application/json"); - } - - @Given("^we are testing the WebDav") - public void we_are_testing_the_WebDav_service() throws Throwable { - RestClient.setDefaultEncoding("UTF8"); - RestClient.setBaseURI(JsonUtils.getWebDav()); - RestClient.appendDefaultContentCharsetToContentTypeIfUndefined(false); - currentRequest.getHeaders().put("X-Client-UserAgent", "test framework"); - currentRequest.setContentType("application/json"); - } - - @Given("^we are testing with the current session the WOPI$") - public void we_are_testing_with_the_current_session_the_WOPI() throws Throwable { - currentRequest.clear(); - currentRequest.getHeaders().put("publicKey", restSessionContainer.getPublicKey()); - currentRequest.getHeaders().put("uuid", restSessionContainer.getOauthUUID()); - currentRequest.getHeaders().put("token", restSessionContainer.getOauthToken()); - we_are_testing_the_WOPI_service(); - } - - @Given("^we are testing with the current session the WebDav$") - public void we_are_testing_with_the_current_session_the_WebDav() throws Throwable { - currentRequest.clear(); - currentRequest.getHeaders().put("publicKey", restSessionContainer.getPublicKey()); - currentRequest.getHeaders().put("uuid", restSessionContainer.getOauthUUID()); - currentRequest.getHeaders().put("token", restSessionContainer.getOauthToken()); - currentRequest.getHeaders().put("passportuuid", restSessionContainer.getPassportEntityUUID()); - we_are_testing_the_WebDav_service(); - } - @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/batch/BatchStepDefinitions.java b/src/test/java/api/test/rest/batch/BatchStepDefinitions.java deleted file mode 100644 index 48c1b9ebe60e42d0e3f3a7cd0316a60a81efa0fa..0000000000000000000000000000000000000000 --- a/src/test/java/api/test/rest/batch/BatchStepDefinitions.java +++ /dev/null @@ -1,157 +0,0 @@ -/* -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/>. -*/ - -package api.test.rest.batch; - -import api.test.core.BaseStepDefinitions; -import api.test.rest.RestSessionContainer; -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.jayway.jsonpath.JsonPath; -import core.DataContainer; -import core.Request; -import core.Response; -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; -import utils.RAFRandomize; - -import java.util.Base64; - -import static org.junit.Assert.assertTrue; - -public class BatchStepDefinitions extends BaseStepDefinitions { - private static final Logger logger = LogManager.getLogger(BatchStepDefinitions.class.getSimpleName()); - RestSessionContainer restSessionContainer; - Request currentRequest; - - public BatchStepDefinitions(RestSessionContainer restSessionContainer, Request currentRequest, DataContainer dataContainer) { - super(dataContainer); - this.restSessionContainer = restSessionContainer; - this.currentRequest = currentRequest; - } - - @Given("^I send a new batch request via API$") - public void I_send_a_new_batch_request_via_API() { - currentRequest.setPath("/sendBatch"); - - Response response = RestClient.post(currentRequest); - addRequest(currentRequest); - addResponse(response); - } - - @Given("^I call getStatuses request via API$") - public void I_call_getStatuses_request_via_API() { - currentRequest.setPath("/getStatuses"); - - Response response = RestClient.post(currentRequest); - addRequest(currentRequest); - addResponse(response); - } - - @Then("^I assert that getStatus status is the same as the sendBatch value via API$") - public void I_assert_that_getStatus_status_is_the_same_as_the_sendBatch_value_via_API() { - String responseBody = getLastResponse().getBody(); - if (restSessionContainer.getBatchValue() != null) { - String actualValue = JsonPath.read(responseBody, "$..Status").toString(); - assertTrue("'Batch Value' doesn't match expected claim: ", actualValue.contains(restSessionContainer.getBatchValue())); - } - } - - - @Given("^I call getStatuses with the current (sealKey|sealKey2) via API$") - public void I_call_getStatuses_with_the_current_sealKey_via_API(String sealKey) { - Gson gson = new Gson(); - JsonElement initialBody = gson.fromJson(currentRequest.getBody(), JsonElement.class); - // only try to load body as JsonObject if it is not null. - JsonObject newBody = new JsonObject(); - if (initialBody != null) newBody = initialBody.getAsJsonObject(); - - switch (sealKey) { - case "sealKey": - newBody.addProperty("key", restSessionContainer.getBatchKey()); - break; - case "sealKey2": - newBody.addProperty("key", restSessionContainer.getBatchKey2()); - break; - } - - currentRequest.setBody(gson.toJson(newBody)); - - I_call_getStatuses_request_via_API(); - } - - @Given("^I send a new random batch request via API$") - public void I_send_a_new_random_batch_request_via_API() throws Throwable { - String originalInput = "batchValue+" + RAFRandomize.getAlphabetic(5, 5); - String encodedString = Base64.getEncoder().encodeToString(originalInput.getBytes()); - restSessionContainer.setBatchValue(encodedString); - - String batchKey = "seal_id_" + RAFRandomize.getAlphabetic(8, 8); - restSessionContainer.setBatchKey(batchKey); - - Gson gson = new Gson(); - JsonElement initialBody = gson.fromJson(currentRequest.getBody(), JsonElement.class); - // only try to load body as JsonObject if it is not null. - JsonObject newBody = new JsonObject(); - JsonObject batch = new JsonObject(); - if (initialBody != null) newBody = initialBody.getAsJsonObject(); - batch.addProperty(batchKey, encodedString); - newBody.add("batch", batch); - currentRequest.setBody(gson.toJson(newBody)); - - I_send_a_new_batch_request_via_API(); - } - - @Given("^I send a new random batch request with 2 objects via API$") - public void I_send_a_new_random_batch_request_with_2_objects_via_API() throws Throwable { - String originalInput = "batchValue+" + RAFRandomize.getAlphabetic(5, 5); - String encodedString = Base64.getEncoder().encodeToString(originalInput.getBytes()); - restSessionContainer.setBatchValue(encodedString); - - String batchKey = "seal_id_" + RAFRandomize.getAlphabetic(8, 8); - String batchKey2 = "seal_id_" + RAFRandomize.getAlphabetic(8, 8); - restSessionContainer.setBatchKey(batchKey); - restSessionContainer.setBatchKey2(batchKey2); - - Gson gson = new Gson(); - JsonElement initialBody = gson.fromJson(currentRequest.getBody(), JsonElement.class); - // only try to load body as JsonObject if it is not null. - JsonObject newBody = new JsonObject(); - JsonObject batch = new JsonObject(); - if (initialBody != null) newBody = initialBody.getAsJsonObject(); - batch.addProperty(batchKey, encodedString); - batch.addProperty(batchKey2, encodedString); - newBody.add("batch", batch); - currentRequest.setBody(gson.toJson(newBody)); - - I_send_a_new_batch_request_via_API(); - } - - @Given("^I send a total count request via API$") - public void I_send_a_total_count_request_via_API() { - currentRequest.setPath("/getTotalCount"); - - Response response = RestClient.post(currentRequest); - addRequest(currentRequest); - addResponse(response); - } - -} \ No newline at end of file diff --git a/src/test/resources/features/batch/api/getStatuses/POST.feature b/src/test/resources/features/batch/api/getStatuses/POST.feature deleted file mode 100644 index beff4258066ed6153cabd7c0870ea0aaae4b9090..0000000000000000000000000000000000000000 --- a/src/test/resources/features/batch/api/getStatuses/POST.feature +++ /dev/null @@ -1,91 +0,0 @@ -#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/api/getStatuses -#Author: Rosen Georgiev rosen.georgiev@vereign.com - -@rest @batch @all -Feature: API - getStatuses POST - Get the previously added Batches - - Background: - Given we are testing the VIAM Api - - @getStatuses @test - Scenario: Send a batch request and then fetch it with getStatuses - Positive -#Send Batch - Given I load the REST request {Batch.json} with profile {successful_batch} - Given I send a new random batch request via API - And the status code should be {200} -#Get Statuses - Then I wait for {60000} mseconds - Given I clear the request body - Then I call getStatuses with the current sealKey via API - And the status code should be {200} - And the field {$.status} has the value {OK} - And the field {$.code} has the value {200} - And the response is valid according to the {Batch_GetStatuses_schema.json} REST schema - And I assert that getStatus status is the same as the sendBatch value via API - - @getStatuses @negative - Scenario Outline: Try to call getStatuses with invalid request - <profile> - Negative -#Get Statuses - Given I clear the request body - Given I load the REST request {Batch.json} with profile {<profile>} - Then I call getStatuses request via API - And the status code should be {400} - And the field {$.message} has the value {<msg>} - Examples: - | profile | msg | - | getStatuses_missing_key | sealID (key) is missing | - | getStatuses_missing_value | sealID (key) is missing | - | getStatuses_empty | sealID (key) is missing | - - @sendbatch - Scenario: Send a batch requests with 2 objects and then get them - Positive -#Send Batch - Given I load the REST request {Batch.json} with profile {successful_batch} - Then I send a new random batch request with 2 objects via API - And the status code should be {200} - And the field {message} has the value {batch is queued} -#Get Statuses of seal key 1 - Then I wait for {60000} mseconds - Given I clear the request body - Then I call getStatuses with the current sealKey via API - And the status code should be {200} - And the response is valid according to the {Batch_GetStatuses_schema.json} REST schema - And I assert that getStatus status is the same as the sendBatch value via API -#Get Statuses of seal key 2 - Given I clear the request body - Then I call getStatuses with the current sealKey2 via API - And the status code should be {200} - And the response is valid according to the {Batch_GetStatuses_schema.json} REST schema - And I assert that getStatus status is the same as the sendBatch value via API - - @sendbatch - Scenario: Send 2 separate batch requests for the same key and then get them - Positive -#Send Batch - Given I load the REST request {Batch.json} with profile {successful_batch} - Given I send a new random batch request via API - And the status code should be {200} - Then I send a new batch request via API - And the status code should be {200} - And the field {message} has the value {batch is queued} -#Get Statuses - Then I wait for {120000} mseconds - Given I clear the request body - Then I call getStatuses with the current sealKey via API - And the status code should be {200} - And the field {$..Status} contains {2} elements \ No newline at end of file diff --git a/src/test/resources/features/batch/api/getTotalCount/POST.feature b/src/test/resources/features/batch/api/getTotalCount/POST.feature deleted file mode 100644 index adcef82bab203cf994fa7f1110c52aa6bfe622a7..0000000000000000000000000000000000000000 --- a/src/test/resources/features/batch/api/getTotalCount/POST.feature +++ /dev/null @@ -1,41 +0,0 @@ -#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/api/sendbatch -#Author: Georgi Michev georgi.michev@vereign.como - -@rest @batch @all -Feature: API - getTotalCount POST - Retrieve counters for processed seal statuses and batches - - Background: - Given we are testing the VIAM Api - - @getTotalCount - Scenario: Send request with empty body - Positive - #Send Request - Given I send a total count request via API - And the status code should be {200} - And the response is valid according to the {Batch_GetTotalCount_schema.json} REST schema - And the field {data} is present and not empty - And the field {data} is not equal to the value {0} - And the field {receivedStatus} is present and not empty - And the field {receivedStatus} is not equal to the value {0} - And the field {storedStatus} is present and not empty - And the field {storedStatus} is not equal to the value {0} - And the field {anchoredStatus} is present and not empty - And the field {anchoredStatus} is not equal to the value {0} - And the field {anchoredBatches} is present and not empty - And the field {anchoredBatches} is not equal to the value {0} diff --git a/src/test/resources/features/batch/api/sendBatch/POST.feature b/src/test/resources/features/batch/api/sendBatch/POST.feature deleted file mode 100644 index 005ee34866dd37d73ad61bfb7e784fbad880e48d..0000000000000000000000000000000000000000 --- a/src/test/resources/features/batch/api/sendBatch/POST.feature +++ /dev/null @@ -1,61 +0,0 @@ -#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/api/sendbatch -#Author: Rosen Georgiev rosen.georgiev@vereign.com - -@rest @batch @all -Feature: API - sendBatch POST - This all sends batch request - - Background: - Given we are testing the VIAM Api - - @sendbatch - Scenario: Send a new random batch - Positive -#Send Batch - Given I load the REST request {Batch.json} with profile {successful_batch} - Given I send a new random batch request via API - And the status code should be {200} - And the field {message} has the value {batch is queued} - - @sendbatch - Scenario: Send 2 batch requests for the same key - Positive -#Send Batch - Given I load the REST request {Batch.json} with profile {successful_batch} - Given I send a new random batch request via API - And the status code should be {200} - Then I send a new batch request via API - And the status code should be {200} - And the field {message} has the value {batch is queued} - - @sendbatch @negative - Scenario Outline: Try to send invalid batch requests for sendBatch - <profile> - Negative -#Send Batch - Given I load the REST request {Batch.json} with profile {<profile>} - Given I send a new batch request via API - And the status code should be {<code>} - And the field {message} has the value {<message>} - And the field {kind} has the value {<kind>} - And the field {id} is present and not empty - Examples: - | profile | message | code | kind | - | missing_batch | no status entries to process | 400 | 1 | - | empty_seal_key | invalid batch | 400 | 1 | - | empty_seal_value | invalid batch | 400 | 1 | - | missing_seal | no status entries to process | 400 | 1 | - | not_base64_value | invalid batch | 400 | 1 | - - diff --git a/src/test/resources/features/policy/api/POST.feature b/src/test/resources/features/policy/api/POST.feature new file mode 100644 index 0000000000000000000000000000000000000000..cd73e6bfcdfedfc2a7e2eda0e8e0a091a7d146e2 --- /dev/null +++ b/src/test/resources/features/policy/api/POST.feature @@ -0,0 +1,29 @@ +#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/policy +#Author: Rosen Georgiev rosen.georgiev@vereign.com + +@rest @all +Feature: API - TSA - policy POST + Add a new policy + + Background: + Given we are testing the TSA Policy Api Api + + @policy @test + Scenario: TSA - Adding a new Policy - Positive +#Send Batch + And I clear the request body \ No newline at end of file