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