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.Matchers.any;
23 import static org.mockito.Matchers.eq;
24 import static org.mockito.Matchers.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.InjectMocks;
37 import org.mockito.Mock;
38 import org.mockito.runners.MockitoJUnitRunner;
39 import org.onap.so.bpmn.common.BuildingBlockExecution;
40 import org.onap.so.bpmn.common.InjectionHelper;
41 import org.onap.so.bpmn.common.data.TestDataSetup;
42 import org.onap.so.bpmn.infrastructure.aai.tasks.AAIFlagTasks;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
44 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
45 import org.onap.so.client.aai.AAIResourcesClient;
46 import org.onap.so.client.aai.mapper.AAIObjectMapper;
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 import org.springframework.beans.factory.annotation.Autowired;
52 @RunWith(MockitoJUnitRunner.class)
53 public class AAIFlagTasksTest extends TestDataSetup {
56 private AAIFlagTasks aaiFlagTasks = new AAIFlagTasks();
59 private AAIVnfResources aaiVnfResources;
62 protected AAIObjectMapper MOCK_aaiObjectMapper;
65 protected InjectionHelper MOCK_injectionHelper;
68 protected AAIResourcesClient MOCK_aaiResourcesClient;
72 private ExtractPojosForBB extractPojosForBB;
75 private ExceptionBuilder exceptionUtil;
77 private GenericVnf genericVnf;
80 public void before() throws BBObjectNotFoundException {
81 genericVnf = setGenericVnf();
82 doReturn(MOCK_aaiResourcesClient).when(MOCK_injectionHelper).getAaiClient();
83 when(extractPojosForBB.extractByKey(any(),any(), any())).thenReturn(genericVnf);
87 public void checkVnfInMaintTestTrue() throws Exception {
88 doThrow(new BpmnError("VNF is in maintenance in A&AI")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
89 doReturn(false).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
90 doReturn(true).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
92 aaiFlagTasks.checkVnfInMaintFlag(execution);
93 } catch (Exception e) {
94 verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class));
95 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), eq("VNF is in maintenance in A&AI"));
100 public void checkVnfInMaintTestFalse() throws Exception {
101 doReturn(false).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
102 aaiFlagTasks.checkVnfInMaintFlag(execution);
103 verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), any(int.class), any(String.class));
107 public void checkVnfInMaintFlagExceptionTest() {
109 doThrow(new BpmnError("Unknown Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
110 doThrow(Exception.class).when(aaiVnfResources).checkInMaintFlag(isA(String.class));
112 aaiFlagTasks.checkVnfInMaintFlag(execution);
113 } catch (Exception e) {
114 verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class));
115 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
121 public void modifyVnfInMaintFlagTest() throws Exception {
122 doNothing().when(aaiVnfResources).updateObjectVnf(isA(GenericVnf.class));
123 aaiFlagTasks.modifyVnfInMaintFlag(execution, true);
124 verify(aaiVnfResources, times(1)).updateObjectVnf(genericVnf);
128 public void modifyVnfInMaintFlagExceptionTest() {
130 doThrow(new BpmnError("Unknown Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
131 doThrow(Exception.class).when(aaiVnfResources).updateObjectVnf(isA(GenericVnf.class));
133 aaiFlagTasks.modifyVnfInMaintFlag(execution, true);
134 } catch (Exception e) {
135 verify(aaiVnfResources, times(1)).checkInMaintFlag(any(String.class));
136 verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));