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.Matchers.any;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.times;
28 import static org.mockito.Mockito.verify;
30 import org.camunda.bpm.engine.delegate.BpmnError;
31 import org.junit.Before;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.rules.ExpectedException;
35 import org.onap.so.bpmn.BaseTaskTest;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
38 import org.springframework.beans.factory.annotation.Autowired;
40 public class SDNCQueryTasksTest extends BaseTaskTest{
42 private SDNCQueryTasks sdncQueryTasks;
45 public ExpectedException expectedException = ExpectedException.none();
47 private GenericVnf genericVnf;
48 private VfModule vfModule;
51 public void before() {
52 genericVnf = setGenericVnf();
53 vfModule = setVfModule();
57 public void queryVfModuleTest() throws Exception {
58 String sdncQueryResponse = "response";
59 vfModule.setSelflink("vfModuleSelfLink");
61 doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
63 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
64 sdncQueryTasks.queryVfModule(execution);
65 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
67 verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
71 public void queryVnfTest() throws Exception {
72 String sdncQueryResponse = "response";
74 doReturn(sdncQueryResponse).when(sdncVnfResources).queryVnf(genericVnf);
76 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
77 sdncQueryTasks.queryVnf(execution);
78 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + genericVnf.getVnfId()));
80 verify(sdncVnfResources, times(1)).queryVnf(genericVnf);
84 public void queryVfModuleForVolumeGroupTest() throws Exception {
85 String sdncQueryResponse = "response";
86 vfModule.setSelflink("vfModuleSelfLink");
88 doReturn(sdncQueryResponse).when(sdncVfModuleResources).queryVfModule(vfModule);
90 assertNotEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
91 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
92 assertEquals(sdncQueryResponse, execution.getVariable("SDNCQueryResponse_" + vfModule.getVfModuleId()));
94 verify(sdncVfModuleResources, times(1)).queryVfModule(vfModule);
98 public void queryVfModuleForVolumeGroupNoSelfLinkExceptionTest() throws Exception {
99 expectedException.expect(BpmnError.class);
101 vfModule.setSelflink("");
103 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
107 public void queryVfModuleForVolumeGroupVfObjectExceptionTest() throws Exception {
108 gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0).getVnfs().get(0).getVfModules().clear();
110 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);
112 verify(sdncVfModuleResources, times(0)).queryVfModule(any(VfModule.class));
116 public void queryVfModuleForVolumeGroupNonVfObjectExceptionTest() throws Exception {
117 expectedException.expect(BpmnError.class);
119 sdncQueryTasks.queryVfModuleForVolumeGroup(execution);