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;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
28 import javax.xml.ws.Holder;
31 import org.junit.Ignore;
32 import org.junit.Test;
33 import org.openecomp.mso.adapters.vnf.MsoVnfAdapter;
34 import org.openecomp.mso.adapters.vnf.MsoVnfAdapterImpl;
35 import org.openecomp.mso.adapters.vnf.exceptions.VnfException;
36 import org.openecomp.mso.openstack.beans.HeatStatus;
37 import org.openecomp.mso.openstack.beans.StackInfo;
38 import org.openecomp.mso.openstack.beans.VnfStatus;
39 import org.openecomp.mso.openstack.exceptions.MsoException;
40 import org.openecomp.mso.openstack.utils.MsoHeatUtils;
42 import org.openecomp.mso.cloud.CloudConfigFactory;
43 import org.openecomp.mso.properties.MsoJavaProperties;
44 import org.openecomp.mso.properties.MsoPropertiesFactory;
46 public class QueryTest {
49 public void testQueryCreatedVnf() throws VnfException {
51 new MockUp<MsoHeatUtils>() {
53 public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException {
54 StackInfo info = new StackInfo("stackName", HeatStatus.CREATED);
59 MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl();
60 String cloudId = "MT";
61 String tenantId = "MSO_Test";
62 String vnfName = "VNF_TEST1";
63 Holder<Boolean> vnfExists = new Holder<>();
64 Holder<String> vnfId = new Holder<>();
65 Holder<VnfStatus> status = new Holder<>();
66 Holder<Map<String, String>> outputs = new Holder<>();
68 vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null,
69 vnfExists, vnfId, status, outputs);
71 assertTrue(vnfExists.value);
76 public void testQueryNotFoundVnf() throws VnfException {
78 new MockUp<MsoHeatUtils>() {
80 public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException {
81 StackInfo info = new StackInfo("stackName", HeatStatus.NOTFOUND);
86 MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl();
87 String cloudId = "MT";
88 String tenantId = "MSO_Test";
89 String vnfName = "VNF_TEST1";
90 Holder<Boolean> vnfExists = new Holder<>();
91 Holder<String> vnfId = new Holder<>();
92 Holder<VnfStatus> status = new Holder<>();
93 Holder<Map<String, String>> outputs = new Holder<>();
95 vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null,
96 vnfExists, vnfId, status, outputs);
98 assertFalse(vnfExists.value);
102 @Test(expected = VnfException.class)
103 // @Ignore // 1802 merge
104 public void testQueryVnfWithException() throws VnfException {
106 String propFile = MsoJavaProperties.class.getClassLoader().getResource("mso.properties").getPath();
107 String cloudConfigJsonFilePath = MsoJavaProperties.class.getClassLoader().getResource("cloud_config.json").getPath();
109 MsoPropertiesFactory msoPropFactory = new MsoPropertiesFactory();
110 CloudConfigFactory cloudConfigFact = new CloudConfigFactory();
112 msoPropFactory.initializeMsoProperties("MSO_PROP_VNF_ADAPTER", propFile);
113 cloudConfigFact.initializeCloudConfig(cloudConfigJsonFilePath, 1);
114 } catch (org.openecomp.mso.properties.MsoPropertiesException e) {
115 // System.err.println("!?!?!?!! mso config exception: " + e);
116 // e.printStackTrace();
117 } catch (org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound e) {
118 // System.err.println("!?!?!?!! cloud config exception: " + e);
119 // e.printStackTrace();
122 MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl(msoPropFactory, cloudConfigFact);
124 String cloudId = "MT";
125 String tenantId = "MSO_Test";
126 String vnfName = "VNF_TEST1";
127 Holder<Boolean> vnfExists = new Holder<>();
128 Holder<String> vnfId = new Holder<>();
129 Holder<VnfStatus> status = new Holder<>();
130 Holder<Map<String, String>> outputs = new Holder<>();
132 vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null,
133 vnfExists, vnfId, status, outputs);