2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.moi.tasks;
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;
47 @RunWith(MockitoJUnitRunner.Silent.class)
49 public class DeleteRANNssiBBTaskTest {
52 BuildingBlockExecution execution;
54 ModelInfoServiceInstance modelInfoServiceInstance;
56 protected ExtractPojosForBB extractPojosForBBMock;
58 protected ExceptionBuilder exceptionUtil;
60 ServiceInstance serviceInstance;
61 private String operationalState;
62 private String administrativeState;
63 private String serviceInstanceId = "123";
65 private String sliceProfileServiceInstanceId = "123";
67 private AAIRestClientImpl aaiRestClient = new AAIRestClientImpl();
69 private GeneralBuildingBlock gBB = new GeneralBuildingBlock();
72 public ExpectedException expectedException = ExpectedException.none();
74 DeleteRANNssiBBTask deleteRANNssiBBTask;
77 public void before() throws BBObjectNotFoundException {
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));
95 public void deleteNssiTest() throws JsonProcessingException {
96 doNothing().when(deleteRANNssiBBTask).deleteNssi(execution);
97 deleteRANNssiBBTask.deleteNssi(execution);
98 verify(deleteRANNssiBBTask, times(1)).deleteNssi(execution);