8382b9be728fe2ce6ae681e73119f0bf5c05c181
[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.onap.so.client.aai.entities.AAIEdgeLabel;
37 import org.springframework.beans.factory.annotation.Autowired;
38
39 public class AssignVnfTest extends BaseTaskTest {
40         @Autowired
41         private AssignVnf assignVnf;
42         
43         private InstanceGroup instanceGroup1;
44         private InstanceGroup instanceGroup2;
45         private InstanceGroup instanceGroup3;
46         private InstanceGroup instanceGroup4;
47         private GenericVnf genericVnf;
48         
49         @Before
50         public void before() {
51                 ModelInfoInstanceGroup modelVnfc = new ModelInfoInstanceGroup();
52                 modelVnfc.setType("VNFC");
53                 modelVnfc.setFunction("function");
54                 
55                 ModelInfoInstanceGroup modelNetworkInstanceGroup = new ModelInfoInstanceGroup();
56                 modelNetworkInstanceGroup.setType("networkInstanceGroup");
57                 modelNetworkInstanceGroup.setFunction("function");
58                 
59                 instanceGroup1 = new InstanceGroup();
60                 instanceGroup1.setId("test-001");
61                 instanceGroup1.setModelInfoInstanceGroup(modelVnfc);
62                 
63                 instanceGroup2 = new InstanceGroup();
64                 instanceGroup2.setId("test-002");
65                 instanceGroup2.setModelInfoInstanceGroup(modelVnfc);
66                 
67                 instanceGroup3 = new InstanceGroup();
68                 instanceGroup3.setId("test-003");
69                 instanceGroup3.setModelInfoInstanceGroup(modelNetworkInstanceGroup);
70                 
71                 instanceGroup4 = new InstanceGroup();
72                 instanceGroup4.setId("test-004");
73                 instanceGroup4.setModelInfoInstanceGroup(modelNetworkInstanceGroup);
74                 
75                 genericVnf = setGenericVnf();
76                 genericVnf.setVnfName("vnfName");
77         }
78
79         @Test
80         public void createInstanceGroupsSunnyDayTest() throws Exception {
81                 
82                 List<InstanceGroup> instanceGroupList = genericVnf.getInstanceGroups();
83                 instanceGroupList.add(instanceGroup1);
84                 instanceGroupList.add(instanceGroup2);
85                 instanceGroupList.add(instanceGroup3);
86                 instanceGroupList.add(instanceGroup4);
87
88                 assignVnf.createInstanceGroups(execution);
89                 verify(aaiInstanceGroupResources, times(1)).createInstanceGroup(instanceGroup1);
90                 verify(aaiInstanceGroupResources, times(1)).createInstanceGroup(instanceGroup2);
91                 verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup1, genericVnf, AAIEdgeLabel.BELONGS_TO);
92                 verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup2, genericVnf, AAIEdgeLabel.BELONGS_TO);
93                 verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup3, genericVnf, AAIEdgeLabel.USES);
94                 verify(aaiInstanceGroupResources, times(1)).connectInstanceGroupToVnf(instanceGroup4, genericVnf, AAIEdgeLabel.USES);
95         }
96         
97         @Test
98         public void createVnfcInstanceGroupNoneTest() throws Exception {
99                 assignVnf.createInstanceGroups(execution);
100                 verify(aaiInstanceGroupResources, times(0)).createInstanceGroup(any(InstanceGroup.class));
101                 verify(aaiInstanceGroupResources, times(0)).connectInstanceGroupToVnf(any(InstanceGroup.class), any(GenericVnf.class));
102         }
103
104         @Test
105         public void createVnfcInstanceGroupExceptionTest() throws Exception {
106                 expectedException.expect(BpmnError.class);
107                 
108                 genericVnf.setVnfId("test-999");
109                 assignVnf.createInstanceGroups(execution);
110         }
111 }