Merge "Reorder modifiers"
[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 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.Mockito.when;
26
27 import java.util.Map;
28
29 import javax.xml.ws.Holder;
30
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;
42
43 public class QueryTest {
44
45         @Test
46         public void testQueryCreatedVnf() throws VnfException, MsoException {
47                 {
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<>();
59
60                         vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
61
62                         assertTrue(vnfExists.value);
63                 }
64         }
65
66         @Test
67         public void testQueryNotFoundVnf() throws VnfException, MsoException {
68                 {
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<>();
80
81                         vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
82
83                         assertFalse(vnfExists.value);
84                 }
85         }
86
87         @Test(expected = VnfException.class)
88         // @Ignore // 1802 merge
89         public void testQueryVnfWithException() throws VnfException {
90                 {
91                         String propFile = MsoJavaProperties.class.getClassLoader().getResource("mso.properties").getPath();
92                         String cloudConfigJsonFilePath = MsoJavaProperties.class.getClassLoader().getResource("cloud_config.json")
93                                         .getPath();
94
95                         MsoPropertiesFactory msoPropFactory = new MsoPropertiesFactory();
96                         CloudConfigFactory cloudConfigFact = new CloudConfigFactory();
97                         try {
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();
106                         }
107
108                         MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl(msoPropFactory, cloudConfigFact);
109
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<>();
117
118                         vnfAdapter.queryVnf(cloudId, tenantId, vnfName, null, vnfExists, vnfId, status, outputs);
119                 }
120         }
121 }