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.util.HashMap;
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;
47 import com.woorea.openstack.base.client.OpenStackConnectException;
49 @RunWith(MockitoJUnitRunner.class)
50 public class MsoHeatUtilsWithUpdateTest {
54 private CloudConfig cloudConfig;
56 private MsoHeatUtilsWithUpdate util=new MsoHeatUtilsWithUpdate();
58 private CloudSite cloudSite;
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());
75 public void testUpdateStack () {
76 // Heat heat = Mockito.mock (Heat.class);
77 Map <String, Object> stackInputs = new HashMap <> ();
79 util.updateStack ("none", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1);
80 } catch (MsoException e) {
81 if (e instanceof MsoCloudSiteNotFound) {
85 fail ("Exception caught");
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
96 fail ("Exception caught");
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
106 e.printStackTrace ();
107 fail ("Exception caught");
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
117 e.printStackTrace ();
118 fail ("Exception caught");
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
128 e.printStackTrace ();
129 fail ("Exception caught");