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.Matchers.any;
24 import static org.mockito.Mockito.times;
25 import static org.mockito.Mockito.verify;
27 import java.util.List;
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;
38 public class AssignVnfTest extends BaseTaskTest {
40 private AssignVnf assignVnf;
42 private InstanceGroup instanceGroup1;
43 private InstanceGroup instanceGroup2;
44 private InstanceGroup instanceGroup3;
45 private InstanceGroup instanceGroup4;
46 private GenericVnf genericVnf;
49 public void before() {
50 ModelInfoInstanceGroup modelVnfc = new ModelInfoInstanceGroup();
51 modelVnfc.setType("VNFC");
52 modelVnfc.setFunction("function");
54 ModelInfoInstanceGroup modelNetworkInstanceGroup = new ModelInfoInstanceGroup();
55 modelNetworkInstanceGroup.setType("networkInstanceGroup");
56 modelNetworkInstanceGroup.setFunction("function");
58 instanceGroup1 = new InstanceGroup();
59 instanceGroup1.setId("test-001");
60 instanceGroup1.setModelInfoInstanceGroup(modelVnfc);
62 instanceGroup2 = new InstanceGroup();
63 instanceGroup2.setId("test-002");
64 instanceGroup2.setModelInfoInstanceGroup(modelVnfc);
66 instanceGroup3 = new InstanceGroup();
67 instanceGroup3.setId("test-003");
68 instanceGroup3.setModelInfoInstanceGroup(modelNetworkInstanceGroup);
70 instanceGroup4 = new InstanceGroup();
71 instanceGroup4.setId("test-004");
72 instanceGroup4.setModelInfoInstanceGroup(modelNetworkInstanceGroup);
74 genericVnf = setGenericVnf();
75 genericVnf.setVnfName("vnfName");
79 public void createInstanceGroupsSunnyDayTest() throws Exception {
81 List<InstanceGroup> instanceGroupList = genericVnf.getInstanceGroups();
82 instanceGroupList.add(instanceGroup1);
83 instanceGroupList.add(instanceGroup2);
84 instanceGroupList.add(instanceGroup3);
85 instanceGroupList.add(instanceGroup4);
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);
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));
104 public void createVnfcInstanceGroupExceptionTest() throws Exception {
105 expectedException.expect(BpmnError.class);
107 genericVnf.setVnfId("test-999");
108 assignVnf.createInstanceGroups(execution);