2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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
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.sdnc.tasks;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotEquals;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.ArgumentMatchers.eq;
27 import static org.mockito.Mockito.doReturn;
28 import static org.mockito.Mockito.doThrow;
29 import static org.mockito.Mockito.times;
30 import static org.mockito.Mockito.verify;
31 import static org.mockito.Mockito.when;
33 import org.camunda.bpm.engine.delegate.BpmnError;
34 import org.junit.Before;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.rules.ExpectedException;
38 import org.mockito.ArgumentMatchers;
39 import org.mockito.InjectMocks;
40 import org.onap.so.bpmn.BaseTaskTest;
41 import org.onap.so.bpmn.common.BuildingBlockExecution;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
44 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
45 import org.onap.so.client.exception.BBObjectNotFoundException;
47 public class SDNCQueryTasksTest extends BaseTaskTest{
49 private SDNCQueryTasks sdncQueryTasks = new SDNCQueryTasks();
52 public ExpectedException expectedException = ExpectedException.none();
54 private GenericVnf genericVnf;
55 private VfModule vfModule;
58 public void before() throws BBObjectNotFoundException {
59 genericVnf = setGenericVnf();
60 vfModule = setVfModule();
62 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
63 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID), any())).thenReturn(genericVnf);
65 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any())).thenReturn(vfModule);
70 public void queryVfModuleTest() throws Exception {
71 String sdncQueryResponse = "response";
72 vfModule.setSelflink("vfModuleSelfLink");
74 doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
76 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
77 sdncQueryTasks.queryVfModule(execution);
78 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
80 verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
84 public void queryVnfTest() throws Exception {
85 String sdncQueryResponse = "response";
87 doReturn(sdncQueryResponse).when(sdncVnfResources).queryVnf(genericVnf);
89 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
90 sdncQueryTasks.queryVnf(execution);
91 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
93 verify(sdncVnfResources, times(1)).queryVnf(genericVnf);
97 public void queryVfModuleForVolumeGroupTest() throws Exception {
98 String sdncQueryResponse = "response";
99 vfModule.setSelflink("vfModuleSelfLink");
101 doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
103 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
104 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
105 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
107 verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
111 public void queryVfModuleForVolumeGroupNoSelfLinkExceptionTest() throws Exception {
112 expectedException.expect(BpmnError.class);
114 vfModule.setSelflink("");
116 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
120 public void queryVfModuleForVolumeGroupVfObjectExceptionTest() throws Exception {
121 expectedException.expect(BpmnError.class);
122 doThrow(RuntimeException.class).when(extractPojosForBB).extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID), any());
123 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
125 verify(sdncVfModuleResources, times(0)).queryVfModule(any(VfModule.class));
129 public void queryVfModuleForVolumeGroupNonVfObjectExceptionTest() throws Exception {
130 expectedException.expect(BpmnError.class);
132 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);