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.openecomp.mso.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;
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;
49 import com.woorea.openstack.base.client.OpenStackConnectException;
51 @RunWith(MockitoJUnitRunner.class)
52 public class MsoHeatUtilsWithUpdateTest {
54 public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
55 public static CloudConfigFactory cloudConfigFactory = new CloudConfigFactory();
58 CloudConfig cloudConfig;
60 MsoHeatUtilsWithUpdate util = new MsoHeatUtilsWithUpdate("NO_PROP", msoPropertiesFactory, cloudConfigFactory);
62 private CloudSite cloudSite;
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());
79 public void testUpdateStack() {
80 // Heat heat = Mockito.mock (Heat.class);
81 Map<String, Object> stackInputs = new HashMap<>();
83 util.updateStack("none", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1);
84 } catch (MsoException e) {
85 if (e instanceof MsoCloudSiteNotFound) {
89 fail("Exception caught");
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
100 fail("Exception caught");
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
111 fail("Exception caught");
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
122 fail("Exception caught");
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
133 fail("Exception caught");