aboutsummaryrefslogtreecommitdiffstats
path: root/vnfmarket-be/vnf-sdk-marketplace/src
diff options
context:
space:
mode:
authorKanagaraj Manickam <kanagaraj.manickam@huawei.com>2020-09-10 06:34:16 +0000
committerGerrit Code Review <gerrit@onap.org>2020-09-10 06:34:16 +0000
commit19f97800c3fbcc9a1f845b9a8e9fee6f3f6400f7 (patch)
treefedb1c193dba58866ebdfd22ebf716e97938b3a3 /vnfmarket-be/vnf-sdk-marketplace/src
parentc25bb0be5f2d0358f094fd5ce294ca046882c981 (diff)
parent5fd768b457c0ec2eaf75963681fe7fcd1e69ae4e (diff)
Merge "Add list of errors in responce for GET request."
Diffstat (limited to 'vnfmarket-be/vnf-sdk-marketplace/src')
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java13
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResultsSupplier.java85
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPExecutionResourceTest.java276
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/execution/VTPExecutionResultsSupplierTest.java88
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/test/resources/executions/test-01-request-id-execution-id-data/output6
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/test/resources/executions/test-incorrect-request-id-execution-id-data/output1
6 files changed, 439 insertions, 30 deletions
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java
index 3bd522ff..2b06fe8f 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java
@@ -1,5 +1,6 @@
/**
* Copyright 2018 Huawei Technologies Co., Ltd.
+ * Copyright 2020 Nokia.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -87,8 +88,9 @@ public class VTPExecutionResource extends VTPResource{
private static final String PRODUCT_ARG="--product";
private static final String OPEN_CLI="open-cli";
private static final String FORMAT="--format";
+ private static final Gson gson = new Gson();
- private static Gson gson = new Gson();
+ protected static String pathToExecutions = "/opt/vtp/data/executions/";
public VTPTestExecutionList executeHandler(VTPTestExecutionList executions, String requestId) throws VTPException {
if (requestId == null) {
@@ -295,8 +297,13 @@ public class VTPExecutionResource extends VTPResource{
if (n.get(END_TIME) != null)
exec.setEndTime(n.get(END_TIME).getAsString());
- if (n.get(EXECUTION_ID) != null)
+ if (n.get(EXECUTION_ID) != null) {
exec.setExecutionId(n.get(EXECUTION_ID).getAsString());
+ exec.setResults(
+ new VTPExecutionResultsSupplier(pathToExecutions)
+ .getExecutionOutputsFromFile(exec.getExecutionId())
+ );
+ }
if (n.get(REQUEST_ID) != null)
exec.setRequestId(n.get(REQUEST_ID).getAsString());
@@ -316,6 +323,7 @@ public class VTPExecutionResource extends VTPResource{
if (n.get(STATUS) != null)
exec.setStatus(n.get(STATUS).getAsString());
+
list.getExecutions().add(exec);
}
@@ -325,6 +333,7 @@ public class VTPExecutionResource extends VTPResource{
return list;
}
+
@Path("/executions")
@GET
@ApiOperation(tags = "VTP Execution", value = " List test executions", response = VTPTestExecution.class, responseContainer = "List")
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResultsSupplier.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResultsSupplier.java
new file mode 100644
index 00000000..3f1e4c57
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResultsSupplier.java
@@ -0,0 +1,85 @@
+/**
+ * Copyright 2020 Nokia.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vtp.execution;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Optional;
+
+public class VTPExecutionResultsSupplier {
+
+ public static final Logger logger = LoggerFactory.getLogger(VTPExecutionResultsSupplier.class);
+
+ private static final String SUB_PATH_TO_EXECUTION_OUTPUT = "/output";
+ private static final Gson gson = new Gson();
+
+ protected String pathToExecutions;
+
+ VTPExecutionResultsSupplier(String pathToExecutions) {
+ this.pathToExecutions = pathToExecutions;
+ }
+
+ public JsonElement getExecutionOutputsFromFile(String executionId) {
+ File directoryWithExecutionFiles = new File(pathToExecutions);
+ return getExecutionFilesForGivenRequest(executionId, directoryWithExecutionFiles)
+ .map(this::getOutputOfLatestExecutionFile)
+ .orElse(createNoOutputFileErrorMessageInJsonFormat());
+ }
+
+ private Optional<File[]> getExecutionFilesForGivenRequest(String requestId, File directoryWithExecutionsData) {
+ return Optional.ofNullable(
+ directoryWithExecutionsData.listFiles((dir, name) -> name.startsWith(requestId))
+ );
+ }
+
+ private JsonElement getOutputOfLatestExecutionFile(File[] directoriesWithExecutionsData) {
+ return Arrays.stream(directoriesWithExecutionsData)
+ .max(Comparator.comparing(File::lastModified))
+ .map(file -> new File(file.getAbsolutePath() + SUB_PATH_TO_EXECUTION_OUTPUT))
+ .filter(File::exists)
+ .map(this::loadOutputJsonFromFile)
+ .orElse(createNoOutputFileErrorMessageInJsonFormat());
+ }
+
+ private JsonArray loadOutputJsonFromFile(File file) {
+ JsonArray outputJson;
+ try {
+ String executionResult = Files.readString(file.toPath());
+ outputJson = gson.fromJson(executionResult, JsonArray.class);
+ } catch (IOException | JsonParseException e) {
+ logger.error(e.getMessage(),e);
+ String errorMessage = "" +
+ "[{ \"error\": \"fail to load execution result\",\"reason\":\"" + e.getMessage() + "\"}]";
+ outputJson = gson.fromJson(errorMessage, JsonArray.class);
+ }
+ return outputJson;
+ }
+
+ private JsonArray createNoOutputFileErrorMessageInJsonFormat() {
+ return gson.fromJson("[{ \"error\": \"unable to find execution results\"}]", JsonArray.class);
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPExecutionResourceTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPExecutionResourceTest.java
index c1a28303..1a3200ab 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPExecutionResourceTest.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPExecutionResourceTest.java
@@ -1,5 +1,6 @@
/**
* Copyright 2019 Huawei Technologies Co., Ltd.
+ * Copyright 2020 Nokia.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,37 +16,66 @@
*/
package org.onap.vtp;
+import com.google.common.collect.Lists;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import org.glassfish.jersey.media.multipart.ContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.vtp.error.VTPError;
import org.onap.vtp.execution.VTPExecutionResource;
import org.onap.vtp.execution.model.VTPTestExecution;
-import org.open.infc.grpc.Result;
import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
@RunWith(MockitoJUnitRunner.class)
public class VTPExecutionResourceTest {
+ static class VTPExecutionResourceForTests extends VTPExecutionResource {
+ public JsonElement expectedRpcResponse = null;
+ public List<String> expectedArguments = null;
+
+ VTPExecutionResourceForTests() {
+ VTPExecutionResource.pathToExecutions = "src/test/resources/executions";
+ }
+
+ @Override
+ protected JsonElement makeRpcAndGetJson(List<String> args, int timeout) throws VTPError.VTPException {
+ if(expectedRpcResponse != null && expectedArguments != null) {
+ if (args.containsAll(expectedArguments)) {
+ return expectedRpcResponse;
+ } else {
+ return null;
+ }
+ } else {
+ return super.makeRpcAndGetJson( args, timeout);
+ }
+ }
+ }
+
@Mock
FormDataBodyPart formDataBodyPart;
@Mock
ContentDisposition contentDisposition;
String requestId;
- VTPExecutionResource vtpExecutionResource;
+ VTPExecutionResourceForTests vtpExecutionResource;
@Before
- public void setUp() throws Exception {
- vtpExecutionResource= new VTPExecutionResource();
+ public void setUp() {
+ vtpExecutionResource= new VTPExecutionResourceForTests();
requestId = UUID.randomUUID().toString();
}
@Test(expected = Exception.class)
@@ -74,31 +104,221 @@ public class VTPExecutionResourceTest {
System.out.println(executions.getExecutions());
assertNotNull(executions.getExecutions());
vtpExecutionResource.executeHandler(executions,null);
- //vtpExecutionResource.executeHandler(executions,requestId);
- //for handler
}
- @Test(expected = Exception.class)
- public void testListTestExecutionsHandler() throws Exception
- {
- vtpExecutionResource.listTestExecutionsHandler(requestId,"VTP Scenario 1","testsuite-1","s1.ts1.testcase-1","open-cli-schema","2019-03-12T11:49:52.845","2020-03-12T11:49:52.845");
- }
-//
-// @Test
-// public void testListTestExecutionsHandler1() throws Exception
-// { VTPExecutionResource vtpExecutionResource1=mock(VTPExecutionResource.class);
-// List<String> list= new ArrayList<>();
-// list.add("abc");
-// Result result= Result.getDefaultInstance();
-//
-// when(vtpExecutionResource1.makeRpc(list)).thenReturn(result);
-// verify(vtpExecutionResource1).makeRpc(list);
-//
-// }
+
+ @Test
+ public void whenListTestExecutionsHandlerIsCalledWithProperParametersThenCorrectExecutionDataIsReturned()
+ throws IOException, VTPError.VTPException {
+ // given
+ String testStartTime = "2019-03-12T11:49:52.845";
+ String testEndTime = "2020-03-12T11:49:52.845";
+ String testProduct = "VTP Scenario 1";
+ String testCommand = "s1.ts1.testcase-1";
+ String testSuiteName = "testsuite-1";
+ String testRequestId = "test-01-request-id";
+ String testExecutionId = testRequestId + "-execution-id";
+ String testProfile = "open-cli-schema";
+ String expectedStatus = "SUCCESS";
+ JsonElement expectedResult = new Gson().fromJson("" +
+ "[{" +
+ "\"test_1\": \"error01\"," +
+ "\"test_2\": \"error02\" " +
+ "}]", JsonArray.class);
+
+ prepareMockRpcMethods(
+ testStartTime, testEndTime, testProduct, testCommand, testSuiteName,
+ testRequestId, testExecutionId, testProfile, expectedStatus
+ );
+
+ // when
+ VTPTestExecution.VTPTestExecutionList testExecutionResponse =
+ vtpExecutionResource.listTestExecutionsHandler(
+ testRequestId, testProduct, testSuiteName, testCommand, testProfile, testStartTime, testEndTime
+ );
+
+ // then
+ assertThatListOfExecutionsContainsOneCorrectExecutionResponse(
+ testExecutionResponse,
+ testStartTime, testEndTime, testProduct, testCommand, testSuiteName,
+ testRequestId, testExecutionId, testProfile, expectedStatus, expectedResult
+ );
+ }
+
+ @Test
+ public void whenListTestExecutionsHandlerIsCalledWithIdThatDoesNotMatchAnyExecutionFileThenResultContainsProperInformation()
+ throws IOException, VTPError.VTPException {
+ // given
+ String testStartTime = "2020-08-09T08:49:52.845";
+ String testEndTime = "2020-08-10T08:49:55.845";
+ String testProduct = "VTP Scenario 2";
+ String testCommand = "s1.ts1.testcase-2";
+ String testSuiteName = "testsuite-2";
+ String testRequestId = "test-02-request-id";
+ String testExecutionId = testRequestId + "-execution-id";
+ String testProfile = "open-cli-schema";
+ String expectedStatus = "FAIL";
+ JsonElement expectedResult = new Gson().fromJson("" +
+ "[{ \"error\": \"unable to find execution results\"}]", JsonArray.class);
+
+ prepareMockRpcMethods(
+ testStartTime, testEndTime, testProduct, testCommand, testSuiteName,
+ testRequestId, testExecutionId, testProfile, expectedStatus
+ );
+
+ // when
+ VTPTestExecution.VTPTestExecutionList testExecutionResponse =
+ vtpExecutionResource.listTestExecutionsHandler(
+ testRequestId, testProduct, testSuiteName, testCommand, testProfile, testStartTime, testEndTime
+ );
+
+ // then
+ assertThatListOfExecutionsContainsOneCorrectExecutionResponse(
+ testExecutionResponse,
+ testStartTime, testEndTime, testProduct, testCommand, testSuiteName,
+ testRequestId, testExecutionId, testProfile, expectedStatus, expectedResult
+ );
+ }
+
+ @Test
+ public void whenListTestExecutionsHandlerIsCalledWithIdThatMatchIncorrectExecutionFileThenResultContainsProperInformation()
+ throws IOException, VTPError.VTPException {
+ // given
+ String testStartTime = "2020-08-09T08:49:52.845";
+ String testEndTime = "2020-08-10T08:49:55.845";
+ String testProduct = "VTP Scenario 3";
+ String testCommand = "s1.ts1.testcase-3";
+ String testSuiteName = "testsuite-3";
+ String testRequestId = "test-incorrect-request-id";
+ String testExecutionId = testRequestId + "-execution-id";
+ String testProfile = "open-cli-schema";
+ String expectedStatus = "FAIL";
+ JsonElement expectedResult = new Gson().fromJson("" +
+ "[{ " +
+ "\"error\": \"fail to load execution result\"," +
+ "\"reason\":\"Expected a com.google.gson.JsonArray but was com.google.gson.JsonPrimitive\"" +
+ "}]",
+ JsonArray.class
+ );
+
+ prepareMockRpcMethods(
+ testStartTime, testEndTime, testProduct, testCommand, testSuiteName,
+ testRequestId, testExecutionId, testProfile, expectedStatus
+ );
+
+ // when
+ VTPTestExecution.VTPTestExecutionList testExecutionResponse =
+ vtpExecutionResource.listTestExecutionsHandler(
+ testRequestId, testProduct, testSuiteName, testCommand, testProfile, testStartTime, testEndTime
+ );
+
+ // then
+ assertThatListOfExecutionsContainsOneCorrectExecutionResponse(
+ testExecutionResponse,
+ testStartTime, testEndTime, testProduct, testCommand, testSuiteName,
+ testRequestId, testExecutionId, testProfile, expectedStatus, expectedResult
+ );
+ }
+
+ @Rule
+ public ExpectedException exceptionRule = ExpectedException.none();
+
+ @Test
+ public void whenListTestExecutionsHandlerIsCalledAndGRpcClientIsUnReachableThenExceptionShouldBeThrown()
+ throws IOException, VTPError.VTPException {
+ // given
+ String testStartTime = "2020-08-10T08:50:20.845";
+ String testEndTime = "2020-08-11T08:51:50.845";
+ String testProduct = "VTP Scenario 3";
+ String testCommand = "s1.ts1.testcase-3";
+ String testSuiteName = "testsuite-3";
+ String testRequestId = "test-03-request-id";
+ String testProfile = "open-cli-schema";
+
+ // when
+ exceptionRule.expect(VTPError.VTPException.class);
+ exceptionRule.expectMessage("Timed out. Please use request-id to track the progress.");
+ vtpExecutionResource.listTestExecutionsHandler(
+ testRequestId, testProduct, testSuiteName, testCommand, testProfile, testStartTime, testEndTime
+ );
+
+ }
+
+ private void assertThatListOfExecutionsContainsOneCorrectExecutionResponse(
+ VTPTestExecution.VTPTestExecutionList testExecutionResponse,
+ String testStartTime, String testEndTime, String testProduct, String testCommand,
+ String testSuiteName, String testRequestId, String testExecutionId, String testProfile,
+ String expectedStatus, JsonElement expectedResult ) {
+
+ assertNotNull(testExecutionResponse);
+ assertEquals(1, testExecutionResponse.getExecutions().size());
+ VTPTestExecution vtpTestExecution = testExecutionResponse.getExecutions().get(0);
+ assertFieldsInExecutionResponseAreCorrect(
+ vtpTestExecution,
+ testStartTime, testEndTime, testProduct, testCommand, testSuiteName,
+ testRequestId, testExecutionId, testProfile, expectedStatus, expectedResult
+ );
+ }
+
+ private void prepareMockRpcMethods(String testStartTime, String testEndTime, String testProduct, String testCommand, String testSuiteName, String testRequestId, String testExecutionId, String testProfile, String expectedStatus) {
+ vtpExecutionResource.expectedArguments =
+ buildListOfMockRpcArguments(
+ testStartTime, testEndTime, testProduct, testCommand, testRequestId, testSuiteName
+ );
+ vtpExecutionResource.expectedRpcResponse =
+ buildExpectedRpcResponse(
+ testStartTime, testEndTime, testProduct, testCommand, testSuiteName, testRequestId,
+ testExecutionId, testProfile, expectedStatus
+ );
+ }
+
+ private JsonArray buildExpectedRpcResponse(
+ String testStartTime, String testEndTime, String testProduct,
+ String testCommand, String testSuiteName, String testRequestId,
+ String testExecutionId, String testProfile, String expectedStatus) {
+ return new Gson().fromJson("[{" +
+ "\"start-time\":\"" + testStartTime + "\";" +
+ "\"end-time\":\"" + testEndTime + "\";" +
+ "\"product\":\"" + testProduct + "\";" +
+ "\"command\":\"" + testCommand + "\";" +
+ "\"service\":\"" + testSuiteName + "\";" +
+ "\"request-id\":\"" + testRequestId + "\";" +
+ "\"execution-id\":\"" + testExecutionId + "\";" +
+ "\"profile\":\"" + testProfile + "\";" +
+ "\"status\":\"" + expectedStatus + "\"" +
+ "}]", JsonArray.class);
+ }
+
+ private List<String> buildListOfMockRpcArguments(
+ String testStartTime, String testEndTime, String testProduct,
+ String testCommand, String testRequestId, String testSuiteName) {
+ return Lists.newArrayList(
+ "--product", "open-cli", "execution-list", "--format", "json",
+ "--start-time", testStartTime, "--end-time", testEndTime,
+ "--service", testSuiteName, "--product", testProduct,
+ "--command", testCommand, "--request-id", testRequestId);
+ }
+
+ private void assertFieldsInExecutionResponseAreCorrect(
+ VTPTestExecution vtpTestExecution,
+ String testStartTime, String testEndTime, String testProduct,
+ String testCommand, String testSuiteName, String testRequestId,
+ String testExecutionId, String testProfile, String expectedStatus, JsonElement expectedResult) {
+ assertEquals(testStartTime, vtpTestExecution.getStartTime());
+ assertEquals(testEndTime, vtpTestExecution.getEndTime());
+ assertEquals(testProduct, vtpTestExecution.getScenario());
+ assertEquals(testCommand, vtpTestExecution.getTestCaseName());
+ assertEquals(testSuiteName, vtpTestExecution.getTestSuiteName());
+ assertEquals(testExecutionId, vtpTestExecution.getExecutionId());
+ assertEquals(testRequestId, vtpTestExecution.getRequestId());
+ assertEquals(testProfile, vtpTestExecution.getProfile());
+ assertEquals(expectedStatus, vtpTestExecution.getStatus());
+ assertEquals(expectedResult, vtpTestExecution.getResults());
+ }
@Test(expected = Exception.class)
public void testListTestExecutions() throws Exception
{
- vtpExecutionResource.listTestExecutions(requestId,"abc","abc","abc","abc","123","123");
+ vtpExecutionResource.listTestExecutions(requestId, "abc", "abc", "abc", "abc", "123", "123");
}
@Test(expected = Exception.class)
public void testGetTestExecution() throws Exception
@@ -130,4 +350,4 @@ public class VTPExecutionResourceTest {
public void testGetTestExecutionLogsHandler() throws Exception {
assertNotNull(vtpExecutionResource.getTestExecutionLogsHandler("1234", "action"));
}
-} \ No newline at end of file
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/execution/VTPExecutionResultsSupplierTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/execution/VTPExecutionResultsSupplierTest.java
new file mode 100644
index 00000000..7be8a7d4
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/execution/VTPExecutionResultsSupplierTest.java
@@ -0,0 +1,88 @@
+/**
+ * Copyright 2020 Nokia.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.vtp.execution;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class VTPExecutionResultsSupplierTest {
+
+ private static final String TEST_PATH_TO_EXECUTION = "src/test/resources/executions";
+
+ @Test
+ public void whenGetExecutionOutputsFromFileIsCalledWithPathToCorrectFileThenContentShouldBeLoadedAsJson() {
+ // given
+ VTPExecutionResultsSupplier vtpExecutionResultsSupplier =
+ new VTPExecutionResultsSupplier(TEST_PATH_TO_EXECUTION);
+ String pathToCorrectFile = "test-01-request-id-execution-id";
+ JsonElement expectedResult = new Gson().fromJson("" +
+ "[{" +
+ "\"test_1\": \"error01\"," +
+ "\"test_2\": \"error02\" " +
+ "}]", JsonArray.class);
+
+ // when
+ JsonElement executionOutputsFromFile =
+ vtpExecutionResultsSupplier.getExecutionOutputsFromFile(pathToCorrectFile);
+
+ // then
+ assertEquals(executionOutputsFromFile, expectedResult);
+ }
+
+ @Test
+ public void whenGetExecutionOutputsFromFileIsCalledWithPathToNonExistingFileThenProperMessageShouldBeReturned() {
+ // given
+ VTPExecutionResultsSupplier vtpExecutionResultsSupplier =
+ new VTPExecutionResultsSupplier(TEST_PATH_TO_EXECUTION);
+ String pathToCorrectFile = "test-02-request-id-execution-id";
+ JsonElement expectedErrorMessage = new Gson().fromJson("" +
+ "[{ \"error\": \"unable to find execution results\"}]", JsonArray.class);
+
+ // when
+ JsonElement executionOutputsFromFile =
+ vtpExecutionResultsSupplier.getExecutionOutputsFromFile(pathToCorrectFile);
+
+ // then
+ assertEquals(executionOutputsFromFile, expectedErrorMessage);
+ }
+
+ @Test
+ public void whenGetExecutionOutputsFromFileIsCalledWithPathToIncorrectFileThenProperMessageShouldBeReturned() {
+ // given
+ VTPExecutionResultsSupplier vtpExecutionResultsSupplier =
+ new VTPExecutionResultsSupplier(TEST_PATH_TO_EXECUTION);
+ String pathToCorrectFile = "test-incorrect-request-id-execution-id-data";
+ JsonElement expectedErrorMessage = new Gson().fromJson("" +
+ "[{ " +
+ "\"error\": \"fail to load execution result\"," +
+ "\"reason\":\"Expected a com.google.gson.JsonArray but was com.google.gson.JsonPrimitive\"" +
+ "}]",
+ JsonArray.class
+ );
+
+ // when
+ JsonElement executionOutputsFromFile =
+ vtpExecutionResultsSupplier.getExecutionOutputsFromFile(pathToCorrectFile);
+
+ // then
+ assertEquals(executionOutputsFromFile, expectedErrorMessage);
+ }
+}
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/resources/executions/test-01-request-id-execution-id-data/output b/vnfmarket-be/vnf-sdk-marketplace/src/test/resources/executions/test-01-request-id-execution-id-data/output
new file mode 100644
index 00000000..e52c4f4e
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/resources/executions/test-01-request-id-execution-id-data/output
@@ -0,0 +1,6 @@
+[
+ {
+ "test_1": "error01",
+ "test_2": "error02"
+ }
+]
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/resources/executions/test-incorrect-request-id-execution-id-data/output b/vnfmarket-be/vnf-sdk-marketplace/src/test/resources/executions/test-incorrect-request-id-execution-id-data/output
new file mode 100644
index 00000000..747c69b0
--- /dev/null
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/resources/executions/test-incorrect-request-id-execution-id-data/output
@@ -0,0 +1 @@
+wrong output, not a JSON