Springboot 2.0 upgrade
[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.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;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.ArgumentMatchers;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.junit.MockitoJUnitRunner;
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.SDNCClient;
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.endpoint.SDNCTopology;
47 import org.onap.so.client.sdnc.mapper.ServiceTopologyOperationMapper;
48
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
51
52 @RunWith(MockitoJUnitRunner.Silent.class)
53 public class SDNCServiceInstanceResourcesTest  extends TestDataSetup{
54         @InjectMocks
55     private SDNCServiceInstanceResources sdncServiceInstanceResources;
56         
57
58         @Mock
59         protected ServiceTopologyOperationMapper MOCK_serviceTopologyOperationMapper;
60         
61         private RequestContext requestContext;
62         private ServiceInstance serviceInstance;
63         private Customer customer;
64         
65         @Mock
66         protected SDNCClient MOCK_sdncClient;
67         
68         @Before
69         public void before() {
70                 requestContext = buildRequestContext();
71                 
72                 serviceInstance = buildServiceInstance();
73
74                 customer = buildCustomer();
75
76                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
77         }
78         
79         @Test
80         public void assignServiceInstanceSuccessTest() throws Exception {
81                 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));
82                 doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
83                 sdncServiceInstanceResources.assignServiceInstance(serviceInstance, customer, requestContext);
84                 verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
85         }
86         
87         @Test
88         public void assignServiceInstanceExceptionTest() throws Exception {
89                 expectedException.expect(Exception.class);
90                 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));
91                 doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
92                 sdncServiceInstanceResources.assignServiceInstance(serviceInstance, customer, requestContext);
93         }
94         
95         @Test
96         public void deleteServiceInstanceSuccessTest() 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                 doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
99                 sdncServiceInstanceResources.deleteServiceInstance(serviceInstance, customer, requestContext);
100                 verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
101         }
102         
103         @Test
104         public void deleteServiceInstanceExceptionTest() throws Exception {
105                 expectedException.expect(Exception.class);
106                 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));
107                 doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
108                 sdncServiceInstanceResources.deleteServiceInstance(serviceInstance, customer, requestContext);
109         }
110         
111         @Test
112         public void unassignServiceInstanceSuccessTest() throws Exception {
113                 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));
114                 doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
115                 sdncServiceInstanceResources.unassignServiceInstance(serviceInstance, customer, requestContext);
116                 verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
117         }
118         
119         @Test
120         public void unassignServiceInstanceExceptionTest() throws Exception {
121                 expectedException.expect(Exception.class);
122                 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));
123                 doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
124                 sdncServiceInstanceResources.unassignServiceInstance(serviceInstance,customer, requestContext);
125         }
126
127         @Test
128         public void deactivateServiceInstanceSuccessTest() throws Exception {
129                 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));
130                 doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
131                 sdncServiceInstanceResources.deactivateServiceInstance(serviceInstance, customer, requestContext);
132                 verify(MOCK_sdncClient, times(1)).post(ArgumentMatchers.isNull(), eq(SDNCTopology.SERVICE));
133         }
134         
135         @Test
136         public void deactivateServiceInstanceExceptionTest() throws Exception {
137                 expectedException.expect(Exception.class);
138                 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));
139                 doThrow(Exception.class).when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
140                 sdncServiceInstanceResources.deactivateServiceInstance(serviceInstance, customer, requestContext);
141         }
142
143         @Test
144         public void test_changeModelServiceInstance() throws MapperException, BadResponseException {
145                 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));
146                 doReturn("test").when(MOCK_sdncClient).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
147                 sdncServiceInstanceResources.changeModelServiceInstance(serviceInstance, customer, requestContext);
148                 verify(MOCK_sdncClient, times(1)).post(any(GenericResourceApiServiceOperationInformation.class), eq(SDNCTopology.SERVICE));
149         }
150 }