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