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.Matchers.any;
24 import static org.mockito.Matchers.eq;
25 import static org.mockito.Mockito.doReturn;
26 import static org.mockito.Mockito.doThrow;
27 import static org.mockito.Mockito.times;
28 import static org.mockito.Mockito.verify;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mock;
35 import org.mockito.runners.MockitoJUnitRunner;
36 import org.onap.so.bpmn.common.data.TestDataSetup;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
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.endpoint.SDNCTopology;
46 import org.onap.so.client.sdnc.mapper.ServiceTopologyOperationMapper;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
51 @RunWith(MockitoJUnitRunner.class)
52 public class SDNCServiceInstanceResourcesTest extends TestDataSetup{
54 private SDNCServiceInstanceResources sdncServiceInstanceResources;
58 protected ServiceTopologyOperationMapper MOCK_serviceTopologyOperationMapper;
60 private RequestContext requestContext;
61 private ServiceInstance serviceInstance;
62 private Customer customer;
65 protected SDNCClient MOCK_sdncClient;
68 public void before() {
69 requestContext = buildRequestContext();
71 serviceInstance = buildServiceInstance();
73 customer = buildCustomer();
75 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
79 public void assignServiceInstanceSuccessTest() throws Exception {
80 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.ASSIGN), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
81 doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
82 sdncServiceInstanceResources.assignServiceInstance(serviceInstance, customer, requestContext);
83 verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
87 public void assignServiceInstanceExceptionTest() throws Exception {
88 expectedException.expect(Exception.class);
89 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.ASSIGN), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
90 doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
91 sdncServiceInstanceResources.assignServiceInstance(serviceInstance, customer, requestContext);
95 public void deleteServiceInstanceSuccessTest() throws Exception {
96 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
97 doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
98 sdncServiceInstanceResources.deleteServiceInstance(serviceInstance, customer, requestContext);
99 verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
103 public void deleteServiceInstanceExceptionTest() throws Exception {
104 expectedException.expect(Exception.class);
105 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
106 doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
107 sdncServiceInstanceResources.deleteServiceInstance(serviceInstance, customer, requestContext);
111 public void unassignServiceInstanceSuccessTest() throws Exception {
112 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
113 doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
114 sdncServiceInstanceResources.unassignServiceInstance(serviceInstance, customer, requestContext);
115 verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
119 public void unassignServiceInstanceExceptionTest() throws Exception {
120 expectedException.expect(Exception.class);
121 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
122 doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
123 sdncServiceInstanceResources.unassignServiceInstance(serviceInstance,customer, requestContext);
127 public void deactivateServiceInstanceSuccessTest() throws Exception {
128 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DEACTIVATE), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
129 doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
130 sdncServiceInstanceResources.deactivateServiceInstance(serviceInstance, customer, requestContext);
131 verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
135 public void deactivateServiceInstanceExceptionTest() throws Exception {
136 expectedException.expect(Exception.class);
137 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DEACTIVATE), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
138 doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
139 sdncServiceInstanceResources.deactivateServiceInstance(serviceInstance, customer, requestContext);
143 public void test_changeModelServiceInstance() throws MapperException, BadResponseException {
144 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.CHANGE_ASSIGN), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
145 doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
146 sdncServiceInstanceResources.changeModelServiceInstance(serviceInstance, customer, requestContext);
147 verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));