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.Matchers.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;
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.so.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(), any())).thenReturn(genericVnf);
70 public void checkVnfInMaintTestTrue() throws Exception {
71 doThrow(new BpmnError("VNF is in maintenance in A&AI")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
72 doReturn(false).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
73 doReturn(true).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
75 aaiFlagTasks.checkVnfInMaintFlag(execution);
76 } catch (Exception e) {
77 verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class));
78 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), eq("VNF is in maintenance in A&AI"));
83 public void checkVnfInMaintTestFalse() throws Exception {
84 doReturn(false).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
85 aaiFlagTasks.checkVnfInMaintFlag(execution);
86 verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), any(int.class), any(String.class));
90 public void checkVnfInMaintFlagExceptionTest() {
92 doThrow(new BpmnError("Unknown Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
93 doThrow(RuntimeException.class).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
95 aaiFlagTasks.checkVnfInMaintFlag(execution);
96 } catch (Exception e) {
97 verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class));
98 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
104 public void modifyVnfInMaintFlagTest() throws Exception {
105 doNothing().when(aaiVnfResources).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class));
106 aaiFlagTasks.modifyVnfInMaintFlag(execution, true);
107 verify(aaiVnfResources, times(1)).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class));
111 public void modifyVnfInMaintFlagExceptionTest() {
113 doThrow(new BpmnError("Unknown Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
114 doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(isA(GenericVnf.class));
116 aaiFlagTasks.modifyVnfInMaintFlag(execution, true);
117 } catch (Exception e) {
118 verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class));
119 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));