6489c9b14978aa71b17ef709250a9f5998897a98
[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.Mockito.doReturn;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28
29 import java.util.Map;
30 import java.util.Optional;
31
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
36 import org.onap.so.bpmn.BaseTaskTest;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
41 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
42 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
43 import org.springframework.beans.factory.annotation.Autowired;
44
45 public class NetworkAdapterUpdateTasksTest extends BaseTaskTest{
46         @Autowired
47         private NetworkAdapterUpdateTasks networkAdapterUpdateTasks;
48         
49         private ServiceInstance serviceInstance;
50         private L3Network network;
51         private RequestContext requestContext;
52         private CloudRegion cloudRegion;
53         private OrchestrationContext orchestrationContext;
54         private Map<String, String> userInput;
55         private Customer customer;
56         
57         @Before
58         public void before() {
59                 customer = setCustomer();
60                 serviceInstance = setServiceInstance();
61                 network = setL3Network();
62                 requestContext = setRequestContext();
63                 cloudRegion = setCloudRegion();
64                 orchestrationContext = setOrchestrationContext();
65                 userInput = setUserInput();
66                 userInput.put("userInputKey1", "userInputValue1");
67
68         }
69         
70         @Test
71         public void updateNetworkTest() throws Exception {
72                 UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse();
73                 updateNetworkResponse.setMessageId("messageId");
74                 updateNetworkResponse.setNetworkId("networkId");
75                 Optional<UpdateNetworkResponse> oUpdateNetworkResponse = Optional.of(updateNetworkResponse);
76                 
77                 doReturn(oUpdateNetworkResponse).when(networkAdapterResources).updateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer);
78                 
79                 networkAdapterUpdateTasks.updateNetwork(execution);
80                 
81                 verify(networkAdapterResources, times(1)).updateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer);
82                 assertEquals(updateNetworkResponse, execution.getVariable("NetworkAdapterUpdateNetworkResponse"));
83         }
84         
85         @Test
86         public void updateNetworkNoResponseTest() throws Exception {
87                 doReturn(Optional.empty()).when(networkAdapterResources).updateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer);
88                 
89                 networkAdapterUpdateTasks.updateNetwork(execution);
90                 
91                 verify(networkAdapterResources, times(1)).updateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer);
92                 assertNull(execution.getVariable("NetworkAdapterUpdateNetworkResponse"));
93         }
94         
95         @Test
96         public void updateNetworkExceptionTest() {
97                 expectedException.expect(BpmnError.class);
98                 
99                 networkAdapterUpdateTasks.updateNetwork(execution);
100         }
101 }