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