04345a67925da41910e6ff2433d26b800555a233
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
22
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.ArgumentMatchers.eq;
25 import static org.mockito.Mockito.doThrow;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.when;
29 import org.camunda.bpm.engine.delegate.BpmnError;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.ArgumentMatchers;
33 import org.mockito.InjectMocks;
34 import org.onap.so.bpmn.BaseTaskTest;
35 import org.onap.so.bpmn.common.BuildingBlockExecution;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
38 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
39 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup;
40
41 public class UnassignVnfTest extends BaseTaskTest {
42     @InjectMocks
43     private UnassignVnf unassignVnf = new UnassignVnf();
44
45     @Before
46     public void setup() {
47         doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
48                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
49         doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
50                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class));
51
52     }
53
54     @Test
55     public void deleteInstanceGroupsSunnyDayTest() throws Exception {
56         GenericVnf genericVnf = setGenericVnf();
57
58         ModelInfoInstanceGroup modelVnfc = new ModelInfoInstanceGroup();
59         modelVnfc.setType("VNFC");
60
61         InstanceGroup instanceGroup1 = new InstanceGroup();
62         instanceGroup1.setId("test-001");
63         instanceGroup1.setModelInfoInstanceGroup(modelVnfc);
64         genericVnf.getInstanceGroups().add(instanceGroup1);
65
66         InstanceGroup instanceGroup2 = new InstanceGroup();
67         instanceGroup2.setId("test-002");
68         instanceGroup2.setModelInfoInstanceGroup(modelVnfc);
69         genericVnf.getInstanceGroups().add(instanceGroup2);
70         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
71                 .thenReturn(genericVnf);
72         unassignVnf.deleteInstanceGroups(execution);
73         verify(aaiInstanceGroupResources, times(1)).deleteInstanceGroup(eq(instanceGroup1));
74         verify(aaiInstanceGroupResources, times(1)).deleteInstanceGroup(eq(instanceGroup2));
75     }
76
77     @Test
78     public void deletecreateVnfcInstanceGroupExceptionTest() throws Exception {
79         expectedException.expect(BpmnError.class);
80
81         unassignVnf.deleteInstanceGroups(execution);
82     }
83 }