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 org.junit.Assert;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.openecomp.core.externaltesting.api.*;
24 import org.openecomp.core.externaltesting.errors.ExternalTestingException;
26 import javax.ws.rs.core.Response;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.List;
31 public class ApiTest {
33 private static final String EP = "ep";
34 private static final String EXEC = "exec";
35 private static final String SC = "sc";
36 private static final String TS = "ts";
37 private static final String TC = "tc";
38 private static final String EXPECTED = "Expected";
42 private ExternalTestingManager testingManager;
45 * At the API level, test that the code does not throw
46 * exceptions but there's not much to test.
49 public void testApi() {
50 MockitoAnnotations.initMocks(this);
52 ExternalTestingImpl testing = new ExternalTestingImpl(testingManager);
53 Assert.assertNotNull(testing.getConfig());
54 Assert.assertNotNull(testing.getEndpoints());
55 Assert.assertNotNull(testing.getExecution(EP, EXEC));
56 Assert.assertNotNull(testing.getScenarios(EP));
57 Assert.assertNotNull(testing.getTestcase(EP, SC, TS, TC));
58 Assert.assertNotNull(testing.getTestcases(EP, SC));
59 Assert.assertNotNull(testing.getTestsuites(EP, SC));
60 Assert.assertNotNull(testing.getTestCasesAsTree());
62 List<VtpTestExecutionRequest> requests =
63 Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest());
64 Assert.assertNotNull(testing.execute(requests, "requestId"));
67 ClientConfiguration cc = new ClientConfiguration();
68 Assert.assertNotNull(testing.setConfig(cc));
70 ArrayList<RemoteTestingEndpointDefinition> lst = new ArrayList<>();
71 Assert.assertNotNull(testing.setEndpoints(lst));
74 class ApiTestExternalTestingManager implements ExternalTestingManager {
76 public ClientConfiguration getConfig() {
77 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
81 public ClientConfiguration setConfig(ClientConfiguration config) {
82 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
86 public List<RemoteTestingEndpointDefinition> setEndpoints(List<RemoteTestingEndpointDefinition> endpoints) {
87 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
91 public TestTreeNode getTestCasesAsTree() {
92 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
96 public List<RemoteTestingEndpointDefinition> getEndpoints() {
97 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
101 public List<VtpNameDescriptionPair> getScenarios(String endpoint) {
102 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
106 public List<VtpNameDescriptionPair> getTestSuites(String endpoint, String scenario) {
107 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
111 public List<VtpTestCase> getTestCases(String endpoint, String scenario) {
112 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
116 public VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName) {
117 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
121 public List<VtpTestExecutionResponse> execute(List<VtpTestExecutionRequest> requests, String requestId) {
122 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
126 public VtpTestExecutionResponse getExecution(String endpoint, String executionId) {
127 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
132 * Test the exception handler logic for configuration get/set.
135 public void testConfigExceptions() {
136 MockitoAnnotations.initMocks(this);
138 ExternalTestingManager m = new ApiTestExternalTestingManager();
139 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
141 Response getResponse = testingF.getConfig();
142 Assert.assertEquals(500, getResponse.getStatus());
144 Response setResponse = testingF.setConfig(new ClientConfiguration());
145 Assert.assertEquals(500, setResponse.getStatus());
149 * Test the exception handler logic for endpoint get/set.
152 public void testEndpointExceptions() {
153 MockitoAnnotations.initMocks(this);
155 ExternalTestingManager m = new ApiTestExternalTestingManager();
156 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
158 Response getResponse = testingF.getEndpoints();
159 Assert.assertEquals(500, getResponse.getStatus());
161 Response setResponse = testingF.setEndpoints(new ArrayList<>());
162 Assert.assertEquals(500, setResponse.getStatus());
166 * Test the exception handler logic for executions (invocation and query).
169 public void testExecutionExceptions() {
170 MockitoAnnotations.initMocks(this);
172 ExternalTestingManager m = new ApiTestExternalTestingManager();
173 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
175 List<VtpTestExecutionRequest> requests =
176 Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest());
178 Response invokeResponse = testingF.execute(requests, null);
179 Assert.assertEquals(500, invokeResponse.getStatus());
181 Response getResponse = testingF.getExecution(EP, EXEC);
182 Assert.assertEquals(500, getResponse.getStatus());
187 * Test the exception handler logic for the cases when the
188 * testing manager throws an accessing the scenarios.
191 public void testScenarioExceptions() {
192 MockitoAnnotations.initMocks(this);
194 ExternalTestingManager m = new ApiTestExternalTestingManager();
195 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
197 Response response = testingF.getScenarios(EP);
198 Assert.assertEquals(500, response.getStatus());
202 * Test the exception handler logic for the cases when the
203 * testing manager throws an accessing a test case.
206 public void testTestCaseExceptions() {
207 MockitoAnnotations.initMocks(this);
209 ExternalTestingManager m = new ApiTestExternalTestingManager();
210 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
212 Response response = testingF.getTestcase(EP, SC, TS, TC);
213 Assert.assertEquals(500, response.getStatus());
217 * Test the exception handler logic for the cases when the
218 * testing manager throws an accessing the test cases.
221 public void testTestCasesExceptions() {
222 MockitoAnnotations.initMocks(this);
224 ExternalTestingManager m = new ApiTestExternalTestingManager();
225 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
227 Response response = testingF.getTestcases(EP, SC);
228 Assert.assertEquals(500, response.getStatus());
232 * Test the exception handler logic for the cases when the
233 * testing manager throws an accessing the test suites.
236 public void testTestSuitesExceptions() {
237 MockitoAnnotations.initMocks(this);
239 ExternalTestingManager m = new ApiTestExternalTestingManager();
240 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
242 Response response = testingF.getTestsuites(EP, SC);
243 Assert.assertEquals(500, response.getStatus());
247 * Test the exception handler logic for the cases when the
248 * testing manager throws an accessing the test tree.
251 public void testTreeExceptions() {
252 MockitoAnnotations.initMocks(this);
254 ExternalTestingManager m = new ApiTestExternalTestingManager();
255 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
257 Response response = testingF.getTestCasesAsTree();
258 Assert.assertEquals(500, response.getStatus());