package correction for vnfadater
[so.git] / adapters / mso-vnf-adapter / src / test / java / org / openecomp / mso / adapters / vnf / QueryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.mso.adapters.vnf;
22
23
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26
27 import java.util.Map;
28 import javax.xml.ws.Holder;
29 import mockit.Mock;
30 import mockit.MockUp;
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;
41
42 import org.openecomp.mso.cloud.CloudConfigFactory;
43 import org.openecomp.mso.properties.MsoJavaProperties;
44 import org.openecomp.mso.properties.MsoPropertiesFactory;
45
46 public class QueryTest {
47
48     @Test
49     public void testQueryCreatedVnf() throws VnfException {
50         {
51             new MockUp<MsoHeatUtils>() {
52                 @Mock
53                 public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException {
54                     StackInfo info = new StackInfo("stackName", HeatStatus.CREATED);
55                     return info;
56                 }
57             };
58
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<>();
67
68             vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null,
69                     vnfExists, vnfId, status, outputs);
70
71             assertTrue(vnfExists.value);
72         }
73     }
74
75     @Test
76     public void testQueryNotFoundVnf() throws VnfException {
77         {
78             new MockUp<MsoHeatUtils>() {
79                 @Mock
80                 public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException {
81                     StackInfo info = new StackInfo("stackName", HeatStatus.NOTFOUND);
82                     return info;
83                 }
84             };
85
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<>();
94
95             vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null,
96                     vnfExists, vnfId, status, outputs);
97
98             assertFalse(vnfExists.value);
99         }
100     }
101
102     @Test(expected = VnfException.class)
103     //    @Ignore // 1802 merge
104     public void testQueryVnfWithException() throws VnfException {
105         {
106             String propFile = MsoJavaProperties.class.getClassLoader().getResource("mso.properties").getPath();
107             String cloudConfigJsonFilePath = MsoJavaProperties.class.getClassLoader().getResource("cloud_config.json").getPath();
108
109             MsoPropertiesFactory msoPropFactory = new MsoPropertiesFactory();
110             CloudConfigFactory cloudConfigFact = new CloudConfigFactory();
111             try {
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();
120             }
121
122             MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl(msoPropFactory, cloudConfigFact);
123
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<>();
131
132             vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null,
133                     vnfExists, vnfId, status, outputs);
134         }
135     }
136 }