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.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.isA;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.times;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.ArgumentMatchers;
35 import org.mockito.InjectMocks;
36 import org.mockito.Mock;
37 import org.mockito.junit.MockitoJUnitRunner;
38 import org.onap.so.adapters.nwrest.UpdateNetworkRequest;
39 import org.onap.so.bpmn.common.data.TestDataSetup;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
44 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
45 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
46 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
47 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
48 import org.onap.so.client.adapter.network.mapper.NetworkAdapterObjectMapper;
49 import org.onap.so.client.exception.BBObjectNotFoundException;
51 @RunWith(MockitoJUnitRunner.Silent.class)
52 public class NetworkAdapterUpdateTasksTest extends TestDataSetup {
54 protected ExtractPojosForBB extractPojosForBB;
56 protected NetworkAdapterObjectMapper networkAdapterObjectMapper;
58 private NetworkAdapterUpdateTasks networkAdapterUpdateTasks = new NetworkAdapterUpdateTasks();
60 private ServiceInstance serviceInstance;
61 private L3Network network;
62 private RequestContext requestContext;
63 private CloudRegion cloudRegion;
64 private OrchestrationContext orchestrationContext;
65 private Map<String, String> userInput;
66 private Customer customer;
69 public void before() throws BBObjectNotFoundException {
70 customer = setCustomer();
71 serviceInstance = setServiceInstance();
72 network = setL3Network();
73 requestContext = setRequestContext();
74 cloudRegion = setCloudRegion();
75 orchestrationContext = setOrchestrationContext();
76 userInput = setUserInput();
77 userInput.put("userInputKey1", "userInputValue1");
79 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.NETWORK_ID))).thenReturn(network);
80 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
81 .thenReturn(serviceInstance);
86 public void updateNetworkTest() {
87 String cloudRegionPo = "cloudRegionPo";
88 UpdateNetworkRequest updateNetworkRequest = new UpdateNetworkRequest();
89 execution.setVariable("cloudRegionPo", cloudRegionPo);
91 doReturn(updateNetworkRequest).when(networkAdapterObjectMapper).createNetworkUpdateRequestMapper(
92 isA(RequestContext.class), isA(CloudRegion.class), isA(OrchestrationContext.class),
93 isA(ServiceInstance.class), isA(L3Network.class), isA(Map.class), isA(Customer.class));
94 networkAdapterUpdateTasks.updateNetwork(execution);
95 verify(networkAdapterObjectMapper, times(1)).createNetworkUpdateRequestMapper(requestContext, cloudRegion,
96 orchestrationContext, serviceInstance, network, userInput, customer);
97 assertEquals(updateNetworkRequest.toXmlString(), execution.getVariable("networkAdapterRequest"));