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.junit.Assert.assertEquals;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Matchers.eq;
26 import static org.mockito.ArgumentMatchers.isA;
27 import static org.mockito.Mockito.doReturn;
28 import static org.mockito.Mockito.times;
29 import static org.mockito.Mockito.verify;
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.bpmn.common.data.TestDataSetup;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
44 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
45 import org.onap.so.client.exception.BadResponseException;
46 import org.onap.so.client.exception.MapperException;
47 import org.onap.so.client.sdnc.SDNCClient;
48 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
49 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
50 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
51 import org.onap.so.client.sdnc.mapper.NetworkTopologyOperationRequestMapper;
52 import org.onap.so.db.catalog.beans.OrchestrationStatus;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
57 @RunWith(MockitoJUnitRunner.Silent.class)
58 public class SDNCNetworkResourcesTest extends TestDataSetup{
61 private SDNCNetworkResources sdncNetworkResources;
64 protected SDNCClient MOCK_sdncClient;
67 protected NetworkTopologyOperationRequestMapper MOCK_networkTopologyOperationRequestMapper;
69 private L3Network network;
70 private ServiceInstance serviceInstance;
71 private Customer customer;
72 private RequestContext requestContext;
73 private CloudRegion cloudRegion;
76 public void before() {
77 network = buildL3Network();
79 customer = buildCustomer();
81 serviceInstance = buildServiceInstance();
83 requestContext = buildRequestContext();
85 cloudRegion = new CloudRegion();
89 public void assignNetworkTest() throws Exception {
90 network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
92 doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK));
94 sdncNetworkResources.assignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
96 verify(MOCK_sdncClient, times(1)).post(ArgumentMatchers.isNull(), eq(SDNCTopology.NETWORK));
98 assertEquals(OrchestrationStatus.ASSIGNED, network.getOrchestrationStatus());
102 public void rollbackAssignNetworkTest() throws Exception {
103 network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
105 doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK));
107 sdncNetworkResources.rollbackAssignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
109 verify(MOCK_sdncClient, times(1)).post(ArgumentMatchers.isNull(), eq(SDNCTopology.NETWORK));
111 assertEquals(OrchestrationStatus.ASSIGNED, network.getOrchestrationStatus());
115 public void activateNetworkTest() throws Exception {
116 network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
118 doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK));
120 sdncNetworkResources.activateNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
122 verify(MOCK_sdncClient, times(1)).post(ArgumentMatchers.isNull(), eq(SDNCTopology.NETWORK));
124 assertEquals(OrchestrationStatus.ASSIGNED, network.getOrchestrationStatus());
128 public void deleteNetworkTest() throws Exception {
129 network.setOrchestrationStatus(OrchestrationStatus.ASSIGNED);
131 doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK));
133 sdncNetworkResources.deleteNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
135 verify(MOCK_sdncClient, times(1)).post(ArgumentMatchers.isNull(), eq(SDNCTopology.NETWORK));
137 assertEquals(OrchestrationStatus.ASSIGNED, network.getOrchestrationStatus());
141 public void test_deactivateNetwork() throws MapperException, BadResponseException {
142 serviceInstance.getNetworks().add(network);
144 Customer customer = new Customer();
145 customer.setGlobalCustomerId("gcustId");
146 customer.setServiceSubscription(new ServiceSubscription());
147 // set Customer on service instance
148 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
150 GenericResourceApiNetworkOperationInformation expectedGenericResourceApiNetworkOperationInformation = new GenericResourceApiNetworkOperationInformation();
152 String expectedResponse = "response";
154 doReturn(expectedResponse).when(MOCK_sdncClient).post(expectedGenericResourceApiNetworkOperationInformation, SDNCTopology.NETWORK);
156 doReturn(expectedGenericResourceApiNetworkOperationInformation).when(MOCK_networkTopologyOperationRequestMapper).reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.DEACTIVATE, GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, customer, requestContext, cloudRegion);
158 String actualResponse = sdncNetworkResources.deactivateNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
160 verify(MOCK_networkTopologyOperationRequestMapper, times(1)).reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.DEACTIVATE, GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, customer, requestContext, cloudRegion);
162 verify(MOCK_sdncClient).post(expectedGenericResourceApiNetworkOperationInformation, SDNCTopology.NETWORK);
164 assertEquals(expectedResponse, actualResponse);
168 public void changeAssignNetworkTest() throws MapperException, BadResponseException {
169 String expectedSdncResponse = "SDNCChangeAssignNetworkResponse";
171 serviceInstance.getNetworks().add(network);
173 Customer customer = new Customer();
174 customer.setGlobalCustomerId("globalCustomerId");
175 customer.setServiceSubscription(new ServiceSubscription());
176 // set Customer on service instance
177 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
179 GenericResourceApiNetworkOperationInformation sdncReq = new GenericResourceApiNetworkOperationInformation();
181 doReturn(sdncReq).when(MOCK_networkTopologyOperationRequestMapper).reqMapper(isA(SDNCSvcOperation.class), isA(SDNCSvcAction.class), isA(GenericResourceApiRequestActionEnumeration.class), isA(L3Network.class), isA(ServiceInstance.class), isA(Customer.class), isA(RequestContext.class), isA(CloudRegion.class));
183 doReturn(expectedSdncResponse).when(MOCK_sdncClient).post(isA(GenericResourceApiNetworkOperationInformation.class), isA(SDNCTopology.class));
185 String actualSdncResponse = sdncNetworkResources.changeAssignNetwork(network, serviceInstance, customer, requestContext, cloudRegion);
187 verify(MOCK_networkTopologyOperationRequestMapper, times(1)).reqMapper(SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.CHANGE_ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer, requestContext, cloudRegion);
188 verify(MOCK_sdncClient, times(1)).post(sdncReq, SDNCTopology.NETWORK);
189 assertEquals(actualSdncResponse, expectedSdncResponse);
193 public void unassignNetwork_Test() throws Exception {
194 network.setOrchestrationStatus(OrchestrationStatus.CREATED);
196 doReturn("test").when(MOCK_sdncClient).post(isA(GenericResourceApiNetworkOperationInformation.class), eq(SDNCTopology.NETWORK));
198 sdncNetworkResources.unassignNetwork(network, serviceInstance, customer,
199 requestContext, cloudRegion);
201 verify(MOCK_sdncClient, times(1)).post(ArgumentMatchers.isNull(), eq(SDNCTopology.NETWORK));
203 assertEquals(OrchestrationStatus.CREATED, network.getOrchestrationStatus());