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.openecomp.mso.adapters.vnf;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.Mockito.when;
29 import javax.xml.ws.Holder;
31 import org.junit.Test;
32 import org.mockito.Mockito;
33 import org.openecomp.mso.adapters.vnf.exceptions.VnfException;
34 import org.openecomp.mso.cloud.CloudConfigFactory;
35 import org.openecomp.mso.openstack.beans.HeatStatus;
36 import org.openecomp.mso.openstack.beans.StackInfo;
37 import org.openecomp.mso.openstack.beans.VnfStatus;
38 import org.openecomp.mso.openstack.exceptions.MsoException;
39 import org.openecomp.mso.openstack.utils.MsoHeatUtils;
40 import org.openecomp.mso.properties.MsoJavaProperties;
41 import org.openecomp.mso.properties.MsoPropertiesFactory;
43 public class QueryTest {
46 public void testQueryCreatedVnf() throws VnfException, MsoException {
48 StackInfo info = new StackInfo("stackName", HeatStatus.CREATED);
49 MsoVnfAdapterImpl vnfAdapter = new MsoVnfAdapterImpl();
50 vnfAdapter.heat = Mockito.mock(MsoHeatUtils.class);
51 when(vnfAdapter.heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info);
52 String cloudId = "MT";
53 String tenantId = "MSO_Test";
54 String vnfName = "VNF_TEST1";
55 Holder<Boolean> vnfExists = new Holder<>();
56 Holder<String> vnfId = new Holder<>();
57 Holder<VnfStatus> status = new Holder<>();
58 Holder<Map<String, String>> outputs = new Holder<>();
60 vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
62 assertTrue(vnfExists.value);
67 public void testQueryNotFoundVnf() throws VnfException, MsoException {
69 StackInfo info = new StackInfo("stackName", HeatStatus.NOTFOUND);
70 MsoVnfAdapterImpl vnfAdapter = new MsoVnfAdapterImpl();
71 vnfAdapter.heat = Mockito.mock(MsoHeatUtils.class);
72 when(vnfAdapter.heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info);
73 String cloudId = "MT";
74 String tenantId = "MSO_Test";
75 String vnfName = "VNF_TEST1";
76 Holder<Boolean> vnfExists = new Holder<>();
77 Holder<String> vnfId = new Holder<>();
78 Holder<VnfStatus> status = new Holder<>();
79 Holder<Map<String, String>> outputs = new Holder<>();
81 vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
83 assertFalse(vnfExists.value);
87 @Test(expected = VnfException.class)
88 // @Ignore // 1802 merge
89 public void testQueryVnfWithException() throws VnfException {
91 String propFile = MsoJavaProperties.class.getClassLoader().getResource("mso.properties").getPath();
92 String cloudConfigJsonFilePath = MsoJavaProperties.class.getClassLoader().getResource("cloud_config.json")
95 MsoPropertiesFactory msoPropFactory = new MsoPropertiesFactory();
96 CloudConfigFactory cloudConfigFact = new CloudConfigFactory();
98 msoPropFactory.initializeMsoProperties("MSO_PROP_VNF_ADAPTER", propFile);
99 cloudConfigFact.initializeCloudConfig(cloudConfigJsonFilePath, 1);
100 } catch (org.openecomp.mso.properties.MsoPropertiesException e) {
101 // System.err.println("!?!?!?!! mso config exception: " + e);
102 // e.printStackTrace();
103 } catch (org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound e) {
104 // System.err.println("!?!?!?!! cloud config exception: " + e);
105 // e.printStackTrace();
108 MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl(msoPropFactory, cloudConfigFact);
110 String cloudId = "MT";
111 String tenantId = "MSO_Test";
112 String vnfName = "VNF_TEST1";
113 Holder<Boolean> vnfExists = new Holder<>();
114 Holder<String> vnfId = new Holder<>();
115 Holder<VnfStatus> status = new Holder<>();
116 Holder<Map<String, String>> outputs = new Holder<>();
118 vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);