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 String getConfig() {
68 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
72 public TestTreeNode getTestCasesAsTree() {
73 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
77 public List<VtpNameDescriptionPair> getEndpoints() {
78 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
82 public List<VtpNameDescriptionPair> getScenarios(String endpoint) {
83 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
87 public List<VtpNameDescriptionPair> getTestSuites(String endpoint, String scenario) {
88 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
92 public List<VtpTestCase> getTestCases(String endpoint, String scenario) {
93 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
97 public VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName) {
98 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
102 public List<VtpTestExecutionResponse> execute(List<VtpTestExecutionRequest> requests, String requestId) {
103 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
107 public VtpTestExecutionResponse getExecution(String endpoint, String executionId) {
108 throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
113 * Test the exception handler logic for the cases when the
114 * testing manager throws an exception.
117 public void testExceptions() {
118 MockitoAnnotations.initMocks(this);
120 ExternalTestingManager m = new ApiTestExternalTestingManager();
121 ExternalTestingImpl testingF = new ExternalTestingImpl(m);
124 testingF.getConfig();
126 catch (Exception ex) {
132 testingF.getEndpoints();
134 catch (ExternalTestingException e) {
139 testingF.getExecution(EP, EXEC);
141 catch (ExternalTestingException e) {
145 testingF.getScenarios(EP);
147 catch (ExternalTestingException e) {
152 testingF.getTestcase(EP, SC, TS, TC);
154 catch (ExternalTestingException e) {
159 testingF.getTestcases(EP, SC);
161 catch (ExternalTestingException e) {
166 testingF.getTestsuites(EP, SC);
168 catch (ExternalTestingException e) {
173 testingF.getTestCasesAsTree();
175 catch (ExternalTestingException e) {
179 List<VtpTestExecutionRequest> requestsF =
180 Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest());
183 testingF.execute(requestsF, null);
185 catch (ExternalTestingException e) {
191 testingF.execute(requestsF, null);
193 catch (ExternalTestingException e) {