411be2f15084379acb0e6c2d56280c2771ead021
[sdc.git] /
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 ClientConfiguration getConfig() {
68       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
69     }
70
71     @Override
72     public ClientConfiguration setConfig(ClientConfiguration config) {
73       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
74     }
75
76     @Override
77     public List<RemoteTestingEndpointDefinition> setEndpoints(List<RemoteTestingEndpointDefinition> endpoints) {
78       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
79     }
80
81     @Override
82     public TestTreeNode getTestCasesAsTree() {
83       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
84     }
85
86     @Override
87     public List<RemoteTestingEndpointDefinition> getEndpoints() {
88       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
89     }
90
91     @Override
92     public List<VtpNameDescriptionPair> getScenarios(String endpoint) {
93       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
94     }
95
96     @Override
97     public List<VtpNameDescriptionPair> getTestSuites(String endpoint, String scenario) {
98       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
99     }
100
101     @Override
102     public List<VtpTestCase> getTestCases(String endpoint, String scenario) {
103       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
104     }
105
106     @Override
107     public VtpTestCase getTestCase(String endpoint, String scenario, String testSuite, String testCaseName) {
108       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
109     }
110
111     @Override
112     public List<VtpTestExecutionResponse> execute(List<VtpTestExecutionRequest> requests, String requestId) {
113       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
114     }
115
116     @Override
117     public VtpTestExecutionResponse getExecution(String endpoint, String executionId) {
118       throw new ExternalTestingException(EXPECTED, 500, EXPECTED);
119     }
120   }
121
122   /**
123    * Test the exception handler logic for the cases when the
124    * testing manager throws an exception.
125    */
126   @Test
127   public void testExceptions() {
128     MockitoAnnotations.initMocks(this);
129
130     ExternalTestingManager m = new ApiTestExternalTestingManager();
131     ExternalTestingImpl testingF = new ExternalTestingImpl(m);
132
133     try {
134       testingF.getConfig();
135     }
136     catch (Exception ex) {
137       // expected.
138     }
139
140
141     try {
142       testingF.getEndpoints();
143     }
144     catch (ExternalTestingException e) {
145       // expected.
146     }
147
148     try {
149       testingF.getExecution(EP, EXEC);
150     }
151     catch (ExternalTestingException e) {
152       // expected.
153     }
154     try {
155       testingF.getScenarios(EP);
156     }
157     catch (ExternalTestingException e) {
158       // expected.
159     }
160
161     try {
162       testingF.getTestcase(EP, SC, TS, TC);
163     }
164     catch (ExternalTestingException e) {
165       // expected.
166     }
167
168     try {
169       testingF.getTestcases(EP, SC);
170     }
171     catch (ExternalTestingException e) {
172       // expected.
173     }
174
175     try {
176       testingF.getTestsuites(EP, SC);
177     }
178     catch (ExternalTestingException e) {
179       // expected.
180     }
181
182     try {
183       testingF.getTestCasesAsTree();
184     }
185     catch (ExternalTestingException e) {
186       // expected.
187     }
188
189     List<VtpTestExecutionRequest> requestsF =
190         Arrays.asList(new VtpTestExecutionRequest(), new VtpTestExecutionRequest());
191
192     try {
193       testingF.execute(requestsF, null);
194     }
195     catch (ExternalTestingException e) {
196       // expected.
197     }
198
199
200     try {
201       testingF.execute(requestsF, null);
202     }
203     catch (ExternalTestingException e) {
204       // expected.
205     }
206   }
207 }