delete redundant test dependency
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / common / aai / tasks / AAIFlagTasksTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.bpmn.common.aai.tasks;
21
22 import static org.mockito.ArgumentMatchers.any;
23 import static org.mockito.ArgumentMatchers.eq;
24 import static org.mockito.ArgumentMatchers.isA;
25 import static org.mockito.Mockito.doNothing;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.doThrow;
28 import static org.mockito.Mockito.times;
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.when;
31 import java.io.IOException;
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.ArgumentMatchers;
37 import org.mockito.InjectMocks;
38 import org.mockito.Mock;
39 import org.mockito.junit.MockitoJUnitRunner;
40 import org.onap.so.bpmn.common.BuildingBlockExecution;
41 import org.onap.so.bpmn.common.InjectionHelper;
42 import org.onap.so.bpmn.common.data.TestDataSetup;
43 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIFlagTasks;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
45 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
46 import org.onap.aaiclient.client.aai.AAIResourcesClient;
47 import org.onap.so.client.exception.BBObjectNotFoundException;
48 import org.onap.so.client.exception.ExceptionBuilder;
49 import org.onap.so.client.orchestration.AAIVnfResources;
50
51 @RunWith(MockitoJUnitRunner.Silent.class)
52 public class AAIFlagTasksTest extends TestDataSetup {
53     @Mock
54     protected AAIResourcesClient MOCK_aaiResourcesClient;
55     @Mock
56     protected InjectionHelper MOCK_injectionHelper;
57     @Mock
58     protected ExceptionBuilder exceptionUtil;
59     @Mock
60     protected AAIVnfResources aaiVnfResources;
61     @Mock
62     protected ExtractPojosForBB extractPojosForBBMock;
63     @InjectMocks
64     private AAIFlagTasks aaiFlagTasks;
65
66     @Before
67     public void before() throws BBObjectNotFoundException {
68         GenericVnf genericVnf = setGenericVnf();
69         doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
70         when(extractPojosForBBMock.extractByKey(any(), any())).thenReturn(genericVnf);
71     }
72
73     @Test
74     public void checkVnfInMaintTestTrue() {
75         doThrow(new BpmnError("VNF is in maintenance in A&AI")).when(exceptionUtil)
76                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
77         doReturn(false).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
78         doReturn(true).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
79         try {
80             aaiFlagTasks.checkVnfInMaintFlag(execution);
81         } catch (Exception e) {
82             verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class));
83             verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
84                     eq("VNF is in maintenance in A&AI"));
85         }
86     }
87
88     @Test
89     public void checkVnfInMaintTestFalse() {
90         doReturn(false).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
91         aaiFlagTasks.checkVnfInMaintFlag(execution);
92         verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class),
93                 any(int.class), any(String.class));
94     }
95
96     @Test
97     public void checkVnfInMaintFlagExceptionTest() {
98
99         doThrow(new BpmnError("Unknown Error")).when(exceptionUtil)
100                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
101         doThrow(RuntimeException.class).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
102         try {
103             aaiFlagTasks.checkVnfInMaintFlag(execution);
104         } catch (Exception e) {
105             verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class));
106             verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
107                     any(String.class));
108         }
109
110     }
111
112     @Test
113     public void modifyVnfInMaintFlagTest() {
114         doNothing().when(aaiVnfResources).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class));
115         aaiFlagTasks.modifyVnfInMaintFlag(execution, true);
116         verify(aaiVnfResources, times(1)).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class));
117     }
118
119     @Test
120     public void modifyVnfInMaintFlagExceptionTest() {
121
122         doThrow(new BpmnError("Unknown Error")).when(exceptionUtil)
123                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
124         doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(isA(GenericVnf.class));
125         try {
126             aaiFlagTasks.modifyVnfInMaintFlag(execution, true);
127         } catch (Exception e) {
128             verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class));
129             verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
130                     any(String.class));
131         }
132     }
133
134     @Test
135     public void checkVnfClosedLoopDisabledTestTrue() {
136         doThrow(new BpmnError("VNF Closed Loop Disabled in A&AI")).when(exceptionUtil)
137                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
138         doReturn(false).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class));
139         try {
140             aaiFlagTasks.checkVnfClosedLoopDisabledFlag(execution);
141         } catch (Exception e) {
142             verify(aaiVnfResources, times(1)).checkVnfClosedLoopDisabledFlag(any(String.class));
143             verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
144                     eq("VNF Closed Loop Disabled in A&AI"));
145         }
146     }
147
148     @Test
149     public void checkVnfClosedLoopDisabledTestFalse() {
150         doReturn(false).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class));
151         aaiFlagTasks.checkVnfClosedLoopDisabledFlag(execution);
152         verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class),
153                 any(int.class), any(String.class));
154     }
155
156     @Test
157     public void checkVnfClosedLoopDisabledFlagExceptionTest() {
158
159         doThrow(new BpmnError("Unknown Error")).when(exceptionUtil)
160                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
161         doThrow(RuntimeException.class).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class));
162         try {
163             aaiFlagTasks.checkVnfClosedLoopDisabledFlag(execution);
164         } catch (Exception e) {
165             verify(aaiVnfResources, times(1)).checkVnfClosedLoopDisabledFlag(any(String.class));
166             verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
167                     any(String.class));
168         }
169     }
170
171     @Test
172     public void modifyVnfClosedLoopDisabledFlagTest() {
173         doNothing().when(aaiVnfResources).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class));
174         aaiFlagTasks.modifyVnfClosedLoopDisabledFlag(execution, true);
175         verify(aaiVnfResources, times(1)).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class));
176     }
177
178     @Test
179     public void modifyVnfClosedLoopDisabledFlagExceptionTest() {
180
181         doThrow(new BpmnError("Unknown Error")).when(exceptionUtil)
182                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
183         doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(isA(GenericVnf.class));
184         try {
185             aaiFlagTasks.modifyVnfClosedLoopDisabledFlag(execution, true);
186         } catch (Exception e) {
187             verify(aaiVnfResources, times(1)).checkVnfClosedLoopDisabledFlag(any(String.class));
188             verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
189                     any(String.class));
190         }
191     }
192
193
194     @Test
195     public void checkVnfPserversLockedFlagTestTrue() throws Exception {
196         doThrow(new BpmnError("VNF PServers in Locked in A&AI")).when(exceptionUtil)
197                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
198         doReturn(true).when(aaiVnfResources).checkVnfPserversLockedFlag(isA(String.class));
199         try {
200             aaiFlagTasks.checkVnfClosedLoopDisabledFlag(execution);
201         } catch (Exception e) {
202             verify(aaiVnfResources, times(1)).checkVnfPserversLockedFlag(any(String.class));
203             verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
204                     eq("VNF PServers in Locked in A&AI"));
205         }
206     }
207
208     @Test
209     public void checkVnfPserversLockedFlagTestFalse() throws Exception {
210         doReturn(false).when(aaiVnfResources).checkVnfPserversLockedFlag(isA(String.class));
211         aaiFlagTasks.checkVnfPserversLockedFlag(execution);
212         verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class),
213                 any(int.class), any(String.class));
214     }
215
216     @Test
217     public void checkVnfPserversLockedFlagExceptionTest() throws IOException {
218
219         doThrow(new BpmnError("Unknown Error")).when(exceptionUtil)
220                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
221         doThrow(RuntimeException.class).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class));
222         try {
223             aaiFlagTasks.checkVnfPserversLockedFlag(execution);
224         } catch (Exception e) {
225             verify(aaiVnfResources, times(1)).checkVnfPserversLockedFlag(any(String.class));
226             verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
227                     any(String.class));
228         }
229     }
230 }