2 * Copyright © 2019 iconectiv
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.openecomp.sdcrests.externaltesting.rest.services;
20 import static org.mockito.MockitoAnnotations.openMocks;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.List;
26 import javax.ws.rs.core.Response;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mock;
31 import org.openecomp.core.externaltesting.api.ClientConfiguration;
32 import org.openecomp.core.externaltesting.api.ExternalTestingManager;
33 import org.openecomp.core.externaltesting.api.RemoteTestingEndpointDefinition;
34 import org.openecomp.core.externaltesting.api.TestTreeNode;
35 import org.openecomp.core.externaltesting.api.VtpNameDescriptionPair;
36 import org.openecomp.core.externaltesting.api.VtpTestCase;
37 import org.openecomp.core.externaltesting.api.VtpTestExecutionOutput;
38 import org.openecomp.core.externaltesting.api.VtpTestExecutionRequest;
39 import org.openecomp.core.externaltesting.api.VtpTestExecutionResponse;
40 import org.openecomp.core.externaltesting.errors.ExternalTestingException;
41 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
44 public class ApiTest {
46 private static final String EP = "ep";
47 private static final String EXEC = "exec";
48 private static final String SC = "sc";
49 private static final String TS = "ts";
50 private static final String TC = "tc";
51 private static final String EXPECTED = "Expected";
54 private ExternalTestingManager testingManager;
57 VendorSoftwareProductManager vendorSoftwareProductManager;
63 } catch (Exception e) {
70 * At the API level, test that the code does not throw
71 * exceptions but there's not much to test.
74 public void testApi() {
77 ExternalTestingImpl testing = new ExternalTestingImpl(testingManager, vendorSoftwareProductManager);
78 Assert.assertNotNull(testing.getConfig());
79 Assert.assertNotNull(testing.getEndpoints());
80 Assert.assertNotNull(testing.getExecution(EP, EXEC));
81 Assert.assertNotNull(testing.getScenarios(EP));
82 Assert.assertNotNull(testing.getTestcase(EP, SC, TS, TC));
83 Assert.assertNotNull(testing.getTestcases(EP, SC));
84 Assert.assertNotNull(testing.getTestsuites(EP, SC));
85 Assert.assertNotNull(testing.getTestCasesAsTree());
87 List<VtpTestExecutionRequest> requests =
88 Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest());
89 Assert.assertNotNull(testing.execute("vspId", "vspVersionId", "abc", null, "[]"));
92 ClientConfiguration cc = new ClientConfiguration();
93 Assert.assertNotNull(testing.setConfig(cc));
95 ArrayList<RemoteTestingEndpointDefinition> lst = new ArrayList<>();
96 Assert.assertNotNull(testing.setEndpoints(lst));
99 class ApiTestExternalTestingManager implements ExternalTestingManager {
102 public ClientConfiguration getConfig() {
103 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
107 public ClientConfiguration setConfig(ClientConfiguration config) {
108 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
112 public List<RemoteTestingEndpointDefinition> setEndpoints(List<RemoteTestingEndpointDefinition> endpoints) {
113 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
117 public TestTreeNode getTestCasesAsTree() {
118 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
122 public List<RemoteTestingEndpointDefinition> getEndpoints() {
123 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
127 public List<VtpNameDescriptionPair> getScenarios(String endpoint) {
128 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
132 public List<VtpNameDescriptionPair> getTestSuites(String endpoint, String scenario) {
133 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
137 public List<VtpTestCase> getTestCases(String endpoint, String scenario) {
138 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
142 public VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName) {
143 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
147 public List<VtpTestExecutionResponse> execute(List<VtpTestExecutionRequest> requests, String vspId,
148 String vspVersionId, String requestId, Map<String, byte[]> fileMap) {
150 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
154 public VtpTestExecutionResponse getExecution(String endpoint, String executionId) {
155 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
159 public List<VtpTestExecutionOutput> getExecutionIds(String endpoint, String requestId) {
160 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
166 * Test the exception handler logic for configuration get/set.
169 public void testConfigExceptions() {
172 ExternalTestingManager m = new ApiTestExternalTestingManager();
173 ExternalTestingImpl testingF = new ExternalTestingImpl(m, vendorSoftwareProductManager);
175 Response getResponse = testingF.getConfig();
176 Assert.assertEquals(500, getResponse.getStatus());
178 Response setResponse = testingF.setConfig(new ClientConfiguration());
179 Assert.assertEquals(500, setResponse.getStatus());
183 * Test the exception handler logic for endpoint get/set.
186 public void testEndpointExceptions() {
189 ExternalTestingManager m = new ApiTestExternalTestingManager();
190 ExternalTestingImpl testingF = new ExternalTestingImpl(m, vendorSoftwareProductManager);
192 Response getResponse = testingF.getEndpoints();
193 Assert.assertEquals(500, getResponse.getStatus());
195 Response setResponse = testingF.setEndpoints(new ArrayList<>());
196 Assert.assertEquals(500, setResponse.getStatus());
200 * Test the exception handler logic for executions (invocation and query).
203 public void testExecutionExceptions() {
206 ExternalTestingManager m = new ApiTestExternalTestingManager();
207 ExternalTestingImpl testingF = new ExternalTestingImpl(m, vendorSoftwareProductManager);
209 Response invokeResponse = testingF.execute("vspId", "vspVersionId", "abc", null, "[]");
210 Assert.assertEquals(500, invokeResponse.getStatus());
212 Response getResponse = testingF.getExecution(EP, EXEC);
213 Assert.assertEquals(500, getResponse.getStatus());
218 * Test the exception handler logic for the cases when the
219 * testing manager throws an accessing the scenarios.
222 public void testScenarioExceptions() {
225 ExternalTestingManager m = new ApiTestExternalTestingManager();
226 ExternalTestingImpl testingF = new ExternalTestingImpl(m, vendorSoftwareProductManager);
228 Response response = testingF.getScenarios(EP);
229 Assert.assertEquals(500, response.getStatus());
233 * Test the exception handler logic for the cases when the
234 * testing manager throws an accessing a test case.
237 public void testTestCaseExceptions() {
240 ExternalTestingManager m = new ApiTestExternalTestingManager();
241 ExternalTestingImpl testingF = new ExternalTestingImpl(m, vendorSoftwareProductManager);
243 Response response = testingF.getTestcase(EP, SC, TS, TC);
244 Assert.assertEquals(500, response.getStatus());
248 * Test the exception handler logic for the cases when the
249 * testing manager throws an accessing the test cases.
252 public void testTestCasesExceptions() {
255 ExternalTestingManager m = new ApiTestExternalTestingManager();
256 ExternalTestingImpl testingF = new ExternalTestingImpl(m, vendorSoftwareProductManager);
258 Response response = testingF.getTestcases(EP, SC);
259 Assert.assertEquals(500, response.getStatus());
263 * Test the exception handler logic for the cases when the
264 * testing manager throws an accessing the test suites.
267 public void testTestSuitesExceptions() {
270 ExternalTestingManager m = new ApiTestExternalTestingManager();
271 ExternalTestingImpl testingF = new ExternalTestingImpl(m, vendorSoftwareProductManager);
273 Response response = testingF.getTestsuites(EP, SC);
274 Assert.assertEquals(500, response.getStatus());
278 * Test the exception handler logic for the cases when the
279 * testing manager throws an accessing the test tree.
282 public void testTreeExceptions() {
285 ExternalTestingManager m = new ApiTestExternalTestingManager();
286 ExternalTestingImpl testingF = new ExternalTestingImpl(m, vendorSoftwareProductManager);
288 Response response = testingF.getTestCasesAsTree();
289 Assert.assertEquals(500, response.getStatus());