2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapter_utils.tests;
23 import static org.junit.Assert.fail;
24 import static org.mockito.Mockito.when;
26 import java.security.GeneralSecurityException;
27 import java.util.HashMap;
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;
48 import com.woorea.openstack.base.client.OpenStackConnectException;
50 @RunWith(MockitoJUnitRunner.class)
51 public class MsoHeatUtilsWithUpdateTest {
55 private CloudConfig cloudConfig;
57 private MsoHeatUtilsWithUpdate util=new MsoHeatUtilsWithUpdate();
59 private CloudSite cloudSite;
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());
76 public void testUpdateStack () {
77 // Heat heat = Mockito.mock (Heat.class);
78 Map <String, Object> stackInputs = new HashMap <> ();
80 util.updateStack ("none", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1);
81 } catch (MsoException e) {
82 if (e instanceof MsoCloudSiteNotFound) {
86 fail ("Exception caught");
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
97 fail ("Exception caught");
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
107 e.printStackTrace ();
108 fail ("Exception caught");
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
118 e.printStackTrace ();
119 fail ("Exception caught");
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
129 e.printStackTrace ();
130 fail ("Exception caught");