2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.so.bpmn.common.aai.tasks;
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.BaseTaskTest;
41 import org.onap.so.bpmn.common.BuildingBlockExecution;
42 import org.onap.so.bpmn.common.InjectionHelper;
43 import org.onap.so.bpmn.common.data.TestDataSetup;
44 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIFlagTasks;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
46 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
47 import org.onap.aaiclient.client.aai.AAIResourcesClient;
48 import org.onap.so.client.aai.mapper.AAIObjectMapper;
49 import org.onap.so.client.exception.BBObjectNotFoundException;
50 import org.onap.so.client.exception.ExceptionBuilder;
51 import org.onap.so.client.orchestration.AAIVnfResources;
52 import org.springframework.beans.factory.annotation.Autowired;
55 public class AAIFlagTasksTest extends BaseTaskTest {
58 private AAIFlagTasks aaiFlagTasks = new AAIFlagTasks();
60 private GenericVnf genericVnf;
63 public void before() throws BBObjectNotFoundException {
64 genericVnf = setGenericVnf();
65 doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
66 when(extractPojosForBB.extractByKey(any(), any())).thenReturn(genericVnf);
70 public void checkVnfInMaintTestTrue() throws Exception {
71 doThrow(new BpmnError("VNF is in maintenance in A&AI")).when(exceptionUtil)
72 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
73 doReturn(false).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
74 doReturn(true).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
76 aaiFlagTasks.checkVnfInMaintFlag(execution);
77 } catch (Exception e) {
78 verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class));
79 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
80 eq("VNF is in maintenance in A&AI"));
85 public void checkVnfInMaintTestFalse() throws Exception {
86 doReturn(false).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
87 aaiFlagTasks.checkVnfInMaintFlag(execution);
88 verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class),
89 any(int.class), any(String.class));
93 public void checkVnfInMaintFlagExceptionTest() {
95 doThrow(new BpmnError("Unknown Error")).when(exceptionUtil)
96 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
97 doThrow(RuntimeException.class).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
99 aaiFlagTasks.checkVnfInMaintFlag(execution);
100 } catch (Exception e) {
101 verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class));
102 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
109 public void modifyVnfInMaintFlagTest() throws Exception {
110 doNothing().when(aaiVnfResources).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class));
111 aaiFlagTasks.modifyVnfInMaintFlag(execution, true);
112 verify(aaiVnfResources, times(1)).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class));
116 public void modifyVnfInMaintFlagExceptionTest() {
118 doThrow(new BpmnError("Unknown Error")).when(exceptionUtil)
119 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
120 doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(isA(GenericVnf.class));
122 aaiFlagTasks.modifyVnfInMaintFlag(execution, true);
123 } catch (Exception e) {
124 verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class));
125 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
131 public void checkVnfClosedLoopDisabledTestTrue() throws Exception {
132 doThrow(new BpmnError("VNF Closed Loop Disabled in A&AI")).when(exceptionUtil)
133 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
134 doReturn(false).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class));
136 aaiFlagTasks.checkVnfClosedLoopDisabledFlag(execution);
137 } catch (Exception e) {
138 verify(aaiVnfResources, times(1)).checkVnfClosedLoopDisabledFlag(any(String.class));
139 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
140 eq("VNF Closed Loop Disabled in A&AI"));
145 public void checkVnfClosedLoopDisabledTestFalse() throws Exception {
146 doReturn(false).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class));
147 aaiFlagTasks.checkVnfClosedLoopDisabledFlag(execution);
148 verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class),
149 any(int.class), any(String.class));
153 public void checkVnfClosedLoopDisabledFlagExceptionTest() {
155 doThrow(new BpmnError("Unknown Error")).when(exceptionUtil)
156 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
157 doThrow(RuntimeException.class).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class));
159 aaiFlagTasks.checkVnfClosedLoopDisabledFlag(execution);
160 } catch (Exception e) {
161 verify(aaiVnfResources, times(1)).checkVnfClosedLoopDisabledFlag(any(String.class));
162 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
168 public void modifyVnfClosedLoopDisabledFlagTest() throws Exception {
169 doNothing().when(aaiVnfResources).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class));
170 aaiFlagTasks.modifyVnfClosedLoopDisabledFlag(execution, true);
171 verify(aaiVnfResources, times(1)).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class));
175 public void modifyVnfClosedLoopDisabledFlagExceptionTest() {
177 doThrow(new BpmnError("Unknown Error")).when(exceptionUtil)
178 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
179 doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(isA(GenericVnf.class));
181 aaiFlagTasks.modifyVnfClosedLoopDisabledFlag(execution, true);
182 } catch (Exception e) {
183 verify(aaiVnfResources, times(1)).checkVnfClosedLoopDisabledFlag(any(String.class));
184 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
191 public void checkVnfPserversLockedFlagTestTrue() throws Exception {
192 doThrow(new BpmnError("VNF PServers in Locked in A&AI")).when(exceptionUtil)
193 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
194 doReturn(true).when(aaiVnfResources).checkVnfPserversLockedFlag(isA(String.class));
196 aaiFlagTasks.checkVnfClosedLoopDisabledFlag(execution);
197 } catch (Exception e) {
198 verify(aaiVnfResources, times(1)).checkVnfPserversLockedFlag(any(String.class));
199 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),
200 eq("VNF PServers in Locked in A&AI"));
205 public void checkVnfPserversLockedFlagTestFalse() throws Exception {
206 doReturn(false).when(aaiVnfResources).checkVnfPserversLockedFlag(isA(String.class));
207 aaiFlagTasks.checkVnfPserversLockedFlag(execution);
208 verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class),
209 any(int.class), any(String.class));
213 public void checkVnfPserversLockedFlagExceptionTest() throws IOException {
215 doThrow(new BpmnError("Unknown Error")).when(exceptionUtil)
216 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
217 doThrow(RuntimeException.class).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class));
219 aaiFlagTasks.checkVnfPserversLockedFlag(execution);
220 } catch (Exception e) {
221 verify(aaiVnfResources, times(1)).checkVnfPserversLockedFlag(any(String.class));
222 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000),