Code changes in BPMN infra for RAN Slice Use case
[so.git] / bpmn / so-bpmn-moi / src / test / java / org / onap / so / bpmn / moi / tasks / DeleteRANNssiBBTaskTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (c) 2022 Deutsche telekom
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.moi.tasks;
22
23 import com.fasterxml.jackson.core.JsonProcessingException;
24 import org.camunda.bpm.engine.delegate.BpmnError;
25 import org.junit.Before;
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.rules.ExpectedException;
29 import org.junit.runner.RunWith;
30 import org.mockito.Mock;
31 import org.mockito.junit.MockitoJUnitRunner;
32 import org.onap.aai.domain.yang.ServiceInstance;
33 import org.onap.aai.domain.yang.ServiceSubscription;
34 import org.onap.aaiclient.client.aai.AAIRestClientImpl;
35 import org.onap.so.bpmn.common.BuildingBlockExecution;
36 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
37 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
38 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
39 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
40 import org.onap.so.client.exception.BBObjectNotFoundException;
41 import org.onap.so.client.exception.ExceptionBuilder;
42 import static org.mockito.ArgumentMatchers.any;
43 import static org.mockito.ArgumentMatchers.eq;
44 import static org.mockito.Mockito.*;
45 import static org.mockito.Mockito.times;
46
47 @RunWith(MockitoJUnitRunner.Silent.class)
48
49 public class DeleteRANNssiBBTaskTest {
50
51     @Mock
52     BuildingBlockExecution execution;
53     @Mock
54     ModelInfoServiceInstance modelInfoServiceInstance;
55     @Mock
56     protected ExtractPojosForBB extractPojosForBBMock;
57     @Mock
58     protected ExceptionBuilder exceptionUtil;
59     @Mock
60     ServiceInstance serviceInstance;
61     private String operationalState;
62     private String administrativeState;
63     private String serviceInstanceId = "123";
64
65     private String sliceProfileServiceInstanceId = "123";
66
67     private AAIRestClientImpl aaiRestClient = new AAIRestClientImpl();
68
69     private GeneralBuildingBlock gBB = new GeneralBuildingBlock();
70
71     @Rule
72     public ExpectedException expectedException = ExpectedException.none();
73     @Mock
74     DeleteRANNssiBBTask deleteRANNssiBBTask;
75
76     @Before
77     public void before() throws BBObjectNotFoundException {
78
79         serviceInstance.setServiceInstanceId("123");
80         modelInfoServiceInstance.setModelUuid("231");
81         ServiceInstance serviceInstance = new ServiceInstance();
82         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.SERVICE_INSTANCE_ID)))
83                 .thenReturn(serviceInstanceId);
84         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.ServiceInstance))).thenReturn(serviceInstance);
85         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.ModelInfoServiceInstance)))
86                 .thenReturn(modelInfoServiceInstance);
87         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.operationalState))).thenReturn(operationalState);
88         when(extractPojosForBBMock.extractByKey(any(), eq(ResourceKey.administrativeState)))
89                 .thenReturn(administrativeState);
90         doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
91                 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
92     }
93
94     @Test
95     public void deleteNssiTest() throws JsonProcessingException {
96         doNothing().when(deleteRANNssiBBTask).deleteNssi(execution);
97         deleteRANNssiBBTask.deleteNssi(execution);
98         verify(deleteRANNssiBBTask, times(1)).deleteNssi(execution);
99
100     }
101 }