2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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.adapters.vnf;
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.hamcrest.Matchers.hasProperty;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
27 import static org.mockito.Mockito.when;
31 import javax.xml.ws.Holder;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.rules.ExpectedException;
36 import org.junit.runner.RunWith;
37 import org.mockito.InjectMocks;
38 import org.mockito.Mock;
39 import org.mockito.Mockito;
40 import org.mockito.junit.MockitoJUnitRunner;
41 import org.onap.so.adapters.vnf.exceptions.VnfException;
42 import org.onap.so.openstack.beans.HeatStatus;
43 import org.onap.so.openstack.beans.StackInfo;
44 import org.onap.so.openstack.beans.VnfStatus;
45 import org.onap.so.openstack.exceptions.MsoException;
46 import org.onap.so.openstack.exceptions.MsoOpenstackException;
47 import org.onap.so.openstack.utils.MsoHeatUtils;
49 @RunWith(MockitoJUnitRunner.class)
50 public class QueryTest {
53 private MsoHeatUtils heat;
55 private MsoVnfAdapterImpl vnfAdapter = new MsoVnfAdapterImpl();
58 public ExpectedException thrown = ExpectedException.none();
60 public void testQueryCreatedVnf() throws VnfException, MsoException {
61 StackInfo info = new StackInfo("stackName", HeatStatus.CREATED);
62 when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info);
63 String cloudId = "MT";
64 String cloudOwner = "CloudOwner";
65 String tenantId = "MSO_Test";
66 String vnfName = "VNF_TEST1";
67 Holder<Boolean> vnfExists = new Holder<>();
68 Holder<String> vnfId = new Holder<>();
69 Holder<VnfStatus> status = new Holder<>();
70 Holder<Map<String, String>> outputs = new Holder<>();
72 vnfAdapter.queryVnf(cloudId, cloudOwner, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
74 assertTrue(vnfExists.value);
78 public void testQueryNotFoundVnf() throws VnfException, MsoException {
79 StackInfo info = new StackInfo("stackName", HeatStatus.NOTFOUND);
80 when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info);
81 String cloudId = "MT";
82 String cloudOwner = "CloudOwner";
83 String tenantId = "MSO_Test";
84 String vnfName = "VNF_TEST1";
85 Holder<Boolean> vnfExists = new Holder<>();
86 Holder<String> vnfId = new Holder<>();
87 Holder<VnfStatus> status = new Holder<>();
88 Holder<Map<String, String>> outputs = new Holder<>();
90 vnfAdapter.queryVnf(cloudId, cloudOwner, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
92 assertFalse(vnfExists.value);
96 // @Ignore // 1802 merge
97 public void testQueryVnfWithException() throws VnfException, MsoException {
98 String cloudId = "MT";
99 String cloudOwner = "CloudOwner";
100 String tenantId = "MSO_Test";
101 String vnfName = "VNF_TEST1";
102 Holder<Boolean> vnfExists = new Holder<>();
103 Holder<String> vnfId = new Holder<>();
104 Holder<VnfStatus> status = new Holder<>();
105 Holder<Map<String, String>> outputs = new Holder<>();
106 thrown.expect(VnfException.class);
107 thrown.expectCause(hasProperty("context", is("QueryVNF")));
108 when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenThrow(new MsoOpenstackException(1, "test messsage", "test detail"));
109 vnfAdapter.queryVnf(cloudId, cloudOwner, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);