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;
22 import static org.junit.Assert.assertEquals;
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.ArgumentMatchers.eq;
25 import static org.mockito.Mockito.doNothing;
26 import static org.mockito.Mockito.doThrow;
27 import static org.mockito.Mockito.times;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
30 import java.util.ArrayList;
31 import java.util.List;
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.mockito.ArgumentMatchers;
36 import org.mockito.InjectMocks;
37 import org.onap.so.bpmn.BaseTaskTest;
38 import org.onap.so.bpmn.common.BuildingBlockExecution;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
42 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
43 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
44 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup;
45 import org.onap.so.client.exception.BBObjectNotFoundException;
47 public class CreateNetworkCollectionTest extends BaseTaskTest {
49 private CreateNetworkCollection createNetworkCollection = new CreateNetworkCollection();
51 private L3Network network;
52 private ServiceInstance serviceInstance;
53 private OrchestrationContext orchestrationContext;
54 private CloudRegion cloudRegion;
57 public void before() throws BBObjectNotFoundException {
58 serviceInstance = setServiceInstance();
59 network = setL3Network();
60 cloudRegion = setCloudRegion();
62 List<L3Network> l3NetworkList = new ArrayList<L3Network>();
63 l3NetworkList.add(network);
64 ModelInfoInstanceGroup modelInfoInstanceGroup = new ModelInfoInstanceGroup();
65 modelInfoInstanceGroup.setFunction("function");
66 serviceInstance.getCollection().getInstanceGroup().setModelInfoInstanceGroup(modelInfoInstanceGroup);
68 orchestrationContext = setOrchestrationContext();
69 orchestrationContext.setIsRollbackEnabled(true);
71 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
72 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
73 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
74 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
75 .thenReturn(serviceInstance);
79 public void buildCreateNetworkRequestTest() throws Exception {
80 createNetworkCollection.buildNetworkCollectionName(execution);
83 serviceInstance.getServiceInstanceName() + "_"
84 + serviceInstance.getCollection().getInstanceGroup().getModelInfoInstanceGroup().getFunction(),
85 execution.getVariable("networkCollectionName"));
88 @Test(expected = BpmnError.class)
89 public void buildCreateNetworkRequestInstanceGroupModelInfoFunctionNullExceptionTest() throws Exception {
90 ModelInfoInstanceGroup modelInfoInstanceGroup = new ModelInfoInstanceGroup();
91 serviceInstance.getCollection().getInstanceGroup().setModelInfoInstanceGroup(modelInfoInstanceGroup);
92 createNetworkCollection.buildNetworkCollectionName(execution);
95 @Test(expected = BpmnError.class)
96 public void buildCreateNetworkRequestInstanceGroupModelInfoNullTest() throws Exception {
97 serviceInstance.getCollection().getInstanceGroup().setModelInfoInstanceGroup(null);
98 createNetworkCollection.buildNetworkCollectionName(execution);
102 public void connectCollectionToInstanceGroupTest() throws Exception {
103 doNothing().when(aaiNetworkResources).connectNetworkCollectionInstanceGroupToNetworkCollection(
104 serviceInstance.getCollection().getInstanceGroup(), serviceInstance.getCollection());
105 createNetworkCollection.connectCollectionToInstanceGroup(execution);
106 verify(aaiNetworkResources, times(1)).connectNetworkCollectionInstanceGroupToNetworkCollection(
107 serviceInstance.getCollection().getInstanceGroup(), serviceInstance.getCollection());
111 public void connectCollectionToServiceInstanceTest() throws Exception {
112 doNothing().when(aaiNetworkResources).connectNetworkCollectionToServiceInstance(serviceInstance.getCollection(),
114 createNetworkCollection.connectCollectionToServiceInstance(execution);
115 verify(aaiNetworkResources, times(1)).connectNetworkCollectionToServiceInstance(serviceInstance.getCollection(),
120 public void connectInstanceGroupToCloudRegionTest() throws Exception {
121 doNothing().when(aaiNetworkResources)
122 .connectInstanceGroupToCloudRegion(serviceInstance.getCollection().getInstanceGroup(), cloudRegion);
123 createNetworkCollection.connectInstanceGroupToCloudRegion(execution);
124 verify(aaiNetworkResources, times(1))
125 .connectInstanceGroupToCloudRegion(serviceInstance.getCollection().getInstanceGroup(), cloudRegion);