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