Initial commit of VDU plugin implementation
[so.git] / adapters / mso-adapter-utils / src / test / java / org / openecomp / mso / cloudify / utils / MsoCloudifyUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.mso.cloudify.utils;
22
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;
37
38 import java.util.HashMap;
39 import java.util.Map;
40 import static org.mockito.Mockito.mock;
41
42 import static org.junit.Assert.assertTrue;
43 import static org.mockito.Mockito.doReturn;
44
45 @RunWith(PowerMockRunner.class)
46 @PrepareForTest({MsoCloudifyUtils.class})
47
48
49 public class MsoCloudifyUtilsTest {
50
51
52     @Mock
53     MsoPropertiesFactory msoPropertiesFactory;
54
55     @Mock
56     CloudConfigFactory cloudConfigFactory;
57
58     @Mock
59     DeploymentInfo deploymentInfo;
60
61     @Mock
62     Cloudify cloudify;
63
64     @Mock
65     DeploymentOutputs deploymentOutputs;
66
67     @Mock
68     CloudSite cloudSite;
69
70     @Test(expected = NullPointerException.class)
71     public void testCreateandInstallDeployment() throws MsoException {
72
73         MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
74         Map<String, Object> inputs = new HashMap<>();
75         inputs.put("1", "value");
76
77         mcu.createAndInstallDeployment("cloudSiteId", "tenantId", "deploymentId", "blueprintId"
78                 , inputs, true, 1, true);
79
80         assert (mcu.createAndInstallDeployment("cloudSiteId", "tenantId", "deploymentId", "blueprintId"
81                 , inputs, true, 1, true) != null);
82
83
84     }
85
86     @Test(expected = NullPointerException.class)
87     public void testDeploymentOutputs() throws MsoException {
88
89         MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
90         mcu.queryDeployment("cloudSiteId", "tenantId", "deploymentId");
91         assert (mcu.queryDeployment("cloudSiteId", "tenantId", "deploymentId") != null);
92     }
93
94     @Test(expected = NullPointerException.class)
95     public void testUninstallAndDeleteDeployment() throws MsoException {
96
97         MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
98         mcu.uninstallAndDeleteDeployment("cloudSiteId", "tenantId", "deploymentId", 1);
99         assert (mcu.uninstallAndDeleteDeployment("cloudSiteId", "tenantId", "deploymentId", 1) != null);
100     }
101
102     @Test(expected = NullPointerException.class)
103     public void testIsBlueprintLoaded() throws MsoException {
104
105         MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
106         mcu.isBlueprintLoaded("cloudSiteId", "blueprintId");
107         assertTrue(mcu.isBlueprintLoaded("cloudSiteId", "blueprintId"));
108     }
109
110     @Test(expected = MsoCloudifyManagerNotFound.class)
111     public void testCloudifyClient() throws MsoException {
112
113         MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
114         mcu.getCloudifyClient(cloudSite);
115         assert (mcu.getCloudifyClient(cloudSite) != null);
116
117     }
118
119
120     @Test(expected = NullPointerException.class)
121     public void testuploadBlueprint() throws MsoException {
122
123             MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
124
125             Map<String, byte[]> blueprintFiles = new HashMap<String, byte[]>();
126             byte[] byteArray = new byte[]{8, 1, 2, 8};
127             blueprintFiles.put("1", byteArray);
128
129             mcu.uploadBlueprint("cloudSiteId", "blueprintId", "mainFileName", blueprintFiles, false);
130
131     }
132
133     @Test(expected = NullPointerException.class)
134     public void testqueryDeployment() throws MsoException {
135
136         MsoCloudifyUtils mcu = new MsoCloudifyUtils("msoPropID", msoPropertiesFactory, cloudConfigFactory);
137         mcu.queryDeployment(cloudify, "deploymentId");
138         assert (mcu.queryDeployment(cloudify, "deploymentId") != null);
139
140
141     }
142
143 }