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.ArgumentMatchers.any;
24 import static org.mockito.ArgumentMatchers.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;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
36 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
37 import org.onap.so.bpmn.common.data.TestDataSetup;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
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.beans.SDNCSvcAction;
44 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
45 import org.onap.so.client.sdnc.mapper.ServiceTopologyOperationMapper;
47 @RunWith(MockitoJUnitRunner.Silent.class)
48 public class SDNCServiceInstanceResourcesTest extends TestDataSetup {
51 private SDNCServiceInstanceResources sdncServiceInstanceResources;
53 protected ServiceTopologyOperationMapper MOCK_serviceTopologyOperationMapper;
54 private RequestContext requestContext;
55 private ServiceInstance serviceInstance;
56 private Customer customer;
59 public void before() {
60 requestContext = buildRequestContext();
61 serviceInstance = buildServiceInstance();
62 customer = buildCustomer();
63 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
67 public void assignServiceInstanceSuccessTest() throws Exception {
68 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper)
69 .reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.ASSIGN),
70 eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE),
71 any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
72 sdncServiceInstanceResources.assignServiceInstance(serviceInstance, customer, requestContext);
73 verify(MOCK_serviceTopologyOperationMapper, times(1)).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION),
74 eq(SDNCSvcAction.ASSIGN), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE),
75 any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
79 public void assignServiceInstanceExceptionTest() throws Exception {
80 expectedException.expect(Exception.class);
81 doThrow(Exception.class).when(MOCK_serviceTopologyOperationMapper).reqMapper(
82 eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.ASSIGN),
83 eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class),
84 any(Customer.class), any(RequestContext.class));
85 sdncServiceInstanceResources.assignServiceInstance(serviceInstance, customer, requestContext);
89 public void deleteServiceInstanceSuccessTest() throws Exception {
90 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper)
91 .reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE),
92 eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE),
93 any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
94 sdncServiceInstanceResources.deleteServiceInstance(serviceInstance, customer, requestContext);
95 verify(MOCK_serviceTopologyOperationMapper, times(1)).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION),
96 eq(SDNCSvcAction.DELETE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE),
97 any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
101 public void deleteServiceInstanceExceptionTest() throws Exception {
102 expectedException.expect(Exception.class);
103 doThrow(Exception.class).when(MOCK_serviceTopologyOperationMapper).reqMapper(
104 eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE),
105 eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class),
106 any(Customer.class), any(RequestContext.class));
107 sdncServiceInstanceResources.deleteServiceInstance(serviceInstance, customer, requestContext);
111 public void unassignServiceInstanceSuccessTest() throws Exception {
112 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper)
113 .reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE),
114 eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE),
115 any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
116 sdncServiceInstanceResources.unassignServiceInstance(serviceInstance, customer, requestContext);
117 verify(MOCK_serviceTopologyOperationMapper, times(1)).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION),
118 eq(SDNCSvcAction.DELETE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE),
119 any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
123 public void unassignServiceInstanceExceptionTest() throws Exception {
124 expectedException.expect(Exception.class);
125 doThrow(Exception.class).when(MOCK_serviceTopologyOperationMapper).reqMapper(
126 eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE),
127 eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class),
128 any(Customer.class), any(RequestContext.class));
129 sdncServiceInstanceResources.unassignServiceInstance(serviceInstance, customer, requestContext);
133 public void deactivateServiceInstanceSuccessTest() throws Exception {
134 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper)
135 .reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DEACTIVATE),
136 eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE),
137 any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
138 sdncServiceInstanceResources.deactivateServiceInstance(serviceInstance, customer, requestContext);
139 verify(MOCK_serviceTopologyOperationMapper, times(1)).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION),
140 eq(SDNCSvcAction.DEACTIVATE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE),
141 any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
145 public void deactivateServiceInstanceExceptionTest() throws Exception {
146 expectedException.expect(Exception.class);
147 doThrow(Exception.class).when(MOCK_serviceTopologyOperationMapper).reqMapper(
148 eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DEACTIVATE),
149 eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class),
150 any(Customer.class), any(RequestContext.class));
151 sdncServiceInstanceResources.deactivateServiceInstance(serviceInstance, customer, requestContext);
155 public void test_changeModelServiceInstance() throws MapperException, BadResponseException {
156 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper)
157 .reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.CHANGE_ASSIGN),
158 eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE),
159 any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
160 sdncServiceInstanceResources.changeModelServiceInstance(serviceInstance, customer, requestContext);
161 verify(MOCK_serviceTopologyOperationMapper, times(1)).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION),
162 eq(SDNCSvcAction.CHANGE_ASSIGN), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE),
163 any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));