5808a330a38787680a9f3afab835500d551374fe
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / java / org / onap / so / bpmn / infrastructure / aai / AAIDeleteServiceInstanceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 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.bpmn.infrastructure.aai;
22
23 import static org.mockito.Matchers.isA;
24 import static org.mockito.Mockito.doNothing;
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.camunda.bpm.engine.delegate.BpmnError;
31 import org.camunda.bpm.engine.delegate.DelegateExecution;
32 import org.junit.Before;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.rules.ExpectedException;
36 import org.mockito.Mock;
37 import org.mockito.MockitoAnnotations;
38 import org.onap.so.client.aai.AAIResourcesClient;
39 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
40
41 public class AAIDeleteServiceInstanceTest  {
42         private AAIDeleteServiceInstance aaiDeleteServiceInstance;
43         @Mock
44         private DelegateExecution execution;
45         
46         @Mock
47         private AAIResourcesClient aaiResourcesClient;
48         
49         @Rule
50         public ExpectedException expectedException = ExpectedException.none();
51         
52         
53         @Before
54         public void before() {
55                 MockitoAnnotations.initMocks(this);
56                 
57                 aaiDeleteServiceInstance = new AAIDeleteServiceInstance();
58                 aaiDeleteServiceInstance.setAaiClient(aaiResourcesClient);
59         }
60         
61         @Test
62         public void executeTest() throws Exception {
63                 doReturn("serviceInstanceId").when(execution).getVariable("serviceInstanceId");
64                 doNothing().when(aaiResourcesClient).delete(isA(AAIResourceUri.class));
65                 doNothing().when(execution).setVariable(isA(String.class), isA(Boolean.class));
66                 
67                 aaiDeleteServiceInstance.execute(execution);
68                 
69                 verify(execution, times(1)).getVariable("serviceInstanceId");
70                 verify(aaiResourcesClient, times(1)).delete(isA(AAIResourceUri.class));
71                 verify(execution, times(1)).setVariable("GENDS_SuccessIndicator", true);
72         }
73         
74         @Test
75         public void executeExceptionTest() throws Exception {
76                 expectedException.expect(BpmnError.class);
77                 
78                 doReturn("testProcessKey").when(execution).getVariable("testProcessKey");
79                 doReturn("serviceInstanceId").when(execution).getVariable("serviceInstanceId");
80                 doThrow(Exception.class).when(aaiResourcesClient).delete(isA(AAIResourceUri.class));
81                 
82                 aaiDeleteServiceInstance.execute(execution);
83         }
84 }