List of Input Parameters for VSP
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / externaltesting-rest / externaltesting-rest-services / src / test / java / org / openecomp / sdcrests / externaltesting / rest / services / ApiTests.java
1 /*
2  * Copyright © 2019 iconectiv
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdcrests.externaltesting.rest.services;
18
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;
25
26 import java.util.Arrays;
27 import java.util.List;
28
29 public class ApiTests {
30
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";
37
38
39   @Mock
40   private ExternalTestingManager testingManager;
41
42   /**
43    * At the API level, test that the code does not throw
44    * exceptions but there's not much to test.
45    */
46   @Test
47   public void testApi() {
48     MockitoAnnotations.initMocks(this);
49
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());
59
60     List<VtpTestExecutionRequest> requests =
61             Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest());
62     Assert.assertNotNull(testing.execute(requests, "requestId"));
63   }
64
65   class ApiTestExternalTestingManager implements ExternalTestingManager {
66     @Override
67     public String getConfig() {
68       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
69     }
70
71     @Override
72     public TestTreeNode getTestCasesAsTree() {
73       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
74     }
75
76     @Override
77     public List<VtpNameDescriptionPair> getEndpoints() {
78       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
79     }
80
81     @Override
82     public List<VtpNameDescriptionPair> getScenarios(String endpoint) {
83       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
84     }
85
86     @Override
87     public List<VtpNameDescriptionPair> getTestSuites(String endpoint, String scenario) {
88       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
89     }
90
91     @Override
92     public List<VtpTestCase> getTestCases(String endpoint, String scenario) {
93       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
94     }
95
96     @Override
97     public VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName) {
98       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
99     }
100
101     @Override
102     public List<VtpTestExecutionResponse> execute(List<VtpTestExecutionRequest> requests, String requestId) {
103       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
104     }
105
106     @Override
107     public VtpTestExecutionResponse getExecution(String endpoint, String executionId) {
108       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
109     }
110   }
111
112   /**
113    * Test the exception handler logic for the cases when the
114    * testing manager throws an exception.
115    */
116   @Test
117   public void testExceptions() {
118     MockitoAnnotations.initMocks(this);
119
120     ExternalTestingManager m = new ApiTestExternalTestingManager();
121     ExternalTestingImpl testingF = new ExternalTestingImpl(m);
122
123     try {
124       testingF.getConfig();
125     }
126     catch (Exception ex) {
127       // expected.
128     }
129
130
131     try {
132       testingF.getEndpoints();
133     }
134     catch (ExternalTestingException e) {
135       // expected.
136     }
137
138     try {
139       testingF.getExecution(EP, EXEC);
140     }
141     catch (ExternalTestingException e) {
142       // expected.
143     }
144     try {
145       testingF.getScenarios(EP);
146     }
147     catch (ExternalTestingException e) {
148       // expected.
149     }
150
151     try {
152       testingF.getTestcase(EP, SC, TS, TC);
153     }
154     catch (ExternalTestingException e) {
155       // expected.
156     }
157
158     try {
159       testingF.getTestcases(EP, SC);
160     }
161     catch (ExternalTestingException e) {
162       // expected.
163     }
164
165     try {
166       testingF.getTestsuites(EP, SC);
167     }
168     catch (ExternalTestingException e) {
169       // expected.
170     }
171
172     try {
173       testingF.getTestCasesAsTree();
174     }
175     catch (ExternalTestingException e) {
176       // expected.
177     }
178
179     List<VtpTestExecutionRequest> requestsF =
180             Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest());
181
182     try {
183       testingF.execute(requestsF, null);
184     }
185     catch (ExternalTestingException e) {
186       // expected.
187     }
188
189
190     try {
191       testingF.execute(requestsF, null);
192     }
193     catch (ExternalTestingException e) {
194       // expected.
195     }
196   }
197 }