10/31: merge casablanca to master
[so.git] / adapters / mso-adapter-utils / src / test / java / org / onap / so / 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.onap.so.adapter_utils.tests;
22
23 import java.util.HashMap;
24
25 import org.junit.Ignore;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.onap.so.TestApplication;
29 import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
30 import org.onap.so.openstack.exceptions.MsoException;
31 import org.onap.so.openstack.exceptions.MsoIOException;
32 import org.onap.so.openstack.exceptions.MsoStackAlreadyExists;
33 import org.onap.so.openstack.exceptions.MsoTenantNotFound;
34 import org.onap.so.openstack.utils.MsoCommonUtils;
35 import org.onap.so.openstack.utils.MsoHeatUtils;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.boot.test.context.SpringBootTest;
38 import org.springframework.test.context.ActiveProfiles;
39 import org.springframework.test.context.junit4.SpringRunner;
40
41 import com.woorea.openstack.heat.model.CreateStackParam;
42
43 /**
44  * This class implements test methods of the MsoHeatUtils
45  *
46  *
47  */
48 @RunWith(SpringRunner.class)
49 @SpringBootTest(classes = TestApplication.class)
50 @ActiveProfiles("test")
51 @Ignore
52 public class MsoHeatUtilsTest extends MsoCommonUtils {
53         @Autowired
54         private  MsoHeatUtils msoHeatUtils;
55
56         @Test
57         public final void testCreateStackBadCloudConfig()
58                         throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound {
59                 try {
60                         msoHeatUtils.createStack("DOESNOTEXIST", "test", "stackName", "test", new HashMap<String, Object>(),
61                                         Boolean.TRUE, 10);
62                 } catch (MsoCloudSiteNotFound e) {
63
64                 } catch (java.lang.NullPointerException npe) {
65
66                 }
67
68         }
69
70         @Test
71         public final void testCreateStackFailedConnectionHeatClient()
72                         throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound {
73                 try {
74                         msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE,
75                                         10);
76                 } catch (MsoIOException e) {
77
78                 }
79
80         }
81
82         @Test
83         public final void testCreateStackFailedConnection()
84                         throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound {
85                 try {
86                         msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE,
87                                         10);
88                 } catch (MsoIOException e) {
89
90                 }
91
92         }
93
94         @Test
95         public final void createStackSuccessWithEnvironment() throws MsoException {
96                 try {
97                         msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE, 10,
98                                         "environment");
99                 } catch (MsoIOException e) {
100
101                 }
102
103         }
104
105         @Test
106         public final void createStackSuccessWithFiles() throws MsoException {
107                 try {
108                         msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE, 10,
109                                         "environment", new HashMap<String, Object>());
110                 } catch (MsoIOException e) {
111
112                 }
113
114         }
115
116         @Test
117         public final void createStackSuccessWithHeatFiles() throws MsoException {
118                 try {
119                         msoHeatUtils.createStack("MT", "test", "stackName", "test", new HashMap<String, Object>(), Boolean.TRUE, 10,
120                                         "environment", new HashMap<String, Object>(), new HashMap<String, Object>());
121                 } catch (MsoIOException e) {
122
123                 }
124         }
125
126         @Test
127         public final void requestToStringBuilderTest() {
128                 CreateStackParam param = new CreateStackParam();
129                 param.setDisableRollback(false);
130                 param.setEnvironment("environment");
131                 param.setFiles(new HashMap<String, Object>());
132                 param.setParameters(new HashMap<>());
133                 param.setStackName("stackName");
134                 param.setTemplate("template");
135                 param.setTemplateUrl("http://templateUrl");
136                 param.setTimeoutMinutes(1);
137
138                 msoHeatUtils.requestToStringBuilder(param);
139         }
140 }