2 * Copyright 2020 Nokia.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vtp.execution;
19 import com.google.gson.Gson;
20 import com.google.gson.JsonArray;
21 import com.google.gson.JsonElement;
22 import org.junit.Test;
24 import static org.junit.Assert.assertEquals;
26 public class VTPExecutionResultsSupplierTest {
28 private static final String TEST_PATH_TO_EXECUTION = "src/test/resources/executions";
31 public void whenGetExecutionOutputsFromFileIsCalledWithPathToCorrectFileThenContentShouldBeLoadedAsJson() {
33 VTPExecutionResultsSupplier vtpExecutionResultsSupplier =
34 new VTPExecutionResultsSupplier(TEST_PATH_TO_EXECUTION);
35 String pathToCorrectFile = "test-01-request-id-execution-id";
36 JsonElement expectedResult = new Gson().fromJson("" +
38 "\"test_1\": \"error01\"," +
39 "\"test_2\": \"error02\" " +
40 "}]", JsonArray.class);
43 JsonElement executionOutputsFromFile =
44 vtpExecutionResultsSupplier.getExecutionOutputsFromFile(pathToCorrectFile);
47 assertEquals(executionOutputsFromFile, expectedResult);
51 public void whenGetExecutionOutputsFromFileIsCalledWithPathToNonExistingFileThenProperMessageShouldBeReturned() {
53 VTPExecutionResultsSupplier vtpExecutionResultsSupplier =
54 new VTPExecutionResultsSupplier(TEST_PATH_TO_EXECUTION);
55 String pathToCorrectFile = "test-02-request-id-execution-id";
56 JsonElement expectedErrorMessage = new Gson().fromJson("" +
57 "[{ \"error\": \"unable to find execution results\"}]", JsonArray.class);
60 JsonElement executionOutputsFromFile =
61 vtpExecutionResultsSupplier.getExecutionOutputsFromFile(pathToCorrectFile);
64 assertEquals(executionOutputsFromFile, expectedErrorMessage);
68 public void whenGetExecutionOutputsFromFileIsCalledWithPathToIncorrectFileThenProperMessageShouldBeReturned() {
70 VTPExecutionResultsSupplier vtpExecutionResultsSupplier =
71 new VTPExecutionResultsSupplier(TEST_PATH_TO_EXECUTION);
72 String pathToCorrectFile = "test-incorrect-request-id-execution-id-data";
73 JsonElement expectedErrorMessage = new Gson().fromJson("" +
75 "\"error\": \"fail to load execution result\"," +
76 "\"reason\":\"Expected a com.google.gson.JsonArray but was com.google.gson.JsonPrimitive\"" +
82 JsonElement executionOutputsFromFile =
83 vtpExecutionResultsSupplier.getExecutionOutputsFromFile(pathToCorrectFile);
86 assertEquals(executionOutputsFromFile, expectedErrorMessage);