aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils
diff options
context:
space:
mode:
authorLukasz Muszkieta <lukasz.muszkieta@nokia.com>2019-01-11 13:02:33 +0100
committerLukasz Muszkieta <lukasz.muszkieta@nokia.com>2019-01-11 18:21:47 +0100
commit9ea21b0de17be2b12ac83274f1d7bb007a6b593e (patch)
tree6c240808ec44ff1e9672b502981c2002b94fcd6b /adapters/mso-adapter-utils
parentde5958dddd97b086ec8b603974f434fd814386ac (diff)
Add junit tests for MsoCloudifyUtils
Change-Id: If12ed6350306cd489aa8b1744a513875b42540c3 Issue-ID: SO-430 Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Diffstat (limited to 'adapters/mso-adapter-utils')
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java (renamed from adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest2.java)95
1 files changed, 94 insertions, 1 deletions
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest2.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java
index c7aecd90be..7c5111bd18 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest2.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java
@@ -23,15 +23,24 @@ package org.onap.so.cloudify.utils;
import static com.shazam.shazamcrest.MatcherAssert.assertThat;
import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import com.fasterxml.jackson.databind.JsonNode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.onap.so.adapters.vdu.CloudInfo;
@@ -50,9 +59,16 @@ import org.onap.so.cloudify.beans.DeploymentInfo;
import org.onap.so.cloudify.beans.DeploymentStatus;
import org.onap.so.cloudify.v3.client.Cloudify;
import org.onap.so.cloudify.v3.model.AzureConfig;
+import org.onap.so.db.catalog.beans.CloudifyManager;
+import org.onap.so.db.catalog.beans.HeatTemplateParam;
+import org.onap.so.openstack.exceptions.MsoAdapterException;
import org.onap.so.openstack.exceptions.MsoException;
-public class MsoCloudifyUtilsTest2 {
+public class MsoCloudifyUtilsTest {
+
+ private static final String CLOUD_SITE_ID = "cloudSiteIdTest";
+ private static final String BLUEPRINT_ID = "bluePrintIdTest";
+ private static final String FILE_NAME = "fileName";
@Test
public void instantiateVduTest() throws MsoException {
@@ -225,4 +241,81 @@ public class MsoCloudifyUtilsTest2 {
assertThat(actual, sameBeanAs(expected));
}
+
+ @Test
+ public void uploadBlueprintSuccessful() throws MsoException {
+ // given
+ MsoCloudifyUtils testedObjectSpy = spy(MsoCloudifyUtils.class);
+ testedObjectSpy.cloudConfig = mock(CloudConfig.class);
+ Map<String, byte[]> blueprints = new HashMap<>();
+
+ mockCloudConfig(testedObjectSpy);
+ doReturn(true).when(testedObjectSpy).uploadBlueprint(any(Cloudify.class), eq(BLUEPRINT_ID),
+ eq(FILE_NAME), eq(blueprints));
+ // when
+ testedObjectSpy.uploadBlueprint(CLOUD_SITE_ID, BLUEPRINT_ID, FILE_NAME, blueprints, true);
+ // then
+ verify(testedObjectSpy).uploadBlueprint(any(Cloudify.class), eq(BLUEPRINT_ID), eq(FILE_NAME),
+ eq(blueprints));
+ }
+
+ @Test
+ public void uploadBlueprint_exceptionThrown_blueprintExists() throws MsoException {
+ // given
+ MsoCloudifyUtils testedObjectSpy = spy(MsoCloudifyUtils.class);
+ testedObjectSpy.cloudConfig = mock(CloudConfig.class);
+ Map<String, byte[]> blueprints = new HashMap<>();
+
+ mockCloudConfig(testedObjectSpy);
+ doReturn(false).when(testedObjectSpy).uploadBlueprint(any(Cloudify.class), eq(BLUEPRINT_ID),
+ eq(FILE_NAME), eq(blueprints));
+ // when
+ try {
+ testedObjectSpy.uploadBlueprint(CLOUD_SITE_ID, BLUEPRINT_ID, FILE_NAME, blueprints, true);
+ // then
+ fail("MsoAdapterException should be thrown");
+ } catch (MsoAdapterException e) {
+ Assert.assertEquals(e.getMessage(), "Blueprint already exists");
+ }
+ verify(testedObjectSpy).uploadBlueprint(any(Cloudify.class), eq(BLUEPRINT_ID), eq(FILE_NAME),
+ eq(blueprints));
+ }
+
+ @Test
+ public void convertInputValue_successful() {
+ MsoCloudifyUtils testedObject = new MsoCloudifyUtils();
+
+ HeatTemplateParam heatTemplateParam = new HeatTemplateParam();
+ heatTemplateParam.setParamType("number");
+ Object result = testedObject.convertInputValue("5", heatTemplateParam);
+ assertTrue(result instanceof Integer);
+
+ heatTemplateParam.setParamType("json");
+ Object result2 = testedObject.convertInputValue("{\"key\": \"value\"}", heatTemplateParam);
+ assertTrue(result2 instanceof JsonNode);
+
+ heatTemplateParam.setParamType("boolean");
+ Object result3 = testedObject.convertInputValue("true", heatTemplateParam);
+ assertTrue(result3 instanceof Boolean);
+ }
+
+ private void mockCloudConfig(MsoCloudifyUtils testedObjectSpy) {
+ CloudifyManager cloudifyManager = createCloudifyManager();
+ when(testedObjectSpy.cloudConfig.getCloudSite(CLOUD_SITE_ID)).thenReturn(Optional.of(createCloudSite()));
+ when(testedObjectSpy.cloudConfig.getCloudifyManager(CLOUD_SITE_ID)).thenReturn(cloudifyManager);
+ }
+
+ private CloudifyManager createCloudifyManager() {
+ CloudifyManager cloudifyManager = new CloudifyManager();
+ cloudifyManager.setCloudifyUrl("cloudUrlTest");
+ cloudifyManager.setPassword("546573746F736973546573746F736973");
+ return cloudifyManager;
+ }
+
+ private CloudSite createCloudSite() {
+ CloudSite cloudSite = new CloudSite();
+ cloudSite.setCloudifyId(CLOUD_SITE_ID);
+ return cloudSite;
+ }
+
}