diff options
author | Steve Smokowski <ss835w@att.com> | 2019-01-12 13:16:57 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-01-12 13:16:57 +0000 |
commit | 97c66bbc30ac2f3224fc7491f1ef72ac74172ec9 (patch) | |
tree | 1e72e0a50e5cdd1bc91e04fb2ea6dcbd3a286673 /adapters/mso-adapter-utils/src | |
parent | 4919e6c13e741574d86c2e1993b302d80ec2128d (diff) | |
parent | 9ea21b0de17be2b12ac83274f1d7bb007a6b593e (diff) |
Merge "Add junit tests for MsoCloudifyUtils"
Diffstat (limited to 'adapters/mso-adapter-utils/src')
-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; + } + } |