2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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.cloudify.utils;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.Mock;
26 import org.openecomp.mso.cloud.CloudConfigFactory;
27 import org.openecomp.mso.cloud.CloudSite;
28 import org.openecomp.mso.cloudify.beans.DeploymentInfo;
29 import org.openecomp.mso.cloudify.exceptions.MsoCloudifyManagerNotFound;
30 import org.openecomp.mso.cloudify.v3.client.Cloudify;
31 import org.openecomp.mso.cloudify.v3.model.DeploymentOutputs;
32 import org.openecomp.mso.openstack.exceptions.MsoException;
33 import org.openecomp.mso.properties.MsoPropertiesFactory;
34 import org.powermock.api.mockito.PowerMockito;
35 import org.powermock.core.classloader.annotations.PrepareForTest;
36 import org.powermock.modules.junit4.PowerMockRunner;
38 import java.util.HashMap;
40 import static org.mockito.Mockito.mock;
42 import static org.junit.Assert.assertTrue;
43 import static org.mockito.Mockito.doReturn;
45 @RunWith(PowerMockRunner.class)
46 @PrepareForTest({MsoCloudifyUtils.class})
49 public class MsoCloudifyUtilsTest {
53 MsoPropertiesFactory msoPropertiesFactory;
56 CloudConfigFactory cloudConfigFactory;
59 DeploymentInfo deploymentInfo;
65 DeploymentOutputs deploymentOutputs;
70 @Test(expected = NullPointerException.class)
71 public void testCreateandInstallDeployment() throws MsoException {
73 MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
74 Map<String, Object> inputs = new HashMap<>();
75 inputs.put("1", "value");
77 mcu.createAndInstallDeployment("cloudSiteId", "tenantId", "deploymentId", "blueprintId"
78 , inputs, true, 1, true);
80 assert (mcu.createAndInstallDeployment("cloudSiteId", "tenantId", "deploymentId", "blueprintId"
81 , inputs, true, 1, true) != null);
86 @Test(expected = NullPointerException.class)
87 public void testDeploymentOutputs() throws MsoException {
89 MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
90 mcu.queryDeployment("cloudSiteId", "tenantId", "deploymentId");
91 assert (mcu.queryDeployment("cloudSiteId", "tenantId", "deploymentId") != null);
94 @Test(expected = NullPointerException.class)
95 public void testUninstallAndDeleteDeployment() throws MsoException {
97 MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
98 mcu.uninstallAndDeleteDeployment("cloudSiteId", "tenantId", "deploymentId", 1);
99 assert (mcu.uninstallAndDeleteDeployment("cloudSiteId", "tenantId", "deploymentId", 1) != null);
102 @Test(expected = NullPointerException.class)
103 public void testIsBlueprintLoaded() throws MsoException {
105 MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
106 mcu.isBlueprintLoaded("cloudSiteId", "blueprintId");
107 assertTrue(mcu.isBlueprintLoaded("cloudSiteId", "blueprintId"));
110 @Test(expected = MsoCloudifyManagerNotFound.class)
111 public void testCloudifyClient() throws MsoException {
113 MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
114 mcu.getCloudifyClient(cloudSite);
115 assert (mcu.getCloudifyClient(cloudSite) != null);
120 @Test(expected = NullPointerException.class)
121 public void testuploadBlueprint() throws MsoException {
123 MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
125 Map<String, byte[]> blueprintFiles = new HashMap<String, byte[]>();
126 byte[] byteArray = new byte[]{8, 1, 2, 8};
127 blueprintFiles.put("1", byteArray);
129 mcu.uploadBlueprint("cloudSiteId", "blueprintId", "mainFileName", blueprintFiles, false);
133 @Test(expected = NullPointerException.class)
134 public void testqueryDeployment() throws MsoException {
136 MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
137 mcu.queryDeployment(cloudify, "deploymentId");
138 assert (mcu.queryDeployment(cloudify, "deploymentId") != null);