Change the header to SO
[so.git] / adapters / mso-adapter-utils / src / test / java / org / openecomp / mso / adapter_utils / tests / MsoHeatUtilsWithUpdateTest.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 static org.junit.Assert.fail;
24 import static org.mockito.Mockito.when;
25
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import org.junit.Before;
30 import org.junit.Ignore;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mock;
35 import org.mockito.runners.MockitoJUnitRunner;
36 import org.openecomp.mso.cloud.CloudConfig;
37 import org.openecomp.mso.cloud.CloudConfigFactory;
38 import org.openecomp.mso.cloud.CloudIdentity;
39 import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;
40 import org.openecomp.mso.cloud.CloudSite;
41 import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound;
42 import org.openecomp.mso.openstack.exceptions.MsoException;
43 import org.openecomp.mso.openstack.exceptions.MsoIOException;
44 import org.openecomp.mso.openstack.utils.MsoHeatUtilsWithUpdate;
45 import org.openecomp.mso.properties.MsoPropertiesFactory;
46
47 import com.woorea.openstack.base.client.OpenStackConnectException;
48
49 @RunWith(MockitoJUnitRunner.class)
50 public class MsoHeatUtilsWithUpdateTest {
51
52         public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
53         public static CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
54         
55     @Mock
56     CloudConfig cloudConfig;
57     @InjectMocks
58     MsoHeatUtilsWithUpdate util=new MsoHeatUtilsWithUpdate("NO_PROP",msoPropertiesFactory,cloudConfigFactory);
59
60     private CloudSite cloudSite;
61
62     @Before
63     public void init () {
64         cloudSite = new CloudSite ();
65         cloudSite.setId ("cloud");
66         CloudIdentity cloudIdentity = new CloudIdentity ();
67         cloudIdentity.setIdentityServerType(IdentityServerType.KEYSTONE);
68         cloudIdentity.setKeystoneUrl ("toto");
69         cloudIdentity.setMsoPass (CloudIdentity.encryptPassword ("mockId"));
70         cloudSite.setIdentityService (cloudIdentity);
71         when (cloudConfig.getCloudSite ("cloud")).thenReturn (cloudSite);
72         when (cloudConfig.getCloudSite ("none")).thenReturn (null);
73     }
74
75     @Test
76     @Ignore
77     public void testUpdateStack () {
78         // Heat heat = Mockito.mock (Heat.class);
79         Map <String, Object> stackInputs = new HashMap <> ();
80         try {
81             util.updateStack ("none", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1);
82         } catch (MsoException e) {
83             if (e instanceof MsoCloudSiteNotFound) {
84                 // Ok
85             } else {
86                 e.printStackTrace ();
87                 fail ("Exception caught");
88             }
89         }
90         try {
91             util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1);
92         } catch (MsoException e) {
93             if (e instanceof MsoIOException && e.getCause () != null
94                 && e.getCause () instanceof OpenStackConnectException) {
95                 // Ok, we were able to go up to the connection to OpenStack
96             } else {
97                 e.printStackTrace ();
98                 fail ("Exception caught");
99             }
100         }
101         try {
102             util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment");
103         } catch (MsoException e) {
104             if (e instanceof MsoIOException && e.getCause () != null
105                 && e.getCause () instanceof OpenStackConnectException) {
106                 // Ok, we were able to go up to the connection to OpenStack
107             } else {
108                 e.printStackTrace ();
109                 fail ("Exception caught");
110             }
111         }
112         try {
113             util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment", null);
114         } catch (MsoException e) {
115             if (e instanceof MsoIOException && e.getCause () != null
116                 && e.getCause () instanceof OpenStackConnectException) {
117                 // Ok, we were able to go up to the connection to OpenStack
118             } else {
119                 e.printStackTrace ();
120                 fail ("Exception caught");
121             }
122         }
123         try {
124             util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment", null, null);
125         } catch (MsoException e) {
126             if (e instanceof MsoIOException && e.getCause () != null
127                 && e.getCause () instanceof OpenStackConnectException) {
128                 // Ok, we were able to go up to the connection to OpenStack
129             } else {
130                 e.printStackTrace ();
131                 fail ("Exception caught");
132             }
133         }
134     }
135 }