From 0cdb973be30e05fe7c42bb303ddc2187691984f3 Mon Sep 17 00:00:00 2001 From: "Kalkere Ramesh, Sharan (sk720x)" Date: Fri, 23 Mar 2018 16:11:44 -0400 Subject: Initial commit of VDU plugin implementation This was documented in the API we committed to at M3. Change-Id: Id0c886d956dc46dba71157cfa35d88844028e7fd Issue-ID: SO-511 Signed-off-by: Kalkere Ramesh, Sharan (sk720x) --- .../org/openecomp/mso/adapters/vdu/BeansTest.java | 56 +++++ .../mso/cloudify/utils/MsoCloudifyUtilsTest.java | 2 +- .../mso/cloudify/utils/MsoCloudifyUtilsTest2.java | 254 +++++++++++++++++++++ .../mso/openstack/utils/MsoHeatUtilsTest2.java | 169 ++++++++++++++ 4 files changed, 480 insertions(+), 1 deletion(-) create mode 100644 adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapters/vdu/BeansTest.java create mode 100644 adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest2.java create mode 100644 adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java (limited to 'adapters/mso-adapter-utils/src/test') diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapters/vdu/BeansTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapters/vdu/BeansTest.java new file mode 100644 index 0000000000..1452c1569c --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapters/vdu/BeansTest.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.adapters.vdu; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class BeansTest { + + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + @Test + public void pojoStructure() { + test("org.openecomp.mso.adapters.vdu"); + } + + private void test(String pojoPackage) { + Validator validator = ValidatorBuilder.create() + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses); + } + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java index 214d6f2500..821522fedc 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest.java @@ -140,4 +140,4 @@ public class MsoCloudifyUtilsTest { } -} \ No newline at end of file +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest2.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest2.java new file mode 100644 index 0000000000..05608b4d99 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtilsTest2.java @@ -0,0 +1,254 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.cloudify.utils; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.mso.adapters.vdu.CloudInfo; +import org.openecomp.mso.adapters.vdu.PluginAction; +import org.openecomp.mso.adapters.vdu.VduArtifact; +import org.openecomp.mso.adapters.vdu.VduArtifact.ArtifactType; +import org.openecomp.mso.adapters.vdu.VduInstance; +import org.openecomp.mso.adapters.vdu.VduModelInfo; +import org.openecomp.mso.adapters.vdu.VduStateType; +import org.openecomp.mso.adapters.vdu.VduStatus; +import org.openecomp.mso.cloud.CloudConfig; +import org.openecomp.mso.cloud.CloudIdentity; +import org.openecomp.mso.cloud.CloudSite; +import org.openecomp.mso.cloudify.beans.DeploymentInfo; +import org.openecomp.mso.cloudify.beans.DeploymentStatus; +import org.openecomp.mso.cloudify.v3.client.Cloudify; +import org.openecomp.mso.cloudify.v3.model.AzureConfig; +import org.openecomp.mso.cloudify.v3.model.OpenstackConfig; +import org.openecomp.mso.openstack.exceptions.MsoException; + +public class MsoCloudifyUtilsTest2 { + + @Test + public void instantiateVduTest() throws MsoException { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("id"); + expected.setVduInstanceName("id"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.INSTANTIATED); + status.setLastAction(new PluginAction(null, null, null)); + expected.setStatus(status); + + MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class); + CloudSite site = new CloudSite(); + Optional opSite = Optional.ofNullable(site); + CloudConfig config = Mockito.mock(CloudConfig.class); + cloudify.cloudConfig = config; + Cloudify cloudifyClient = new Cloudify("cloudSite"); + CloudInfo cloudInfo = new CloudInfo(); + cloudInfo.setCloudSiteId("cloudSiteId"); + cloudInfo.setTenantId("tenantId"); + VduModelInfo vduModel = new VduModelInfo(); + vduModel.setModelCustomizationUUID("blueprintId"); + vduModel.setTimeoutMinutes(1); + VduArtifact artifact = new VduArtifact(); + artifact.setName("name"); + artifact.setType(ArtifactType.MAIN_TEMPLATE); + byte[] content = new byte[1]; + artifact.setContent(content); + List artifacts = new ArrayList<>(); + artifacts.add(artifact); + vduModel.setArtifacts(artifacts); + DeploymentInfo deployment = new DeploymentInfo(); + deployment.setId("id"); + deployment.setStatus(DeploymentStatus.INSTALLED); + Map blueprintFiles = new HashMap<>(); + blueprintFiles.put(artifact.getName(), artifact.getContent()); + String instanceName = "instanceName"; + Map inputs = new HashMap<>(); + boolean rollbackOnFailure = true; + + when(config.getCloudSite(cloudInfo.getCloudSiteId())).thenReturn(opSite); + doReturn(false).when(cloudify).isBlueprintLoaded(cloudInfo.getCloudSiteId(), + vduModel.getModelCustomizationUUID()); + doReturn(cloudifyClient).when(cloudify).getCloudifyClient(site); + doReturn(true).when(cloudify).uploadBlueprint(cloudifyClient, vduModel.getModelCustomizationUUID(), + artifact.getName(), blueprintFiles); + doReturn(deployment).when(cloudify).createAndInstallDeployment(cloudInfo.getCloudSiteId(), + cloudInfo.getTenantId(), instanceName, vduModel.getModelCustomizationUUID(), inputs, true, + vduModel.getTimeoutMinutes(), rollbackOnFailure); + + VduInstance actual = cloudify.instantiateVdu(cloudInfo, instanceName, inputs, vduModel, rollbackOnFailure); + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void queryVduTest() throws MsoException { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("id"); + expected.setVduInstanceName("id"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.INSTANTIATED); + status.setLastAction(new PluginAction(null, null, null)); + expected.setStatus(status); + + CloudInfo cloudInfo = new CloudInfo(); + cloudInfo.setCloudSiteId("cloudSiteId"); + cloudInfo.setTenantId("tenantId"); + DeploymentInfo deployment = new DeploymentInfo(); + deployment.setId("id"); + deployment.setStatus(DeploymentStatus.INSTALLED); + String instanceId = "instanceId"; + + MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class); + + doReturn(deployment).when(cloudify).queryDeployment(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(), + instanceId); + + VduInstance actual = cloudify.queryVdu(cloudInfo, instanceId); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void deleteVduTest() throws MsoException { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("id"); + expected.setVduInstanceName("id"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.DELETING); + status.setLastAction(new PluginAction("deleting", null, null)); + expected.setStatus(status); + + CloudInfo cloudInfo = new CloudInfo(); + cloudInfo.setCloudSiteId("cloudSiteId"); + cloudInfo.setTenantId("tenantId"); + String instanceId = "instanceId"; + int timeoutMinutes = 1; + DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class); + deployment.setId("id"); + deployment.setStatus(DeploymentStatus.CREATED); + when(deployment.getId()).thenReturn("id"); + when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED); + when(deployment.getLastAction()).thenReturn("deleting"); + MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class); + doReturn(deployment).when(cloudify).uninstallAndDeleteDeployment(cloudInfo.getCloudSiteId(), + cloudInfo.getTenantId(), instanceId, timeoutMinutes); + + VduInstance actual = cloudify.deleteVdu(cloudInfo, instanceId, timeoutMinutes); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void deploymentInfoToVduInstanceTest() { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("id"); + expected.setVduInstanceName("id"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.DELETING); + status.setLastAction(new PluginAction("deleting", null, null)); + expected.setStatus(status); + + DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class); + deployment.setId("id"); + deployment.setStatus(DeploymentStatus.CREATED); + when(deployment.getId()).thenReturn("id"); + when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED); + when(deployment.getLastAction()).thenReturn("deleting"); + + MsoCloudifyUtils cloudify = new MsoCloudifyUtils(); + + VduInstance actual = cloudify.deploymentInfoToVduInstance(deployment); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void deploymentStatusToVduStatusTest() { + VduStatus expected = new VduStatus(); + expected.setState(VduStateType.DELETING); + expected.setLastAction(new PluginAction("deleting", null, null)); + + DeploymentInfo deployment = Mockito.mock(DeploymentInfo.class); + deployment.setId("id"); + deployment.setStatus(DeploymentStatus.CREATED); + when(deployment.getId()).thenReturn("id"); + when(deployment.getStatus()).thenReturn(DeploymentStatus.CREATED); + when(deployment.getLastAction()).thenReturn("deleting"); + + MsoCloudifyUtils cloudify = new MsoCloudifyUtils(); + + VduStatus actual = cloudify.deploymentStatusToVduStatus(deployment); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void getOpenstackConfigTest() { + OpenstackConfig expected = new OpenstackConfig(); + expected.setRegion("regionId"); + expected.setAuthUrl("identityUrl"); + expected.setUsername("msoId"); + expected.setPassword("msoPass"); + expected.setTenantName("tenantId"); + + MsoCloudifyUtils cloudify = new MsoCloudifyUtils(); + CloudSite cloudSite = Mockito.mock(CloudSite.class); + CloudIdentity cloudIdentity = Mockito.mock(CloudIdentity.class); + when(cloudSite.getIdentityService()).thenReturn(cloudIdentity); + when(cloudSite.getRegionId()).thenReturn("regionId"); + when(cloudIdentity.getIdentityUrl()).thenReturn("identityUrl"); + when(cloudIdentity.getMsoId()).thenReturn("msoId"); + when(cloudIdentity.getMsoPass()).thenReturn("msoPass"); + String tenantId = "tenantId"; + OpenstackConfig actual = cloudify.getOpenstackConfig(cloudSite, tenantId); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void getAzureConfigTest() { + AzureConfig expected = new AzureConfig(); + expected.setSubscriptionId("subscriptionId"); + expected.setTenantId("tenantId"); + expected.setClientId("msoId"); + expected.setClientSecret("msoPass"); + + MsoCloudifyUtils cloudify = new MsoCloudifyUtils(); + CloudSite cloudSite = Mockito.mock(CloudSite.class); + CloudIdentity cloudIdentity = Mockito.mock(CloudIdentity.class); + when(cloudSite.getIdentityService()).thenReturn(cloudIdentity); + when(cloudIdentity.getAdminTenant()).thenReturn("subscriptionId"); + when(cloudIdentity.getMsoId()).thenReturn("msoId"); + when(cloudIdentity.getMsoPass()).thenReturn("msoPass"); + String tenantId = "tenantId"; + AzureConfig actual = cloudify.getAzureConfig(cloudSite, tenantId); + + assertThat(actual, sameBeanAs(expected)); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java new file mode 100644 index 0000000000..a0ab8e6b11 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsTest2.java @@ -0,0 +1,169 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.openstack.utils; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.mso.adapters.vdu.CloudInfo; +import org.openecomp.mso.adapters.vdu.PluginAction; +import org.openecomp.mso.adapters.vdu.VduArtifact; +import org.openecomp.mso.adapters.vdu.VduArtifact.ArtifactType; +import org.openecomp.mso.adapters.vdu.VduInstance; +import org.openecomp.mso.adapters.vdu.VduModelInfo; +import org.openecomp.mso.adapters.vdu.VduStateType; +import org.openecomp.mso.adapters.vdu.VduStatus; +import org.openecomp.mso.cloud.CloudConfig; +import org.openecomp.mso.cloud.CloudSite; +import org.openecomp.mso.cloudify.beans.DeploymentInfo; +import org.openecomp.mso.cloudify.beans.DeploymentStatus; +import org.openecomp.mso.cloudify.utils.MsoCloudifyUtils; +import org.openecomp.mso.openstack.beans.HeatStatus; +import org.openecomp.mso.openstack.beans.StackInfo; +import org.openecomp.mso.openstack.exceptions.MsoException; + +import com.fasterxml.jackson.core.JsonProcessingException; + +public class MsoHeatUtilsTest2 { + + @Test + public void instantiateVduTest() throws MsoException, JsonProcessingException { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("canonicalName"); + expected.setVduInstanceName("name"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.INSTANTIATED); + status.setLastAction((new PluginAction("create", "complete", ""))); + expected.setStatus(status); + + MsoHeatUtils heatUtils = Mockito.spy(MsoHeatUtils.class); + CloudSite site = new CloudSite(); + Optional opSite = Optional.ofNullable(site); + CloudConfig config = Mockito.mock(CloudConfig.class); + heatUtils.cloudConfig = config; + CloudInfo cloudInfo = new CloudInfo(); + cloudInfo.setCloudSiteId("cloudSiteId"); + cloudInfo.setTenantId("tenantId"); + VduModelInfo vduModel = new VduModelInfo(); + vduModel.setModelCustomizationUUID("blueprintId"); + vduModel.setTimeoutMinutes(1); + VduArtifact artifact = new VduArtifact(); + artifact.setName("name"); + artifact.setType(ArtifactType.MAIN_TEMPLATE); + byte[] content = new byte[1]; + artifact.setContent(content); + List artifacts = new ArrayList<>(); + artifacts.add(artifact); + vduModel.setArtifacts(artifacts); + Map blueprintFiles = new HashMap<>(); + blueprintFiles.put(artifact.getName(), artifact.getContent()); + String instanceName = "instanceName"; + Map inputs = new HashMap<>(); + boolean rollbackOnFailure = true; + String heatTemplate = new String(artifact.getContent()); + when(config.getCloudSite(cloudInfo.getCloudSiteId())).thenReturn(opSite); + Map nestedTemplates = new HashMap(); + Map files = new HashMap(); + + StackInfo stackInfo = new StackInfo(); + stackInfo.setCanonicalName("canonicalName"); + stackInfo.setName("name"); + stackInfo.setStatus(HeatStatus.CREATED); + + doReturn(stackInfo).when(heatUtils).createStack(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(), + instanceName, heatTemplate, inputs, true, vduModel.getTimeoutMinutes(), null, nestedTemplates, files, + rollbackOnFailure); + + VduInstance actual = heatUtils.instantiateVdu(cloudInfo, instanceName, inputs, vduModel, rollbackOnFailure); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void queryVduTest() throws MsoException, JsonProcessingException { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("canonicalName"); + expected.setVduInstanceName("name"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.INSTANTIATED); + status.setLastAction((new PluginAction("create", "complete", ""))); + expected.setStatus(status); + + CloudInfo cloudInfo = new CloudInfo(); + cloudInfo.setCloudSiteId("cloudSiteId"); + cloudInfo.setTenantId("tenantId"); + String instanceId = "instanceId"; + + StackInfo stackInfo = new StackInfo(); + stackInfo.setCanonicalName("canonicalName"); + stackInfo.setName("name"); + stackInfo.setStatus(HeatStatus.CREATED); + + MsoHeatUtils heatUtils = Mockito.spy(MsoHeatUtils.class); + + doReturn(stackInfo).when(heatUtils).queryStack(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(), instanceId); + + VduInstance actual = heatUtils.queryVdu(cloudInfo, instanceId); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void deleteVduTest() throws MsoException { + VduInstance expected = new VduInstance(); + expected.setVduInstanceId("canonicalName"); + expected.setVduInstanceName("name"); + VduStatus status = new VduStatus(); + status.setState(VduStateType.DELETED); + expected.setStatus(status); + + CloudInfo cloudInfo = new CloudInfo(); + cloudInfo.setCloudSiteId("cloudSiteId"); + cloudInfo.setTenantId("tenantId"); + String instanceId = "instanceId"; + + StackInfo stackInfo = new StackInfo(); + stackInfo.setCanonicalName("canonicalName"); + stackInfo.setName("name"); + stackInfo.setStatus(HeatStatus.NOTFOUND); + + int timeoutInMinutes = 1; + + MsoHeatUtils heatUtils = Mockito.spy(MsoHeatUtils.class); + + doReturn(stackInfo).when(heatUtils).deleteStack( cloudInfo.getTenantId(), cloudInfo.getCloudSiteId(), instanceId, true); + + VduInstance actual = heatUtils.deleteVdu(cloudInfo, instanceId, timeoutInMinutes); + + assertThat(actual, sameBeanAs(expected)); + } + +} -- cgit 1.2.3-korg