e1b652a140cdaa90fafe39c189aa1b98281246db
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / flowspecific / tasks / AssignVnfTest.java
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.Matchers.any;
24 import static org.mockito.Mockito.times;
25 import static org.mockito.Mockito.verify;
26
27 import java.util.List;
28
29 import org.camunda.bpm.engine.delegate.BpmnError;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.so.bpmn.BaseTaskTest;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
35 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup;
36 import org.springframework.beans.factory.annotation.Autowired;
37
38 public class AssignVnfTest extends BaseTaskTest {
39         @Autowired
40         private AssignVnf assignVnf;
41         
42         private InstanceGroup instanceGroup1;
43         private InstanceGroup instanceGroup2;
44         private InstanceGroup instanceGroup3;
45         private InstanceGroup instanceGroup4;
46         private GenericVnf genericVnf;
47         
48         @Before
49         public void before() {
50                 ModelInfoInstanceGroup modelVnfc = new ModelInfoInstanceGroup();
51                 modelVnfc.setType("VNFC");
52                 modelVnfc.setFunction("function");
53                 
54                 ModelInfoInstanceGroup modelNetworkInstanceGroup = new ModelInfoInstanceGroup();
55                 modelNetworkInstanceGroup.setType("networkInstanceGroup");
56                 modelNetworkInstanceGroup.setFunction("function");
57                 
58                 instanceGroup1 = new InstanceGroup();
59                 instanceGroup1.setId("test-001");
60                 instanceGroup1.setModelInfoInstanceGroup(modelVnfc);
61                 
62                 instanceGroup2 = new InstanceGroup();
63                 instanceGroup2.setId("test-002");
64                 instanceGroup2.setModelInfoInstanceGroup(modelVnfc);
65                 
66                 instanceGroup3 = new InstanceGroup();
67                 instanceGroup3.setId("test-003");
68                 instanceGroup3.setModelInfoInstanceGroup(modelNetworkInstanceGroup);
69                 
70                 instanceGroup4 = new InstanceGroup();
71                 instanceGroup4.setId("test-004");
72                 instanceGroup4.setModelInfoInstanceGroup(modelNetworkInstanceGroup);
73                 
74                 genericVnf = setGenericVnf();
75                 genericVnf.setVnfName("vnfName");
76         }
77
78         @Test
79         public void createInstanceGroupsSunnyDayTest() throws Exception {
80                 
81                 List<InstanceGroup> instanceGroupList = genericVnf.getInstanceGroups();
82                 instanceGroupList.add(instanceGroup1);
83                 instanceGroupList.add(instanceGroup2);
84                 instanceGroupList.add(instanceGroup3);
85                 instanceGroupList.add(instanceGroup4);
86
87                 assignVnf.createInstanceGroups(execution);
88                 verify(aaiInstanceGroupResources, times(1)).createInstanceGroup(instanceGroup1);
89                 verify(aaiInstanceGroupResources, times(1)).createInstanceGroup(instanceGroup2);
90                 verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup1, genericVnf);
91                 verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup2, genericVnf);
92                 verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup3, genericVnf);
93                 verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup4, genericVnf);
94         }
95         
96         @Test
97         public void createVnfcInstanceGroupNoneTest() throws Exception {
98                 assignVnf.createInstanceGroups(execution);
99                 verify(aaiInstanceGroupResources, times(0)).createInstanceGroup(any(InstanceGroup.class));
100                 verify(aaiInstanceGroupResources, times(0)).connectInstanceGroupToVnf(any(InstanceGroup.class), any(GenericVnf.class));
101         }
102
103         @Test
104         public void createVnfcInstanceGroupExceptionTest() throws Exception {
105                 expectedException.expect(BpmnError.class);
106                 
107                 genericVnf.setVnfId("test-999");
108                 assignVnf.createInstanceGroups(execution);
109         }
110 }