509dc1de0d1d823b11b219623af4c206cafce783
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / orchestration / SDNCServiceInstanceResourcesTest.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.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
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.junit.MockitoJUnitRunner;
36 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
37 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
38 import org.onap.so.bpmn.common.data.TestDataSetup;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
41 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
42 import org.onap.so.client.exception.BadResponseException;
43 import org.onap.so.client.exception.MapperException;
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.ServiceTopologyOperationMapper;
47
48 @RunWith(MockitoJUnitRunner.Silent.class)
49 public class SDNCServiceInstanceResourcesTest  extends TestDataSetup{
50         
51         @InjectMocks
52     private SDNCServiceInstanceResources sdncServiceInstanceResources;
53         @Mock
54         protected ServiceTopologyOperationMapper MOCK_serviceTopologyOperationMapper;
55         private RequestContext requestContext;
56         private ServiceInstance serviceInstance;
57         private Customer customer;
58         
59         @Before
60         public void before() {
61                 requestContext = buildRequestContext();
62                 serviceInstance = buildServiceInstance();
63                 customer = buildCustomer();
64                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
65         }
66         
67         @Test
68         public void assignServiceInstanceSuccessTest() throws Exception {
69                 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));
70                 sdncServiceInstanceResources.assignServiceInstance(serviceInstance, customer, requestContext);
71                 verify(MOCK_serviceTopologyOperationMapper, times(1)).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.ASSIGN), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
72         }
73         
74         @Test
75         public void assignServiceInstanceExceptionTest() throws Exception {
76                 expectedException.expect(Exception.class);
77                 doThrow(Exception.class).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.ASSIGN), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
78                 sdncServiceInstanceResources.assignServiceInstance(serviceInstance, customer, requestContext);
79         }
80         
81         @Test
82         public void deleteServiceInstanceSuccessTest() throws Exception {
83                 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));
84                 sdncServiceInstanceResources.deleteServiceInstance(serviceInstance, customer, requestContext);
85                 verify(MOCK_serviceTopologyOperationMapper, times(1)).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
86         }
87         
88         @Test
89         public void deleteServiceInstanceExceptionTest() throws Exception {
90                 expectedException.expect(Exception.class);
91                 doThrow(Exception.class).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
92                 sdncServiceInstanceResources.deleteServiceInstance(serviceInstance, customer, requestContext);
93         }
94         
95         @Test
96         public void unassignServiceInstanceSuccessTest() throws Exception {
97                 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));
98                 sdncServiceInstanceResources.unassignServiceInstance(serviceInstance, customer, requestContext);
99                 verify(MOCK_serviceTopologyOperationMapper, times(1)).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DELETE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
100         }
101         
102         @Test
103         public void unassignServiceInstanceExceptionTest() throws Exception {
104                 expectedException.expect(Exception.class);
105                 doThrow(Exception.class).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                 sdncServiceInstanceResources.unassignServiceInstance(serviceInstance,customer, requestContext);
107         }
108
109         @Test
110         public void deactivateServiceInstanceSuccessTest() throws Exception {
111                 doReturn(new GenericResourceApiServiceOperationInformation()).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DEACTIVATE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
112                 sdncServiceInstanceResources.deactivateServiceInstance(serviceInstance, customer, requestContext);
113                 verify(MOCK_serviceTopologyOperationMapper, times(1)).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DEACTIVATE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
114         }
115         
116         @Test
117         public void deactivateServiceInstanceExceptionTest() throws Exception {
118                 expectedException.expect(Exception.class);
119                 doThrow(Exception.class).when(MOCK_serviceTopologyOperationMapper).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.DEACTIVATE), eq(GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
120                 sdncServiceInstanceResources.deactivateServiceInstance(serviceInstance, customer, requestContext);
121         }
122
123         @Test
124         public void test_changeModelServiceInstance() throws MapperException, BadResponseException {
125                 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));
126                 sdncServiceInstanceResources.changeModelServiceInstance(serviceInstance, customer, requestContext);
127                 verify(MOCK_serviceTopologyOperationMapper, times(1)).reqMapper(eq(SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION), eq(SDNCSvcAction.CHANGE_ASSIGN), eq(GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE), any(ServiceInstance.class), any(Customer.class), any(RequestContext.class));
128         }
129 }