2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.openstack.utils;
\r
23 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
\r
24 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
\r
25 import static org.mockito.Mockito.doReturn;
\r
26 import static org.mockito.Mockito.when;
\r
28 import java.util.ArrayList;
\r
29 import java.util.HashMap;
\r
30 import java.util.List;
\r
31 import java.util.Map;
\r
32 import java.util.Optional;
\r
34 import org.junit.Test;
\r
35 import org.mockito.Mockito;
\r
36 import org.openecomp.mso.adapters.vdu.CloudInfo;
\r
37 import org.openecomp.mso.adapters.vdu.PluginAction;
\r
38 import org.openecomp.mso.adapters.vdu.VduArtifact;
\r
39 import org.openecomp.mso.adapters.vdu.VduArtifact.ArtifactType;
\r
40 import org.openecomp.mso.adapters.vdu.VduInstance;
\r
41 import org.openecomp.mso.adapters.vdu.VduModelInfo;
\r
42 import org.openecomp.mso.adapters.vdu.VduStateType;
\r
43 import org.openecomp.mso.adapters.vdu.VduStatus;
\r
44 import org.openecomp.mso.cloud.CloudConfig;
\r
45 import org.openecomp.mso.cloud.CloudConfigFactory;
\r
46 import org.openecomp.mso.cloud.CloudSite;
\r
47 import org.openecomp.mso.cloudify.beans.DeploymentInfo;
\r
48 import org.openecomp.mso.cloudify.beans.DeploymentStatus;
\r
49 import org.openecomp.mso.cloudify.utils.MsoCloudifyUtils;
\r
50 import org.openecomp.mso.openstack.beans.HeatStatus;
\r
51 import org.openecomp.mso.openstack.beans.StackInfo;
\r
52 import org.openecomp.mso.openstack.exceptions.MsoException;
\r
54 import com.fasterxml.jackson.core.JsonProcessingException;
\r
56 public class MsoHeatUtilsTest2 {
\r
59 public void instantiateVduTest() throws MsoException, JsonProcessingException {
\r
60 VduInstance expected = new VduInstance();
\r
61 expected.setVduInstanceId("canonicalName");
\r
62 expected.setVduInstanceName("name");
\r
63 VduStatus status = new VduStatus();
\r
64 status.setState(VduStateType.INSTANTIATED);
\r
65 status.setLastAction((new PluginAction("create", "complete", "")));
\r
66 expected.setStatus(status);
\r
68 MsoHeatUtils heatUtils = Mockito.spy(MsoHeatUtils.class);
\r
69 CloudSite site = new CloudSite();
\r
70 Optional<CloudSite> opSite = Optional.ofNullable(site);
\r
71 CloudConfig config = Mockito.mock(CloudConfig.class);
\r
72 CloudConfigFactory cloudConfigFactory = Mockito.mock(CloudConfigFactory.class);
\r
73 when(cloudConfigFactory.getCloudConfig()).thenReturn(config);
\r
74 when(heatUtils.getCloudConfigFactory()).thenReturn(cloudConfigFactory);
\r
75 CloudInfo cloudInfo = new CloudInfo();
\r
76 cloudInfo.setCloudSiteId("cloudSiteId");
\r
77 cloudInfo.setTenantId("tenantId");
\r
78 VduModelInfo vduModel = new VduModelInfo();
\r
79 vduModel.setModelCustomizationUUID("blueprintId");
\r
80 vduModel.setTimeoutMinutes(1);
\r
81 VduArtifact artifact = new VduArtifact();
\r
82 artifact.setName("name");
\r
83 artifact.setType(ArtifactType.MAIN_TEMPLATE);
\r
84 byte[] content = new byte[1];
\r
85 artifact.setContent(content);
\r
86 List<VduArtifact> artifacts = new ArrayList<>();
\r
87 artifacts.add(artifact);
\r
88 vduModel.setArtifacts(artifacts);
\r
89 Map<String, byte[]> blueprintFiles = new HashMap<>();
\r
90 blueprintFiles.put(artifact.getName(), artifact.getContent());
\r
91 String instanceName = "instanceName";
\r
92 Map<String, Object> inputs = new HashMap<>();
\r
93 boolean rollbackOnFailure = true;
\r
94 String heatTemplate = new String(artifact.getContent());
\r
95 when(config.getCloudSite(cloudInfo.getCloudSiteId())).thenReturn(opSite);
\r
96 Map<String, Object> nestedTemplates = new HashMap<String, Object>();
\r
97 Map<String, Object> files = new HashMap<String, Object>();
\r
99 StackInfo stackInfo = new StackInfo();
\r
100 stackInfo.setCanonicalName("canonicalName");
\r
101 stackInfo.setName("name");
\r
102 stackInfo.setStatus(HeatStatus.CREATED);
\r
104 doReturn(stackInfo).when(heatUtils).createStack(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(),
\r
105 instanceName, heatTemplate, inputs, true, vduModel.getTimeoutMinutes(), null, nestedTemplates, files,
\r
106 rollbackOnFailure);
\r
108 VduInstance actual = heatUtils.instantiateVdu(cloudInfo, instanceName, inputs, vduModel, rollbackOnFailure);
\r
110 assertThat(actual, sameBeanAs(expected));
\r
114 public void queryVduTest() throws MsoException, JsonProcessingException {
\r
115 VduInstance expected = new VduInstance();
\r
116 expected.setVduInstanceId("canonicalName");
\r
117 expected.setVduInstanceName("name");
\r
118 VduStatus status = new VduStatus();
\r
119 status.setState(VduStateType.INSTANTIATED);
\r
120 status.setLastAction((new PluginAction("create", "complete", "")));
\r
121 expected.setStatus(status);
\r
123 CloudInfo cloudInfo = new CloudInfo();
\r
124 cloudInfo.setCloudSiteId("cloudSiteId");
\r
125 cloudInfo.setTenantId("tenantId");
\r
126 String instanceId = "instanceId";
\r
128 StackInfo stackInfo = new StackInfo();
\r
129 stackInfo.setCanonicalName("canonicalName");
\r
130 stackInfo.setName("name");
\r
131 stackInfo.setStatus(HeatStatus.CREATED);
\r
133 MsoHeatUtils heatUtils = Mockito.spy(MsoHeatUtils.class);
\r
135 doReturn(stackInfo).when(heatUtils).queryStack(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(), instanceId);
\r
137 VduInstance actual = heatUtils.queryVdu(cloudInfo, instanceId);
\r
139 assertThat(actual, sameBeanAs(expected));
\r
143 public void deleteVduTest() throws MsoException {
\r
144 VduInstance expected = new VduInstance();
\r
145 expected.setVduInstanceId("canonicalName");
\r
146 expected.setVduInstanceName("name");
\r
147 VduStatus status = new VduStatus();
\r
148 status.setState(VduStateType.DELETED);
\r
149 expected.setStatus(status);
\r
151 CloudInfo cloudInfo = new CloudInfo();
\r
152 cloudInfo.setCloudSiteId("cloudSiteId");
\r
153 cloudInfo.setTenantId("tenantId");
\r
154 String instanceId = "instanceId";
\r
156 StackInfo stackInfo = new StackInfo();
\r
157 stackInfo.setCanonicalName("canonicalName");
\r
158 stackInfo.setName("name");
\r
159 stackInfo.setStatus(HeatStatus.NOTFOUND);
\r
161 int timeoutInMinutes = 1;
\r
163 MsoHeatUtils heatUtils = Mockito.spy(MsoHeatUtils.class);
\r
165 doReturn(stackInfo).when(heatUtils).deleteStack( cloudInfo.getTenantId(), cloudInfo.getCloudSiteId(), instanceId, true);
\r
167 VduInstance actual = heatUtils.deleteVdu(cloudInfo, instanceId, timeoutInMinutes);
\r
169 assertThat(actual, sameBeanAs(expected));
\r