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 java.util.Arrays;
27 import java.util.List;
29 public class ApiTests {
31 private static final String EP = "ep";
32 private static final String EXEC = "exec";
33 private static final String SC = "sc";
34 private static final String TS = "ts";
35 private static final String TC = "tc";
36 private static final String EXPECTED = "Expected";
40 private ExternalTestingManager testingManager;
43 * At the API level, test that the code does not throw
44 * exceptions but there's not much to test.
47 public void testApi() {
48 MockitoAnnotations.initMocks(this);
50 ExternalTestingImpl testing = new ExternalTestingImpl(testingManager);
51 Assert.assertNotNull(testing.getConfig());
52 Assert.assertNotNull(testing.getEndpoints());
53 Assert.assertNotNull(testing.getExecution(EP, EXEC));
54 Assert.assertNotNull(testing.getScenarios(EP));
55 Assert.assertNotNull(testing.getTestcase(EP, SC, TS, TC));
56 Assert.assertNotNull(testing.getTestcases(EP, SC));
57 Assert.assertNotNull(testing.getTestsuites(EP, SC));
58 Assert.assertNotNull(testing.getTestCasesAsTree());
60 List<VtpTestExecutionRequest> requests =
61 Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest());
62 Assert.assertNotNull(testing.execute(requests, "requestId"));
65 class ApiTestExternalTestingManager implements ExternalTestingManager {
67 public ClientConfiguration getConfig() {
68 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
72 public ClientConfiguration setConfig(ClientConfiguration config) {
73 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
77 public List<RemoteTestingEndpointDefinition> setEndpoints(List<RemoteTestingEndpointDefinition> endpoints) {
78 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
82 public TestTreeNode getTestCasesAsTree() {
83 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
87 public List<RemoteTestingEndpointDefinition> getEndpoints() {
88 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
92 public List<VtpNameDescriptionPair> getScenarios(String endpoint) {
93 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
97 public List<VtpNameDescriptionPair> getTestSuites(String endpoint, String scenario) {
98 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
102 public List<VtpTestCase> getTestCases(String endpoint, String scenario) {
103 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
107 public VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName) {
108 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
112 public List<VtpTestExecutionResponse> execute(List<VtpTestExecutionRequest> requests, String requestId) {
113 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
117 public VtpTestExecutionResponse getExecution(String endpoint, String executionId) {
118 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
123 * Test the exception handler logic for the cases when the
124 * testing manager throws an exception.
127 public void testExceptions() {
128 MockitoAnnotations.initMocks(this);
130 ExternalTestingManager m = new ApiTestExternalTestingManager();
131 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
134 testingF.getConfig();
136 catch (Exception ex) {
142 testingF.getEndpoints();
144 catch (ExternalTestingException e) {
149 testingF.getExecution(EP, EXEC);
151 catch (ExternalTestingException e) {
155 testingF.getScenarios(EP);
157 catch (ExternalTestingException e) {
162 testingF.getTestcase(EP, SC, TS, TC);
164 catch (ExternalTestingException e) {
169 testingF.getTestcases(EP, SC);
171 catch (ExternalTestingException e) {
176 testingF.getTestsuites(EP, SC);
178 catch (ExternalTestingException e) {
183 testingF.getTestCasesAsTree();
185 catch (ExternalTestingException e) {
189 List<VtpTestExecutionRequest> requestsF =
190 Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest());
193 testingF.execute(requestsF, null);
195 catch (ExternalTestingException e) {
201 testingF.execute(requestsF, null);
203 catch (ExternalTestingException e) {