f275f3c484ab5114745290c7eaaa856f40bdb159
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / orchestration / SDNCNetworkResourcesTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.client.orchestration;
22
23 import static org.mockito.Mockito.doReturn;
24 import static org.mockito.Mockito.times;
25 import static org.mockito.Mockito.verify;
26
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.InjectMocks;
31 import org.mockito.Mock;
32 import org.mockito.junit.MockitoJUnitRunner;
33 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
34 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
35 import org.onap.so.bpmn.common.data.TestDataSetup;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
40 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
41 import org.onap.so.client.exception.BadResponseException;
42 import org.onap.so.client.exception.MapperException;
43 import org.onap.so.client.sdnc.SDNCClient;
44 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
45 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
46 import org.onap.so.client.sdnc.mapper.NetworkTopologyOperationRequestMapper;
47
48 @RunWith(MockitoJUnitRunner.Silent.class)
49 public class SDNCNetworkResourcesTest extends TestDataSetup {
50
51         @InjectMocks
52         private SDNCNetworkResources sdncNetworkResources;
53
54         @Mock
55         protected SDNCClient MOCK_sdncClient;
56
57         @Mock
58         protected NetworkTopologyOperationRequestMapper MOCK_networkTopologyOperationRequestMapper;
59
60         private L3Network network;
61         private ServiceInstance serviceInstance;
62         private Customer customer;
63         private RequestContext requestContext;
64         private CloudRegion cloudRegion;
65
66         @Before
67         public void before() {
68                 network = buildL3Network();
69
70                 customer = buildCustomer();
71
72                 serviceInstance = buildServiceInstance();
73
74                 requestContext = buildRequestContext();
75
76                 cloudRegion = new CloudRegion();
77         }
78
79         @Test
80         public void assignNetworkTest() throws Exception {
81                 doReturn(new GenericResourceApiNetworkOperationInformation()).when(MOCK_networkTopologyOperationRequestMapper)
82                                 .reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
83                                                 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance,
84                                                 customer, requestContext, cloudRegion);
85                 sdncNetworkResources.assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
86                 verify(MOCK_networkTopologyOperationRequestMapper, times(1)).reqMapper(
87                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
88                                 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
89                                 requestContext, cloudRegion);
90         }
91
92         @Test
93         public void rollbackAssignNetworkTest() throws Exception {
94                 doReturn(new GenericResourceApiNetworkOperationInformation()).when(MOCK_networkTopologyOperationRequestMapper)
95                                 .reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN,
96                                                 GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance,
97                                                 customer, requestContext, cloudRegion);
98                 sdncNetworkResources.rollbackAssignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
99                 verify(MOCK_networkTopologyOperationRequestMapper, times(1)).reqMapper(
100                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN,
101                                 GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, customer,
102                                 requestContext, cloudRegion);
103         }
104
105         @Test
106         public void activateNetworkTest() throws Exception {
107                 doReturn(new GenericResourceApiNetworkOperationInformation()).when(MOCK_networkTopologyOperationRequestMapper)
108                                 .reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ACTIVATE,
109                                                 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance,
110                                                 customer, requestContext, cloudRegion);
111                 sdncNetworkResources.activateNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
112                 verify(MOCK_networkTopologyOperationRequestMapper, times(1)).reqMapper(
113                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ACTIVATE,
114                                 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
115                                 requestContext, cloudRegion);
116         }
117
118         @Test
119         public void deleteNetworkTest() throws Exception {
120                 doReturn(new GenericResourceApiNetworkOperationInformation()).when(MOCK_networkTopologyOperationRequestMapper)
121                                 .reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.DELETE,
122                                                 GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance,
123                                                 customer, requestContext, cloudRegion);
124                 sdncNetworkResources.deleteNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
125                 verify(MOCK_networkTopologyOperationRequestMapper, times(1)).reqMapper(
126                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.DELETE,
127                                 GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, customer,
128                                 requestContext, cloudRegion);
129         }
130
131         @Test
132         public void test_deactivateNetwork() throws MapperException, BadResponseException {
133                 doReturn(new GenericResourceApiNetworkOperationInformation()).when(MOCK_networkTopologyOperationRequestMapper)
134                                 .reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.DEACTIVATE,
135                                                 GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance,
136                                                 customer, requestContext, cloudRegion);
137                 sdncNetworkResources.deactivateNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
138                 verify(MOCK_networkTopologyOperationRequestMapper, times(1)).reqMapper(
139                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.DEACTIVATE,
140                                 GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, customer,
141                                 requestContext, cloudRegion);
142         }
143
144         @Test
145         public void changeAssignNetworkTest() throws MapperException, BadResponseException {
146                 doReturn(new GenericResourceApiNetworkOperationInformation()).when(MOCK_networkTopologyOperationRequestMapper)
147                                 .reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.CHANGE_ASSIGN,
148                                                 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance,
149                                                 customer, requestContext, cloudRegion);
150                 sdncNetworkResources.changeAssignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
151                 verify(MOCK_networkTopologyOperationRequestMapper, times(1)).reqMapper(
152                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.CHANGE_ASSIGN,
153                                 GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
154                                 requestContext, cloudRegion);
155         }
156
157         @Test
158         public void unassignNetwork_Test() throws Exception {
159                 doReturn(new GenericResourceApiNetworkOperationInformation()).when(MOCK_networkTopologyOperationRequestMapper)
160                                 .reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN,
161                                                 GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance,
162                                                 customer, requestContext, cloudRegion);
163                 sdncNetworkResources.unassignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
164                 verify(MOCK_networkTopologyOperationRequestMapper, times(1)).reqMapper(
165                                 SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN,
166                                 GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, customer,
167                                 requestContext, cloudRegion);
168         }
169 }