2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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=========================================================
20 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
21 import static org.junit.Assert.assertEquals;
22 import static org.mockito.Mockito.doNothing;
23 import static org.mockito.Mockito.times;
24 import static org.mockito.Mockito.verify;
26 import java.util.ArrayList;
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.L3Network;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
35 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
36 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup;
37 import org.springframework.beans.factory.annotation.Autowired;
39 public class CreateNetworkCollectionTest extends BaseTaskTest{
41 private CreateNetworkCollection createNetworkCollection;
43 private L3Network network;
44 private ServiceInstance serviceInstance;
45 private OrchestrationContext orchestrationContext;
48 public void before() {
49 serviceInstance = setServiceInstance();
50 network = setL3Network();
52 List<L3Network> l3NetworkList = new ArrayList<L3Network>();
53 l3NetworkList.add(network);
54 ModelInfoInstanceGroup modelInfoInstanceGroup = new ModelInfoInstanceGroup();
55 modelInfoInstanceGroup.setFunction("function");
56 serviceInstance.getCollection().getInstanceGroup().setModelInfoInstanceGroup(modelInfoInstanceGroup);
58 orchestrationContext = setOrchestrationContext();
59 orchestrationContext.setIsRollbackEnabled(true);
63 public void buildCreateNetworkRequestTest() throws Exception {
64 createNetworkCollection.buildNetworkCollectionName(execution);
66 assertEquals(serviceInstance.getServiceInstanceName() + "_" + serviceInstance.getCollection().getInstanceGroup().getModelInfoInstanceGroup().getFunction(), execution.getVariable("networkCollectionName"));
69 @Test(expected = BpmnError.class)
70 public void buildCreateNetworkRequestInstanceGroupModelInfoFunctionNullExceptionTest() throws Exception {
71 ModelInfoInstanceGroup modelInfoInstanceGroup = new ModelInfoInstanceGroup();
72 serviceInstance.getCollection().getInstanceGroup().setModelInfoInstanceGroup(modelInfoInstanceGroup);
73 createNetworkCollection.buildNetworkCollectionName(execution);
76 @Test(expected = BpmnError.class)
77 public void buildCreateNetworkRequestInstanceGroupModelInfoNullTest() throws Exception {
78 serviceInstance.getCollection().getInstanceGroup().setModelInfoInstanceGroup(null);
79 createNetworkCollection.buildNetworkCollectionName(execution);
83 public void connectCollectionToInstanceGroupTest() throws Exception {
84 doNothing().when(aaiNetworkResources).connectNetworkCollectionInstanceGroupToNetworkCollection(serviceInstance.getCollection().getInstanceGroup(), serviceInstance.getCollection());
85 createNetworkCollection.connectCollectionToInstanceGroup(execution);
86 verify(aaiNetworkResources, times(1)).connectNetworkCollectionInstanceGroupToNetworkCollection(serviceInstance.getCollection().getInstanceGroup(), serviceInstance.getCollection());
90 public void connectCollectionToServiceInstanceTest() throws Exception {
91 doNothing().when(aaiNetworkResources).connectNetworkCollectionToServiceInstance(serviceInstance.getCollection(), serviceInstance);
92 createNetworkCollection.connectCollectionToServiceInstance(execution);
93 verify(aaiNetworkResources, times(1)).connectNetworkCollectionToServiceInstance(serviceInstance.getCollection(), serviceInstance);