rename package for external use
[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.ArgumentMatchers.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 import org.camunda.bpm.engine.delegate.BpmnError;
30 import org.camunda.bpm.engine.delegate.DelegateExecution;
31 import org.junit.Before;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
35 import org.mockito.Mock;
36 import org.mockito.MockitoAnnotations;
37 import org.onap.aaiclient.client.aai.AAIResourcesClient;
38 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
39
40 public class AAIDeleteServiceInstanceTest {
41     private AAIDeleteServiceInstance aaiDeleteServiceInstance;
42     @Mock
43     private DelegateExecution execution;
44
45     @Mock
46     private AAIResourcesClient aaiResourcesClient;
47
48     @Rule
49     public ExpectedException expectedException = ExpectedException.none();
50
51
52     @Before
53     public void before() {
54         MockitoAnnotations.initMocks(this);
55
56         aaiDeleteServiceInstance = new AAIDeleteServiceInstance();
57         aaiDeleteServiceInstance.setAaiClient(aaiResourcesClient);
58     }
59
60     @Test
61     public void executeTest() throws Exception {
62         doReturn("serviceInstanceId").when(execution).getVariable("serviceInstanceId");
63         doNothing().when(aaiResourcesClient).delete(isA(AAIResourceUri.class));
64         doNothing().when(execution).setVariable(isA(String.class), isA(Boolean.class));
65
66         aaiDeleteServiceInstance.execute(execution);
67
68         verify(execution, times(1)).getVariable("serviceInstanceId");
69         verify(aaiResourcesClient, times(1)).delete(isA(AAIResourceUri.class));
70         verify(execution, times(1)).setVariable("GENDS_SuccessIndicator", true);
71     }
72
73     @Test
74     public void executeExceptionTest() throws Exception {
75         expectedException.expect(BpmnError.class);
76
77         doReturn("testProcessKey").when(execution).getVariable("testProcessKey");
78         doReturn("serviceInstanceId").when(execution).getVariable("serviceInstanceId");
79         doThrow(RuntimeException.class).when(aaiResourcesClient).delete(isA(AAIResourceUri.class));
80
81         aaiDeleteServiceInstance.execute(execution);
82     }
83 }