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