2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Modifications Copyright (c) 2021 Nokia
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.infrastructure.aai.tasks;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
26 import java.util.Optional;
27 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.junit.MockitoJUnitRunner;
34 import org.onap.so.bpmn.common.BuildingBlockExecution;
35 import org.onap.so.bpmn.common.DelegateExecutionImpl;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
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;
43 @RunWith(MockitoJUnitRunner.class)
44 public class AAICommonTasksTest {
46 private static final String SERVICE_TYPE = "testService";
49 private ExtractPojosForBB extractPojosForBBMock;
51 private ExceptionBuilder exceptionBuilder;
53 private AAICommonTasks testedObject;
55 private ServiceInstance serviceInstance;
56 private BuildingBlockExecution buildingBlockExecution;
60 serviceInstance = new ServiceInstance();
61 buildingBlockExecution = new DelegateExecutionImpl(new DelegateExecutionFake());
65 public void getServiceType_success() throws Exception {
67 ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
68 modelInfoServiceInstance.setServiceType(SERVICE_TYPE);
69 serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);
70 when(extractPojosForBBMock.extractByKey(buildingBlockExecution, ResourceKey.SERVICE_INSTANCE_ID))
71 .thenReturn(serviceInstance);
73 Optional<String> resultOpt = testedObject.getServiceType(buildingBlockExecution);
75 assertThat(resultOpt).isNotEmpty();
76 String result = resultOpt.get();
77 assertThat(result).isEqualTo(SERVICE_TYPE);
81 public void getServiceType_emptyWhenServiceInstanceModelIsNull() throws Exception {
83 when(extractPojosForBBMock.extractByKey(buildingBlockExecution, ResourceKey.SERVICE_INSTANCE_ID))
84 .thenReturn(serviceInstance);
86 Optional<String> result = testedObject.getServiceType(buildingBlockExecution);
88 assertThat(result).isEmpty();
92 public void getServiceType_exceptionHandling() throws Exception {
94 BBObjectNotFoundException exception = new BBObjectNotFoundException();
95 when(extractPojosForBBMock.extractByKey(buildingBlockExecution, ResourceKey.SERVICE_INSTANCE_ID))
96 .thenThrow(exception);
98 testedObject.getServiceType(buildingBlockExecution);
100 verify(exceptionBuilder).buildAndThrowWorkflowException(buildingBlockExecution, 7000, exception);