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.adapter.network.tasks;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.ArgumentMatchers.eq;
27 import static org.mockito.ArgumentMatchers.isA;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.doThrow;
30 import static org.mockito.Mockito.times;
31 import static org.mockito.Mockito.verify;
32 import static org.mockito.Mockito.when;
34 import java.io.UnsupportedEncodingException;
36 import java.util.Optional;
38 import org.camunda.bpm.engine.delegate.BpmnError;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.mockito.ArgumentMatchers;
42 import org.mockito.InjectMocks;
43 import org.onap.so.adapters.nwrest.CreateNetworkRequest;
44 import org.onap.so.adapters.nwrest.UpdateNetworkRequest;
45 import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
46 import org.onap.so.bpmn.BaseTaskTest;
47 import org.onap.so.bpmn.common.BuildingBlockExecution;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
50 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
51 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
52 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
53 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
54 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
55 import org.onap.so.client.adapter.network.NetworkAdapterClientException;
56 import org.onap.so.client.exception.BBObjectNotFoundException;
57 import org.springframework.beans.factory.annotation.Autowired;
59 public class NetworkAdapterUpdateTasksTest extends BaseTaskTest{
61 private NetworkAdapterUpdateTasks networkAdapterUpdateTasks = new NetworkAdapterUpdateTasks();
63 private ServiceInstance serviceInstance;
64 private L3Network network;
65 private RequestContext requestContext;
66 private CloudRegion cloudRegion;
67 private OrchestrationContext orchestrationContext;
68 private Map<String, String> userInput;
69 private Customer customer;
72 public void before() throws BBObjectNotFoundException {
73 customer = setCustomer();
74 serviceInstance = setServiceInstance();
75 network = setL3Network();
76 requestContext = setRequestContext();
77 cloudRegion = setCloudRegion();
78 orchestrationContext = setOrchestrationContext();
79 userInput = setUserInput();
80 userInput.put("userInputKey1", "userInputValue1");
82 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
83 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))).thenReturn(serviceInstance);
88 public void updateNetworkTest() throws Exception {
89 String cloudRegionPo = "cloudRegionPo";
90 UpdateNetworkRequest updateNetworkRequest = new UpdateNetworkRequest();
91 execution.setVariable("cloudRegionPo", cloudRegionPo);
93 doReturn(updateNetworkRequest).when(networkAdapterObjectMapper).createNetworkUpdateRequestMapper(isA(RequestContext.class), isA(CloudRegion.class), isA(OrchestrationContext.class), isA(ServiceInstance.class), isA(L3Network.class), isA(Map.class), isA(Customer.class));
94 networkAdapterUpdateTasks.updateNetwork(execution);
95 verify(networkAdapterObjectMapper, times(1)).createNetworkUpdateRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer);
96 assertEquals(updateNetworkRequest, execution.getVariable("networkAdapterRequest"));