Merge "Enable DeleteChildService functionality" into recursive-orch
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / adapter / network / tasks / NetworkAdapterUpdateTasksTest.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.adapter.network.tasks;
22
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;
33 import java.io.UnsupportedEncodingException;
34 import java.util.Map;
35 import java.util.Optional;
36 import org.camunda.bpm.engine.delegate.BpmnError;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.mockito.ArgumentMatchers;
40 import org.mockito.InjectMocks;
41 import org.onap.so.adapters.nwrest.CreateNetworkRequest;
42 import org.onap.so.adapters.nwrest.UpdateNetworkRequest;
43 import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
44 import org.onap.so.bpmn.BaseTaskTest;
45 import org.onap.so.bpmn.common.BuildingBlockExecution;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
50 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
51 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
52 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
53 import org.onap.so.client.adapter.network.NetworkAdapterClientException;
54 import org.onap.so.client.exception.BBObjectNotFoundException;
55 import org.springframework.beans.factory.annotation.Autowired;
56
57 public class NetworkAdapterUpdateTasksTest extends BaseTaskTest {
58     @InjectMocks
59     private NetworkAdapterUpdateTasks networkAdapterUpdateTasks = new NetworkAdapterUpdateTasks();
60
61     private ServiceInstance serviceInstance;
62     private L3Network network;
63     private RequestContext requestContext;
64     private CloudRegion cloudRegion;
65     private OrchestrationContext orchestrationContext;
66     private Map<String, String> userInput;
67     private Customer customer;
68
69     @Before
70     public void before() throws BBObjectNotFoundException {
71         customer = setCustomer();
72         serviceInstance = setServiceInstance();
73         network = setL3Network();
74         requestContext = setRequestContext();
75         cloudRegion = setCloudRegion();
76         orchestrationContext = setOrchestrationContext();
77         userInput = setUserInput();
78         userInput.put("userInputKey1", "userInputValue1");
79
80         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
81         when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
82                 .thenReturn(serviceInstance);
83
84     }
85
86     @Test
87     public void updateNetworkTest() throws Exception {
88         String cloudRegionPo = "cloudRegionPo";
89         UpdateNetworkRequest updateNetworkRequest = new UpdateNetworkRequest();
90         execution.setVariable("cloudRegionPo", cloudRegionPo);
91
92         doReturn(updateNetworkRequest).when(networkAdapterObjectMapper).createNetworkUpdateRequestMapper(
93                 isA(RequestContext.class), isA(CloudRegion.class), isA(OrchestrationContext.class),
94                 isA(ServiceInstance.class), isA(L3Network.class), isA(Map.class), isA(Customer.class));
95         networkAdapterUpdateTasks.updateNetwork(execution);
96         verify(networkAdapterObjectMapper, times(1)).createNetworkUpdateRequestMapper(requestContext, cloudRegion,
97                 orchestrationContext, serviceInstance, network, userInput, customer);
98         assertEquals(updateNetworkRequest.toXmlString(), execution.getVariable("networkAdapterRequest"));
99     }
100
101
102 }