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