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;
32 import org.camunda.bpm.engine.delegate.BpmnError;
33 import org.junit.Before;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.rules.ExpectedException;
37 import org.mockito.ArgumentMatchers;
38 import org.mockito.InjectMocks;
39 import org.onap.so.bpmn.BaseTaskTest;
40 import org.onap.so.bpmn.common.BuildingBlockExecution;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
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 ServiceInstance serviceInstance;
55 private GenericVnf genericVnf;
56 private VfModule vfModule;
59 public void before() throws BBObjectNotFoundException {
60 serviceInstance = setServiceInstance();
61 genericVnf = setGenericVnf();
62 vfModule = setVfModule();
64 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil)
65 .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
66 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID)))
67 .thenReturn(serviceInstance);
69 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID)))
70 .thenReturn(genericVnf);
72 when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
77 public void queryVfModuleTest() throws Exception {
78 String sdncQueryResponse = "response";
79 vfModule.setSelflink("vfModuleSelfLink");
81 doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
83 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
84 sdncQueryTasks.queryVfModule(execution);
85 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
87 verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
91 public void queryVnfTest() throws Exception {
92 String sdncQueryResponse = "response";
94 doReturn(sdncQueryResponse).when(sdncVnfResources).queryVnf(genericVnf);
96 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
97 sdncQueryTasks.queryVnf(execution);
98 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
100 verify(sdncVnfResources, times(1)).queryVnf(genericVnf);
104 public void queryVfModuleForVolumeGroupTest() throws Exception {
105 String sdncQueryResponse = "response";
106 vfModule.setSelflink("vfModuleSelfLink");
108 doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
110 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
111 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
112 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
114 verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
118 public void queryVfModuleForVolumeGroupNoSelfLinkExceptionTest() throws Exception {
119 expectedException.expect(BpmnError.class);
121 vfModule.setSelflink("");
123 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
127 public void queryVfModuleForVolumeGroupVfObjectExceptionTest() throws Exception {
128 expectedException.expect(BpmnError.class);
129 doThrow(RuntimeException.class).when(extractPojosForBB).extractByKey(any(),
130 ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID));
131 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
133 verify(sdncVfModuleResources, times(0)).queryVfModule(any(VfModule.class));
137 public void queryVfModuleForVolumeGroupNonVfObjectExceptionTest() throws Exception {
138 expectedException.expect(BpmnError.class);
140 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);