2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 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=========================================================
21 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.ArgumentMatchers.eq;
25 import static org.mockito.ArgumentMatchers.eq;
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 org.camunda.bpm.engine.delegate.BpmnError;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.ArgumentMatchers;
35 import org.mockito.InjectMocks;
36 import org.onap.so.bpmn.BaseTaskTest;
37 import org.onap.so.bpmn.common.BuildingBlockExecution;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
40 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
41 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup;
43 public class UnassignVnfTest extends BaseTaskTest {
45 private UnassignVnf unassignVnf = new UnassignVnf();
49 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
50 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
51 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
52 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
57 public void deleteInstanceGroupsSunnyDayTest() throws Exception {
58 GenericVnf genericVnf = setGenericVnf();
60 ModelInfoInstanceGroup modelVnfc = new ModelInfoInstanceGroup();
61 modelVnfc.setType("VNFC");
63 InstanceGroup instanceGroup1 = new InstanceGroup();
64 instanceGroup1.setId("test-001");
65 instanceGroup1.setModelInfoInstanceGroup(modelVnfc);
66 genericVnf.getInstanceGroups().add(instanceGroup1);
68 InstanceGroup instanceGroup2 = new InstanceGroup();
69 instanceGroup2.setId("test-002");
70 instanceGroup2.setModelInfoInstanceGroup(modelVnfc);
71 genericVnf.getInstanceGroups().add(instanceGroup2);
72 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
73 .thenReturn(genericVnf);
74 unassignVnf.deleteInstanceGroups(execution);
75 verify(aaiInstanceGroupResources, times(1)).deleteInstanceGroup(eq(instanceGroup1));
76 verify(aaiInstanceGroupResources, times(1)).deleteInstanceGroup(eq(instanceGroup2));
80 public void deletecreateVnfcInstanceGroupExceptionTest() throws Exception {
81 expectedException.expect(BpmnError.class);
83 unassignVnf.deleteInstanceGroups(execution);