From 9eedd3e7567e7926eadf3efd700a8c9153e9259b Mon Sep 17 00:00:00 2001 From: mojahidi Date: Thu, 28 Dec 2017 17:50:41 +0530 Subject: Fixed sonar issues - VersionedVendorSoftwareProd Fixed all sonar issues Change-Id: Ibf766225a961e11249fbcebe8115b5426f521a83 Issue-ID: SDC-343 Signed-off-by: mojahidi --- .../sdc/vendorsoftwareproduct/VSPFullTest.java | 200 --------------- .../impl/VendorSoftwareProductManagerImplTest.java | 273 --------------------- 2 files changed, 473 deletions(-) delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VSPFullTest.java (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java') diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VSPFullTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VSPFullTest.java deleted file mode 100644 index be2de13c16..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/VSPFullTest.java +++ /dev/null @@ -1,200 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 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.sdc.vendorsoftwareproduct; - -public class VSPFullTest { -/* - - - public static final Version VERSION01 = new Version(0, 1); - private static final VendorSoftwareProductDao vendorSoftwareProductDao = - VendorSoftwareProductDaoFactory - .getInstance().createInterface(); - private static final String USER1 = "vspTestUser1"; - private static VendorSoftwareProductManager vendorSoftwareProductManager = null; - //new VendorSoftwareProductManagerImpl(); - private static VendorLicenseFacade vendorLicenseFacade = - VendorLicenseFacadeFactory.getInstance().createInterface(); - private OrchestrationTemplateCandidateManager candidateManager; - private MonitoringUploadsManager mibManager; - private NicManager nicManager; - - @Test - public void testEnrichModelInSubmit() { - UniqueValueUtil - .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, - "VSP_FullTest"); - - String vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VSPCommon - .createVendorLicenseModel("vlmName " + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"), - USER1).getId(); - String entitlementPoolId = vendorLicenseFacade - .createEntitlementPool(new EntitlementPoolEntity(vlm1Id, null, null), USER1).getId(); - - FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlm1Id, null, null); - featureGroup.getEntitlementPoolIds().add(entitlementPoolId); - String featureGroupId = vendorLicenseFacade.createFeatureGroup(featureGroup, USER1).getId(); - - LicenseAgreementEntity licenseAgreement = new LicenseAgreementEntity(vlm1Id, null, null); - licenseAgreement.getFeatureGroupIds().add(featureGroupId); - String licenseAgreementId = - vendorLicenseFacade.createLicenseAgreement(licenseAgreement, USER1).getId(); - - vendorLicenseFacade.checkin(vlm1Id, USER1); - vendorLicenseFacade.submit(vlm1Id, USER1); - - String vspId = createVsp(vlm1Id, licenseAgreementId, licenseAgreement.getFeatureGroupIds()); - - Collection components = uploadFullCompositionFile(vspId); - - InputStream zis1 = getFileInputStream("/validation/zips/various/MIB.zip"); - mibManager - .upload(zis1, "MMSC.zip", vspId, VERSION01, - components.iterator().next().getId(), - MonitoringUploadType.SNMP_TRAP, - USER1); - - //check in - vendorSoftwareProductManager.checkin(vspId, USER1); - //submit - try { - ValidationResponse result = vendorSoftwareProductManager.submit(vspId, USER1); - //Assert.assertTrue(result.isValid()); - //PackageInfo createPackageResult = vendorSoftwareProductManager.createPackage(vspId, USER1); - - } catch (IOException exception) { - Assert.fail(); - } - VersionedVendorSoftwareProductInfo details = - vendorSoftwareProductManager.getVsp(vspId, null, USER1); - - - //File csar = vendorSoftwareProductManager.getTranslatedFile(vspId,details.getVersionInfo().getActiveVersion(),USER1); - // writeFile(csar); - - - ToscaServiceModel model = - (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface() - .getServiceModel(vspId, details.getVersionInfo().getActiveVersion()); - - Map capabilities = new HashMap<>(); - for (ComponentEntity component : components) { - model.getServiceTemplates(). - entrySet(). - stream(). - filter(entryValue -> entryValue.getValue() != null && - entryValue.getValue().getNode_types() != null && - entryValue.getValue(). - getNode_types(). - containsKey(component.getComponentCompositionData().getName())). - forEach(entryValue -> entryValue.getValue().getNode_types(). - values(). - stream(). - filter(type -> MapUtils.isNotEmpty(type.getCapabilities())). - forEach(type -> type.getCapabilities(). - entrySet(). - forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(), - entry.getValue())))); - - } - - Assert.assertNotNull(capabilities); - } - - private Collection uploadFullCompositionFile(String vspId) { - candidateManager.upload(vspId, VERSION01, - getFileInputStream("/vspmanager/zips/fullComposition.zip"), USER1); - candidateManager.process(vspId, VERSION01, USER1); - - Collection components = null; - //vendorSoftwareProductManager.listComponents(vspId, null, USER1); - Assert.assertFalse(components.isEmpty()); - - for (ComponentEntity component : components) { -*/ -/* Assert.assertNotNull(vendorSoftwareProductManager - .getQuestionnaire(vspId, null, component.getId(), USER1).getData());*//* - - - Collection nics = - nicManager.listNics(vspId, null, component.getId(), USER1); - Assert.assertFalse(nics.isEmpty()); - for (NicEntity nic : nics) { - Assert.assertNotNull(nicManager - .getNicQuestionnaire(vspId, null, component.getId(), nic.getId(), USER1).getData()); - } - } - - return components; - } - - private String createVsp(String vlm1Id, String licenseAgreementId, Set featureGroupIds) { - VspDetails expectedVsp = VSPCommon - .createVspDetails(null, null, "VSP_FullTest", "Test-vsp_fullTest", "vendorName", vlm1Id, - "icon", "category", "subCategory", licenseAgreementId, - featureGroupIds.stream().collect(Collectors.toList())); - String vspId = vendorSoftwareProductManager.createVsp(expectedVsp, USER1).getId(); - - VspDetails actualVsp = - vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(vspId, VERSION01)); - expectedVsp.setId(vspId); - expectedVsp.setVersion(VERSION01); - - //VendorSoftwareProductManagerImplTest.assertVspsEquals(actualVsp, expectedVsp); - Assert.assertNotNull( - vendorSoftwareProductManager.getVspQuestionnaire(vspId, null, USER1).getData()); - return vspId; - } - - private void writeFile(File csar) { - try { - FileInputStream in = new FileInputStream(csar); - File output = new File("CSAR_vDNS.zip"); - - FileOutputStream out = new FileOutputStream(output); - - IOUtils.copy(in, out); - in.close(); - out.close(); - } catch (IOException exception) { - throw new RuntimeException(exception); - } - } - - private void addCapability(String entryValueKey, Map capabilities, - String key, CapabilityDefinition value) { - - capabilities.put(entryValueKey + "_" + key, value); - } - - private InputStream getFileInputStream(String fileName) { - URL url = this.getClass().getResource(fileName); - try { - return url.openStream(); - } catch (IOException exception) { - exception.printStackTrace(); - return null; - } - } - - -*/ -} 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 9ef408c460..4e22cf794e 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 @@ -157,96 +157,6 @@ public class VendorSoftwareProductManagerImplTest { public void tearDown(){ vendorSoftwareProductManager = null; } -/* - @Test - public void testListWhenNone() { - doReturn(new HashMap<>()).when(versioningManagerMock).listEntitiesVersionInfo - (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, - VersionableEntityAction.Read); - List vsps = - vendorSoftwareProductManager.listVsps(null); - Assert.assertEquals(vsps.size(), 0); - } - - @Test - public void testList() { - String vsp1id = "vsp1_id"; - String vsp2id = "vsp2_id"; - Map vspsTobeReturned = new HashMap<>(); - - VersionInfo versionInfo1 = new VersionInfo(); - versionInfo1.setActiveVersion(VERSION01); - vspsTobeReturned.put(vsp1id, versionInfo1); - - VersionInfo versionInfo2 = new VersionInfo(); - versionInfo2.setActiveVersion(VERSION10); - vspsTobeReturned.put(vsp2id, versionInfo2); - - doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo - (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, - VersionableEntityAction.Read); - - VspDetails vsp1 = new VspDetails(vsp1id, VERSION01); - vsp1.setWritetimeMicroSeconds(8L); - doReturn(vsp1).when(vspInfoDaoMock) - .get(any(VspDetails.class)); - - List vsps = - vendorSoftwareProductManager.listVsps(null); - Assert.assertEquals(vsps.size(), 2); - } - - @Test - public void testListFinalsWhenNone() { - String vsp1id = "vsp1_id"; - String vsp2id = "vsp2_id"; - Map vspsTobeReturned = new HashMap<>(); - - VersionInfo versionInfo1 = new VersionInfo(); - versionInfo1.setActiveVersion(VERSION01); - vspsTobeReturned.put(vsp1id, versionInfo1); - - VersionInfo versionInfo2 = new VersionInfo(); - versionInfo2.setActiveVersion(VERSION10); - vspsTobeReturned.put(vsp2id, versionInfo2); - - doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo - (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, - VersionableEntityAction.Read); - - List vsps = - vendorSoftwareProductManager.listVsps(VersionStatus.Certified.name()); - Assert.assertEquals(vsps.size(), 0); - } - - @Test - public void testListFinals() { - String vsp1id = "vsp1_id"; - String vsp2id = "vsp2_id"; - Map vspsTobeReturned = new HashMap<>(); - - VersionInfo versionInfo1 = new VersionInfo(); - versionInfo1.setActiveVersion(VERSION01); - vspsTobeReturned.put(vsp1id, versionInfo1); - - VersionInfo versionInfo2 = new VersionInfo(); - versionInfo2.setActiveVersion(new Version(1, 3)); - versionInfo2.setLatestFinalVersion(VERSION10); - vspsTobeReturned.put(vsp2id, versionInfo2); - - doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo - (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, - VersionableEntityAction.Read); - - VspDetails vsp2 = new VspDetails(vsp2id, VERSION10); - vsp2.setWritetimeMicroSeconds(8L); - doReturn(vsp2).when(vspInfoDaoMock) - .get(any(VspDetails.class)); - - List vsps = - vendorSoftwareProductManager.listVsps(VersionStatus.Certified.name()); - Assert.assertEquals(vsps.size(), 1); - }*/ @Test @@ -585,107 +495,6 @@ public class VendorSoftwareProductManagerImplTest { Assert.assertEquals(ce.getMessage(), Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()); } } -/* - @Test - public void testEnrichModelInSubmit() { - UniqueValueUtil - .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, - "VSP_syb"); - VspDetails vspDetails = vendorSoftwareProductManager.createVsp( - createVspDetails(null, null, "VSP_syb", "Test-vsp_syb", "vendorName", "vlm1Id", "icon", - "category", "subCategory", "456", null), USER1); - String id = vspDetails.getId(); - - //upload file - InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip"); - candidateManager.upload(id, VERSION01, zis, USER1); - OrchestrationTemplateActionResponse uploadFileResponse = - candidateManager.process(id, VERSION01, USER1); - - //check in - vendorSoftwareProductManager.checkin(id, USER1); - //submit - try { - ValidationResponse result = vendorSoftwareProductManager.submit(id, USER1); - } catch (IOException exception) { - Assert.fail(); - } - VersionedVendorSoftwareProductInfo details = - vendorSoftwareProductManager.getVsp(id, null, USER1); - Collection components =vendorSoftwareProductManager - .listComponents(id, details.getVersionInfo().getVersion(), USER1); - - ToscaServiceModel model = - (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface() - .getServiceModel(id, details.getVersionInfo().getVersion()); - - Map capabilities = new HashMap<>(); - for (ComponentEntity component : components) { - model.getServiceTemplates(). - entrySet(). - stream(). - filter(entryValue -> entryValue.getValue() != null && - entryValue.getValue().getNode_types() != null && - entryValue.getValue(). - getNode_types(). - containsKey(component.getComponentCompositionData().getName())). - forEach(entryValue -> entryValue.getValue().getNode_types(). - values(). - stream(). - filter(type -> MapUtils.isNotEmpty(type.getCapabilities())). - forEach(type -> type.getCapabilities(). - entrySet(). - forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(), - entry.getValue())))); - - } - - Assert.assertNotNull(capabilities); - } - - @Test(dependsOnMethods = {"testCreatePackage"}) - public void testEnrichedFilesDeletedOnNewUpload() throws IOException { - Version activeVersion; - - createPackageFromUpload(VSP_ID, USER1, "/fullComposition"); - activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo() - .getVersion(); - - List firstExternalArtifacts = enrichedServiceModelDaoMock - .getExternalArtifacts(VSP_ID, activeVersion); - ToscaServiceModel firstServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID, - activeVersion); - - createPackageFromUpload(VSP_ID, USER1, "/emptyComposition"); - activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo() - .getVersion(); - - List secondExternalArtifacts = enrichedServiceModelDaoMock - .getExternalArtifacts(VSP_ID, activeVersion); - ToscaServiceModel secondServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID, - activeVersion); - - Assert.assertNotEquals(firstExternalArtifacts, secondExternalArtifacts); - Assert.assertNotEquals(firstServiceModel, secondServiceModel); - - } - - @Test(dependsOnMethods = {"testMibsDeletedInCsar"}) - public void testServiceTemplatesAreDeletedInCsarOnNewUpload() throws IOException { - String nestedPath = "Definitions" + File.separator + "nested"; - - uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullCompositionNested.zip"); - checkinSubmitCreatePackage(VSP_ID, USER1); - List nestedFileNamesServiceTemplates = - getWantedFileNamesFromCsar(nestedPath); - - uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullComposition.zip"); - checkinSubmitCreatePackage(VSP_ID, USER1); - List emptyNestedNamesList = getWantedFileNamesFromCsar(nestedPath); - - Assert.assertEquals(emptyNestedNamesList.size(), 0); - Assert.assertNotEquals(emptyNestedNamesList.size(), nestedFileNamesServiceTemplates.size()); - }*/ private List getWantedFileNamesFromCsar(String pathInCsar) throws IOException { @@ -788,11 +597,6 @@ public class VendorSoftwareProductManagerImplTest { Assert.assertNotNull(uploadData); } - private void addCapability(String entryValueKey, Map capabilities, - String key, CapabilityDefinition value) { - - capabilities.put(entryValueKey + "_" + key, value); - } public InputStream getFileInputStream(String fileName) { URL url = this.getClass().getResource(fileName); @@ -804,30 +608,6 @@ public class VendorSoftwareProductManagerImplTest { } } -/* private void assertVSPInWantedLocationInVSPList(String vspId, int location, String user) { - List vspList = - vendorSoftwareProductManager.listVsps(null); - Assert.assertEquals(vspList.get(location).getVspDetails().getId(), vspId); - }*/ - - - // private void assertInfoArtifactIsInRightPathInCsar(String vspId, String zipFileName) -// throws IOException { -// ZipInputStream inputZipStream = new ZipInputStream(new FileInputStream(new File(zipFileName))); -// boolean isInfoArtifactInZip = false; -// -// ZipEntry zipEntry; -// while ((zipEntry = inputZipStream.getNextEntry()) != null) { -// String currentEntryName = zipEntry.getName(); -// if(currentEntryName.equals("Artifacts\\Informative\\Guide\\VSP_" + -// vspId + "_Information.txt")){ -// isInfoArtifactInZip = true; -// break; -// } -// } -// -// Assert.assertTrue(isInfoArtifactInZip); -// } static VspDetails createVspDetails(String id, Version version, String name, String desc, String vendorName, String vlm, String icon, String category, String subCategory, @@ -862,43 +642,6 @@ public class VendorSoftwareProductManagerImplTest { } -// @Test -// public void testDownloadFile() throws IOException { -// VspDetails expectedVsp = VSPCommon.createVspDetails(null, null, String.format("VSP-test-%s", vlm1Id), "Test-vsp", "vendorName", "vlm1Id", "icon", "category", "subCategory", "123", null); -// VspDetails createdVsp = vendorSoftwareProductManager.createVsp(expectedVsp, USER1); -// -// id005 = createdVsp.getId(); -// Assert.assertNotNull(id005); -// Assert.assertNotNull(createdVsp.getVersion()); -// -// try (InputStream zipInputStream = new ZipFileUtils().getZipInputStream("/legalUploadWithWarning")) { -// -// UploadFileResponse uploadFileResponse = vendorSoftwareProductManager.upload(id005, zipInputStream, USER1); -// vendorSoftwareProductManager.process(id005, USER1); -// Optional fileCandidate = vendorSoftwareProductManager.get(id005, USER1); -// -// File latestHeatPackage = fileCandidate.get(); -// -// zipInputStream.reset(); -// byte[] uploaded = IOUtils.toByteArray(zipInputStream); -// -// Optional zipContentMap = vendorSoftwareProductManager.getZipContentMap(uploadFileResponse, uploaded); -// FileContentHandler fileContentHandler = new FileContentHandler(); -// if(zipContentMap.isPresent()){ -// fileContentHandler = zipContentMap.get(); -// } -// -// uploaded = IOUtils.toByteArray(fileContentHandler.getFiles().values()); -// -// byte[] downloaded; -// try (BufferedInputStream fileStream = new BufferedInputStream(new FileInputStream(latestHeatPackage))) { -// downloaded = IOUtils.toByteArray(fileStream); -// } -// -// Assert.assertTrue(Arrays.equals(uploaded, downloaded)); -// } -// } - // todo ********************** move to common ************************************** private void mockVersioning(VersionableEntityAction action) { @@ -909,20 +652,4 @@ public class VendorSoftwareProductManagerImplTest { action); } - private void mockVersioningEntityNotExist(VersionableEntityAction action, String vspId) { - doThrow(new CoreException(new EntityNotExistErrorBuilder( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId).build())) - .when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId, USER1, - action); - } - - private void MockVersioningEntityLocked(VersionableEntityAction action) { - doThrow(new CoreException(new EditOnEntityLockedByOtherErrorBuilder( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1) - .build())) - .when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER2, - action); - } } \ No newline at end of file -- cgit 1.2.3-korg