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