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;
19 import static org.mockito.Mockito.when;
20 import static org.mockito.MockitoAnnotations.initMocks;
21 import static org.powermock.api.mockito.PowerMockito.mockStatic;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.List;
27 import javax.ws.rs.core.Response;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.openecomp.core.externaltesting.api.ClientConfiguration;
34 import org.openecomp.core.externaltesting.api.ExternalTestingManager;
35 import org.openecomp.core.externaltesting.api.RemoteTestingEndpointDefinition;
36 import org.openecomp.core.externaltesting.api.TestTreeNode;
37 import org.openecomp.core.externaltesting.api.VtpNameDescriptionPair;
38 import org.openecomp.core.externaltesting.api.VtpTestCase;
39 import org.openecomp.core.externaltesting.api.VtpTestExecutionOutput;
40 import org.openecomp.core.externaltesting.api.VtpTestExecutionRequest;
41 import org.openecomp.core.externaltesting.api.VtpTestExecutionResponse;
42 import org.openecomp.core.externaltesting.errors.ExternalTestingException;
43 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
44 import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory;
45 import org.powermock.core.classloader.annotations.PrepareForTest;
46 import org.powermock.modules.junit4.PowerMockRunner;
48 @RunWith(PowerMockRunner.class)
49 @PrepareForTest({VspManagerFactory.class})
50 public class ApiTest {
52 private static final String EP = "ep";
53 private static final String EXEC = "exec";
54 private static final String SC = "sc";
55 private static final String TS = "ts";
56 private static final String TC = "tc";
57 private static final String EXPECTED = "Expected";
60 private ExternalTestingManager testingManager;
62 private VspManagerFactory vspManagerFactory;
64 VendorSoftwareProductManager vendorSoftwareProductManager;
70 mockStatic(VspManagerFactory.class);
71 when(VspManagerFactory.getInstance()).thenReturn(vspManagerFactory);
72 when(vspManagerFactory.createInterface()).thenReturn(vendorSoftwareProductManager);
73 when(vspManagerFactory.getInstance().createInterface()).thenReturn(vendorSoftwareProductManager);
74 } catch (Exception e) {
81 * At the API level, test that the code does not throw
82 * exceptions but there's not much to test.
85 public void testApi() {
88 ExternalTestingImpl testing = new ExternalTestingImpl(testingManager);
89 Assert.assertNotNull(testing.getConfig());
90 Assert.assertNotNull(testing.getEndpoints());
91 Assert.assertNotNull(testing.getExecution(EP, EXEC));
92 Assert.assertNotNull(testing.getScenarios(EP));
93 Assert.assertNotNull(testing.getTestcase(EP, SC, TS, TC));
94 Assert.assertNotNull(testing.getTestcases(EP, SC));
95 Assert.assertNotNull(testing.getTestsuites(EP, SC));
96 Assert.assertNotNull(testing.getTestCasesAsTree());
98 List<VtpTestExecutionRequest> requests =
99 Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest());
100 Assert.assertNotNull(testing.execute("vspId", "vspVersionId", "abc", null, "[]"));
103 ClientConfiguration cc = new ClientConfiguration();
104 Assert.assertNotNull(testing.setConfig(cc));
106 ArrayList<RemoteTestingEndpointDefinition> lst = new ArrayList<>();
107 Assert.assertNotNull(testing.setEndpoints(lst));
110 class ApiTestExternalTestingManager implements ExternalTestingManager {
113 public ClientConfiguration getConfig() {
114 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
118 public ClientConfiguration setConfig(ClientConfiguration config) {
119 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
123 public List<RemoteTestingEndpointDefinition> setEndpoints(List<RemoteTestingEndpointDefinition> endpoints) {
124 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
128 public TestTreeNode getTestCasesAsTree() {
129 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
133 public List<RemoteTestingEndpointDefinition> getEndpoints() {
134 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
138 public List<VtpNameDescriptionPair> getScenarios(String endpoint) {
139 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
143 public List<VtpNameDescriptionPair> getTestSuites(String endpoint, String scenario) {
144 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
148 public List<VtpTestCase> getTestCases(String endpoint, String scenario) {
149 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
153 public VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName) {
154 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
158 public List<VtpTestExecutionResponse> execute(List<VtpTestExecutionRequest> requests, String vspId,
159 String vspVersionId, String requestId, Map<String, byte[]> fileMap) {
161 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
165 public VtpTestExecutionResponse getExecution(String endpoint, String executionId) {
166 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
170 public List<VtpTestExecutionOutput> getExecutionIds(String endpoint, String requestId) {
171 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
177 * Test the exception handler logic for configuration get/set.
180 public void testConfigExceptions() {
183 ExternalTestingManager m = new ApiTestExternalTestingManager();
184 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
186 Response getResponse = testingF.getConfig();
187 Assert.assertEquals(500, getResponse.getStatus());
189 Response setResponse = testingF.setConfig(new ClientConfiguration());
190 Assert.assertEquals(500, setResponse.getStatus());
194 * Test the exception handler logic for endpoint get/set.
197 public void testEndpointExceptions() {
200 ExternalTestingManager m = new ApiTestExternalTestingManager();
201 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
203 Response getResponse = testingF.getEndpoints();
204 Assert.assertEquals(500, getResponse.getStatus());
206 Response setResponse = testingF.setEndpoints(new ArrayList<>());
207 Assert.assertEquals(500, setResponse.getStatus());
211 * Test the exception handler logic for executions (invocation and query).
214 public void testExecutionExceptions() {
217 ExternalTestingManager m = new ApiTestExternalTestingManager();
218 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
220 Response invokeResponse = testingF.execute("vspId", "vspVersionId", "abc", null, "[]");
221 Assert.assertEquals(500, invokeResponse.getStatus());
223 Response getResponse = testingF.getExecution(EP, EXEC);
224 Assert.assertEquals(500, getResponse.getStatus());
229 * Test the exception handler logic for the cases when the
230 * testing manager throws an accessing the scenarios.
233 public void testScenarioExceptions() {
236 ExternalTestingManager m = new ApiTestExternalTestingManager();
237 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
239 Response response = testingF.getScenarios(EP);
240 Assert.assertEquals(500, response.getStatus());
244 * Test the exception handler logic for the cases when the
245 * testing manager throws an accessing a test case.
248 public void testTestCaseExceptions() {
251 ExternalTestingManager m = new ApiTestExternalTestingManager();
252 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
254 Response response = testingF.getTestcase(EP, SC, TS, TC);
255 Assert.assertEquals(500, response.getStatus());
259 * Test the exception handler logic for the cases when the
260 * testing manager throws an accessing the test cases.
263 public void testTestCasesExceptions() {
266 ExternalTestingManager m = new ApiTestExternalTestingManager();
267 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
269 Response response = testingF.getTestcases(EP, SC);
270 Assert.assertEquals(500, response.getStatus());
274 * Test the exception handler logic for the cases when the
275 * testing manager throws an accessing the test suites.
278 public void testTestSuitesExceptions() {
281 ExternalTestingManager m = new ApiTestExternalTestingManager();
282 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
284 Response response = testingF.getTestsuites(EP, SC);
285 Assert.assertEquals(500, response.getStatus());
289 * Test the exception handler logic for the cases when the
290 * testing manager throws an accessing the test tree.
293 public void testTreeExceptions() {
296 ExternalTestingManager m = new ApiTestExternalTestingManager();
297 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
299 Response response = testingF.getTestCasesAsTree();
300 Assert.assertEquals(500, response.getStatus());