Adding UT for MsoHeatUtils
[so.git] / adapters / mso-adapter-utils / src / test / java / org / openecomp / mso / adapter_utils / tests / MsoHeatUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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.adapter_utils.tests;
22
23 import java.util.HashMap;
24
25 import org.junit.BeforeClass;
26 import org.junit.Test;
27 import org.openecomp.mso.cloud.CloudConfigFactory;
28 import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound;
29 import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound;
30 import org.openecomp.mso.openstack.exceptions.MsoException;
31 import org.openecomp.mso.openstack.exceptions.MsoIOException;
32 import org.openecomp.mso.openstack.exceptions.MsoStackAlreadyExists;
33 import org.openecomp.mso.openstack.exceptions.MsoTenantNotFound;
34 import org.openecomp.mso.openstack.utils.MsoCommonUtils;
35 import org.openecomp.mso.openstack.utils.MsoHeatUtils;
36 import org.openecomp.mso.properties.MsoPropertiesFactory;
37
38 import com.woorea.openstack.heat.model.CreateStackParam;
39
40 /**
41  * This class implements test methods of the MsoHeatUtils
42  *
43  *
44  */
45 public class MsoHeatUtilsTest extends MsoCommonUtils {
46         public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
47         public static CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
48         public static MsoHeatUtils msoHeatUtils;
49
50         @BeforeClass
51         public static final void loadClasses() throws MsoCloudIdentityNotFound {
52                 ClassLoader classLoader = CloudConfigTest.class.getClassLoader();
53                 String config = classLoader.getResource("cloud_config.json").toString().substring(5);
54                 cloudConfigFactory.initializeCloudConfig(config, 1);
55                 msoHeatUtils = new MsoHeatUtils("NO_PROP", msoPropertiesFactory, cloudConfigFactory);
56         }
57
58         @Test
59         public final void testCreateStackBadCloudConfig()
60                         throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound {
61                 try {
62                         msoHeatUtils.createStack("DOESNOTEXIST", "test", "stackName", "test", new HashMap<String, Object>(),
63                                         Boolean.TRUE, 10);
64                 } catch (MsoCloudSiteNotFound e) {
65
66                 } catch (java.lang.NullPointerException npe) {
67
68                 }
69
70         }
71
72         @Test
73         public final void testCreateStackFailedConnectionHeatClient()
74                         throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound {
75                 try {
76                         msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE,
77                                         10);
78                 } catch (MsoIOException e) {
79
80                 }
81
82         }
83
84         @Test
85         public final void testCreateStackFailedConnection()
86                         throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound {
87                 try {
88                         msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE,
89                                         10);
90                 } catch (MsoIOException e) {
91
92                 }
93
94         }
95
96         @Test
97         public final void createStackSuccessWithEnvironment() throws MsoException {
98                 try {
99                         msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE, 10,
100                                         "environment");
101                 } catch (MsoIOException e) {
102
103                 }
104
105         }
106
107         @Test
108         public final void createStackSuccessWithFiles() throws MsoException {
109                 try {
110                         msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE, 10,
111                                         "environment", new HashMap<String, Object>());
112                 } catch (MsoIOException e) {
113
114                 }
115
116         }
117
118         @Test
119         public final void createStackSuccessWithHeatFiles() throws MsoException {
120                 try {
121                         msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE, 10,
122                                         "environment", new HashMap<String, Object>(), new HashMap<String, Object>());
123                 } catch (MsoIOException e) {
124
125                 }
126         }
127
128         @Test
129         public final void requestToStringBuilderTest() {
130                 CreateStackParam param = new CreateStackParam();
131                 param.setDisableRollback(false);
132                 param.setEnvironment("environment");
133                 param.setFiles(new HashMap<String, Object>());
134                 param.setParameters(new HashMap<>());
135                 param.setStackName("stackName");
136                 param.setTemplate("template");
137                 param.setTemplateUrl("http://templateUrl");
138                 param.setTimeoutMinutes(1);
139
140                 msoHeatUtils.requestToStringBuilder(param);
141         }
142
143         @Test
144         public final void heatCacheResetTest() {
145                 msoHeatUtils.heatCacheReset();
146         }
147
148         @Test
149         public final void expireHeatClientTest() {
150                 msoHeatUtils.expireHeatClient("tenantId", "cloudId");
151         }
152
153         @Test
154         public final void heatCacheCleanupTest() {
155                 msoHeatUtils.heatCacheCleanup();
156         }
157 }