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