diff options
author | shrikantawachar <shrikant.awachar@amdocs.com> | 2018-02-12 16:57:59 +0530 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2018-02-14 11:23:44 +0000 |
commit | 9f33060362b6bf8b3a7cdcdab6ce3d1c81946300 (patch) | |
tree | 4900df52242ab5804408ccda3e51159e344f01e4 /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test | |
parent | 71904f241cd3047054dc0a36c04120a3f53205ae (diff) |
Enforcing HEAT validation after HEAT upload
Back end implementation , Junits for Enforcing HEAT validation after heat upload.
Change-Id: I0572b1d5e455023d45dc3b50b0bae7f3b6bbcc2e
Issue-ID: SDC-1027
Signed-off-by: shrikantawachar <shrikant.awachar@amdocs.com>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test')
2 files changed, 128 insertions, 20 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java index 5af39551b4..e1d58c6a18 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java @@ -1,3 +1,19 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + package org.openecomp.sdc.vendorsoftwareproduct.impl; import static org.mockito.Matchers.any; @@ -11,6 +27,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.json.JsonUtil; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao; @@ -23,6 +40,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData; import org.openecomp.sdc.vendorsoftwareproduct.utils.ZipFileUtils; import org.openecomp.sdc.versioning.dao.types.Version; @@ -59,6 +77,8 @@ public class OrchestrationTemplateCandidateManagerImplTest { private static final String COMPONENT_NAME_3 = "oam_server"; private static final String COMPONENT_NAME_4 = "ps_server"; + private static final String USER1 = "vspTestUser1"; + @Mock private VendorSoftwareProductInfoDao vspInfoDaoMock; @Mock @@ -240,6 +260,43 @@ public class OrchestrationTemplateCandidateManagerImplTest { Assert.assertEquals(componentDependenciesBeforeDelete.size(), 2); } + @Test + public void testGetFileDataStructure() { + Optional<String> jsonFileDataStructure = Optional.of(new String("{\n" + + " \"modules\": [\n" + + " {\n" + + " \"yaml\": \"hot-mog-0108-bs1271.yml\",\n" + + " \"env\": \"hot-mog-0108-bs1271.env\"\n" + + " }\n" + + " ],\n" + + " \"unassigned\": [],\n" + + " \"artifacts\": [],\n" + + " \"nested\": []\n" + + "}")); + Optional<FilesDataStructure> filesDataStructureOptional = Optional.of(JsonUtil.json2Object + (jsonFileDataStructure.get(), FilesDataStructure.class)); + doReturn(filesDataStructureOptional).when(candidateServiceMock) + .getOrchestrationTemplateCandidateFileDataStructure(VSP_ID, VERSION01); + Optional<FilesDataStructure> filesDataStructure = candidateManager.getFilesDataStructure(VSP_ID, + VERSION01); + assertNotNull(filesDataStructure); + assertEquals(filesDataStructureOptional.get().getModules().size(), filesDataStructure.get() + .getModules().size()); + assertEquals(filesDataStructureOptional.get().getModules().get(0).getName(), + filesDataStructure.get().getModules().get(0).getName()); + } + + @Test + public void testAbort() { + + Mockito.doNothing().when(candidateServiceMock).deleteOrchestrationTemplateCandidate(VSP_ID, + VERSION01); + candidateManager.abort(VSP_ID, VERSION01); + + Mockito.verify(candidateServiceMock, Mockito.times(1)).deleteOrchestrationTemplateCandidate + (VSP_ID, VERSION01); + } + private Map<String, String> getVspInitComponentIdNameInfo() { Map<String, String> componentIdNameInfoBeforeProcess = new HashMap<>(); componentIdNameInfoBeforeProcess.put(COMPONENT_ORIG_ID_1, COMPONENT_NAME_1); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java index fd274d0898..2e10f1351e 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java @@ -1,9 +1,6 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ +/* + * Copyright © 2016-2018 European Support Limited + * * 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 @@ -15,11 +12,18 @@ * 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.sdc.vendorsoftwareproduct.impl; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; @@ -40,32 +44,31 @@ import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; -import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade; import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService; +import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager; import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager; import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager; import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.EnrichmentManagerFactoryImpl; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator; -import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor; import org.openecomp.sdc.versioning.VersioningManager; import org.openecomp.sdc.versioning.dao.types.Version; import org.openecomp.sdc.versioning.dao.types.VersionStatus; -import org.openecomp.sdc.versioning.errors.EditOnEntityLockedByOtherErrorBuilder; -import org.openecomp.sdc.versioning.errors.EntityNotExistErrorBuilder; import org.openecomp.sdc.versioning.types.VersionInfo; import org.openecomp.sdc.versioning.types.VersionableEntityAction; import org.testng.Assert; @@ -84,18 +87,9 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; - public class VendorSoftwareProductManagerImplTest { private static final String INVALID_VERSION_MSG = "Invalid requested version."; @@ -142,6 +136,10 @@ public class VendorSoftwareProductManagerImplTest { @InjectMocks private VendorSoftwareProductManagerImpl vendorSoftwareProductManager; + @Mock + private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManagerMock; + @Mock + private ComponentDependencyModelDao componentDependencyModelDao; private OrchestrationTemplateCandidateManager candidateManager; private MonitoringUploadsManager monitoringUploadsManager; @@ -587,6 +585,59 @@ public class VendorSoftwareProductManagerImplTest { assertVSPInWantedLocationInVSPList(id007, 0, USER3); } */ + @Test + public void testSubmitWithCandidateDataNotProcessed() throws IOException { + VspDetails vsp = + createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", + "category", "subCategory", "licenseAgreementId", + Collections.singletonList("featureGroupId")); + vsp.setOnboardingMethod("NetworkPackage"); + doReturn(vsp).when(vspInfoDaoMock).get(anyObject()); + + OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new + OrchestrationTemplateCandidateData(); + orchestrationTemplateCandidateData.setFileSuffix("zip"); + orchestrationTemplateCandidateData.setFilesDataStructure("testdata"); + orchestrationTemplateCandidateData.setValidationData(""); + doReturn(orchestrationTemplateCandidateData).when(orchestrationTemplateCandidateManagerMock) + .getInfo(VSP_ID, VERSION01); + ValidationResponse validationResponse = + vendorSoftwareProductManager.validate(VSP_ID, VERSION01); + Assert.assertNotNull(validationResponse); + Assert.assertFalse(validationResponse.isValid()); + Assert.assertNotNull(validationResponse.getVspErrors()); + Assert.assertEquals(validationResponse.getVspErrors().size(), 1); + + verify(versioningManagerMock, never()) + .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, + USER1, null); + } + + @Test + public void testSubmitWithCandidateProcessedIsInvalid() throws IOException { + VspDetails vsp = createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-VSP", "vendorName", + "vl1Id", "icond", "category", "subcategory", "licenseAgreementId", Collections + .singletonList("featureGroupId")); + vsp.setOnboardingMethod("NetworkPackage"); + doReturn(vsp).when(vspInfoDaoMock).get(anyObject()); + + OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new + OrchestrationTemplateCandidateData(); + orchestrationTemplateCandidateData.setFileSuffix("zip"); + orchestrationTemplateCandidateData.setValidationData("Invalid processed data"); + doReturn(orchestrationTemplateCandidateData).when(orchestrationTemplateCandidateManagerMock) + .getInfo(VSP_ID, VERSION01); + ValidationResponse validationResponse = + vendorSoftwareProductManager.validate(VSP_ID, VERSION01); + Assert.assertNotNull(validationResponse); + Assert.assertFalse(validationResponse.isValid()); + Assert.assertNotNull(validationResponse.getVspErrors()); + Assert.assertEquals(validationResponse.getVspErrors().size(), 1); + + verify(versioningManagerMock, never()) + .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, + USER1, null); + } private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { candidateManager.upload(vspId, VERSION01, upload, "zip", "file"); |