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.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;
51 @RunWith(MockitoJUnitRunner.Silent.class)
52 public class AAIFlagTasksTest extends TestDataSetup {
54 protected AAIResourcesClient MOCK_aaiResourcesClient;
56 protected InjectionHelper MOCK_injectionHelper;
58 protected ExceptionBuilder exceptionUtil;
60 protected AAIVnfResources aaiVnfResources;
62 protected ExtractPojosForBB extractPojosForBBMock;
64 private AAIFlagTasks aaiFlagTasks;
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);
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));
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"));
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));
97 public void checkVnfInMaintFlagExceptionTest() {
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));
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),
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));
120 public void modifyVnfInMaintFlagExceptionTest() {
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));
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),
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));
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"));
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));
157 public void checkVnfClosedLoopDisabledFlagExceptionTest() {
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));
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),
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));
179 public void modifyVnfClosedLoopDisabledFlagExceptionTest() {
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));
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),
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));
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"));
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));
217 public void checkVnfPserversLockedFlagExceptionTest() throws IOException {
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));
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),