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.ServiceInstance;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
45 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
46 import org.onap.so.client.exception.BBObjectNotFoundException;
48 public class SDNCQueryTasksTest extends BaseTaskTest{
50 private SDNCQueryTasks sdncQueryTasks = new SDNCQueryTasks();
53 public ExpectedException expectedException = ExpectedException.none();
55 private ServiceInstance serviceInstance;
56 private GenericVnf genericVnf;
57 private VfModule vfModule;
60 public void before() throws BBObjectNotFoundException {
61 serviceInstance = setServiceInstance();
62 genericVnf = setGenericVnf();
63 vfModule = setVfModule();
65 doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class));
66 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))).thenReturn(serviceInstance);
68 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(genericVnf);
70 when(extractPojosForBB.extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
75 public void queryVfModuleTest() throws Exception {
76 String sdncQueryResponse = "response";
77 vfModule.setSelflink("vfModuleSelfLink");
79 doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
81 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
82 sdncQueryTasks.queryVfModule(execution);
83 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
85 verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
89 public void queryVnfTest() throws Exception {
90 String sdncQueryResponse = "response";
92 doReturn(sdncQueryResponse).when(sdncVnfResources).queryVnf(genericVnf);
94 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
95 sdncQueryTasks.queryVnf(execution);
96 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
98 verify(sdncVnfResources, times(1)).queryVnf(genericVnf);
102 public void queryVfModuleForVolumeGroupTest() throws Exception {
103 String sdncQueryResponse = "response";
104 vfModule.setSelflink("vfModuleSelfLink");
106 doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
108 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
109 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
110 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
112 verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
116 public void queryVfModuleForVolumeGroupNoSelfLinkExceptionTest() throws Exception {
117 expectedException.expect(BpmnError.class);
119 vfModule.setSelflink("");
121 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
125 public void queryVfModuleForVolumeGroupVfObjectExceptionTest() throws Exception {
126 expectedException.expect(BpmnError.class);
127 doThrow(RuntimeException.class).when(extractPojosForBB).extractByKey(any(),ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID));
128 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
130 verify(sdncVfModuleResources, times(0)).queryVfModule(any(VfModule.class));
134 public void queryVfModuleForVolumeGroupNonVfObjectExceptionTest() throws Exception {
135 expectedException.expect(BpmnError.class);
137 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);