diff options
23 files changed, 107 insertions, 182 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java index 8e8b273015..d278962bdb 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java @@ -57,6 +57,8 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; + public class MonitoringUploadsManagerImpl implements MonitoringUploadsManager { private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage(); private final ComponentArtifactDao componentArtifactDao; @@ -109,7 +111,8 @@ public class MonitoringUploadsManagerImpl implements MonitoringUploadsManager { LoggerErrorCode.DATA_ERROR.getErrorCode(), INVALID + type .toString() + " zip file"); throw new CoreException(new MonitoringUploadErrorBuilder( - Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage()).build()); + getErrorWithParameters(Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(), + "zip")).build()); } else { Map<String, List<ErrorMessage>> errors = new HashMap<>(); try { @@ -137,7 +140,7 @@ public class MonitoringUploadsManagerImpl implements MonitoringUploadsManager { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, LoggerTragetServiceName.UPLOAD_MONITORING_FILE, ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(), INVALID + type - .toString() + "zip file" ); + .toString() + "zip file"); throw new CoreException(new MonitoringUploadErrorBuilder(exception.getMessage()).build()); } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java index c9bb956a18..093192e858 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java @@ -55,6 +55,8 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; + public class OrchestrationTemplateCandidateManagerImpl implements OrchestrationTemplateCandidateManager { private static final Logger LOGGER = @@ -156,7 +158,8 @@ public class OrchestrationTemplateCandidateManagerImpl if (!candidateDataEntity.isPresent()) { ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR, - Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage()); + getErrorWithParameters(Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage + (), "")); LOGGER.error(errorMessage.getMessage()); MDC_DATA_DEBUG_MESSAGE.debugExitMessage(VSP_ID, vspId); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java index d20dc07b63..f25f6d780b 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java @@ -31,12 +31,12 @@ public abstract class BaseOrchestrationTemplateHandler implements OrchestrationT CandidateService candidateService) { UploadFileResponse uploadFileResponse = new UploadFileResponse(); uploadFileResponse.setOnboardingType(getHandlerType()); - if (isNotEmptyFileToUpload(fileToUpload, uploadFileResponse, candidateService)) { + if (isNotEmptyFileToUpload(fileSuffix, fileToUpload, uploadFileResponse, candidateService)) { return uploadFileResponse; } byte[] uploadedFileData = FileUtils.toByteArray(fileToUpload); - if (isInvalidRawZipData(uploadFileResponse, uploadedFileData, candidateService)) { + if (isInvalidRawZipData(fileSuffix, uploadFileResponse, uploadedFileData, candidateService)) { return uploadFileResponse; } @@ -75,11 +75,11 @@ public abstract class BaseOrchestrationTemplateHandler implements OrchestrationT CandidateService candidateService, UploadFileResponse uploadFileResponse); - private boolean isNotEmptyFileToUpload(InputStream fileToUpload, + private boolean isNotEmptyFileToUpload(String fileSuffix, InputStream fileToUpload, UploadFileResponse uploadFileResponse, CandidateService candidateService) { Optional<ErrorMessage> errorMessage = - candidateService.validateNonEmptyFileToUpload(fileToUpload); + candidateService.validateNonEmptyFileToUpload(fileToUpload, fileSuffix); if (errorMessage.isPresent()) { uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); return true; @@ -87,11 +87,12 @@ public abstract class BaseOrchestrationTemplateHandler implements OrchestrationT return false; } - protected boolean isInvalidRawZipData(UploadFileResponse uploadFileResponse, + protected boolean isInvalidRawZipData(String fileSuffix, + UploadFileResponse uploadFileResponse, byte[] uploadedFileData, CandidateService candidateService) { Optional<ErrorMessage> errorMessage; - errorMessage = candidateService.validateRawZipData(uploadedFileData); + errorMessage = candidateService.validateRawZipData(fileSuffix, uploadedFileData); if (errorMessage.isPresent()) { uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); return true; diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java index 16147553fe..bc999de4fe 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java @@ -160,9 +160,10 @@ public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateH } @Override - protected boolean isInvalidRawZipData(UploadFileResponse uploadFileResponse, + protected boolean isInvalidRawZipData(String fileSuffix, + UploadFileResponse uploadFileResponse, byte[] uploadedFileData, CandidateService candidateService) { - return super.isInvalidRawZipData(uploadFileResponse, uploadedFileData, candidateService); + return super.isInvalidRawZipData(fileSuffix, uploadFileResponse, uploadedFileData, candidateService); } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ValidationResponse.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ValidationResponse.java index 09e7a40ec5..316b1a4049 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ValidationResponse.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ValidationResponse.java @@ -64,7 +64,7 @@ public class ValidationResponse { valid = false; } - VendorSoftwareProductUtils.setErrorsIntoLogger(vspErrors, serviceName, targetServiceName); + VendorSoftwareProductUtils.setErrorsIntoLogger(vspErrors, targetServiceName); } @@ -103,7 +103,7 @@ public class ValidationResponse { } VendorSoftwareProductUtils - .setErrorsIntoLogger(uploadDataErrors, serviceName, targetServiceName); + .setErrorsIntoLogger(uploadDataErrors, targetServiceName); } public Map<String, List<ErrorMessage>> getCompilationErrors() { @@ -125,7 +125,7 @@ public class ValidationResponse { } VendorSoftwareProductUtils - .setErrorsIntoLogger(uploadDataErrors, serviceName, targetServiceName); + .setErrorsIntoLogger(uploadDataErrors, targetServiceName); } public QuestionnaireValidationResult getQuestionnaireValidationResult() { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/utils/VendorSoftwareProductUtils.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/utils/VendorSoftwareProductUtils.java index 08528408d6..369efe38bc 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/utils/VendorSoftwareProductUtils.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/utils/VendorSoftwareProductUtils.java @@ -34,7 +34,6 @@ import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage; import org.openecomp.sdc.logging.types.LoggerConstants; import org.openecomp.sdc.logging.types.LoggerErrorDescription; -import org.openecomp.sdc.logging.types.LoggerServiceName; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; import org.slf4j.MDC; @@ -48,9 +47,8 @@ import java.util.Map; public class VendorSoftwareProductUtils { - private static final String MANUAL = "Manual"; protected static Logger logger = - (Logger) LoggerFactory.getLogger(VendorSoftwareProductUtils.class); + LoggerFactory.getLogger(VendorSoftwareProductUtils.class); /** * Add file names to upload file response. @@ -69,21 +67,6 @@ public class VendorSoftwareProductUtils { uploadFileResponse.removeFileFromList(SdcCommon.MANIFEST_NAME); } - /** - * Validate raw zip data. - * - * @param uploadedFileData the uploaded file data - * @param errors the errors - */ - public static void validateRawZipData(byte[] uploadedFileData, - Map<String, List<ErrorMessage>> errors) { - if (uploadedFileData.length == 0) { - MDC.put(LoggerConstants.ERROR_DESCRIPTION, LoggerErrorDescription.INVALID_ZIP); - ErrorMessage.ErrorMessageUtil.addMessage(SdcCommon.UPLOAD_FILE, errors).add( - new ErrorMessage(ErrorLevel.ERROR, - Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); - } - } /** * Validate content zip data. @@ -94,7 +77,7 @@ public class VendorSoftwareProductUtils { public static void validateContentZipData(FileContentHandler contentMap, Map<String, List<ErrorMessage>> errors) { MDC.put(LoggerConstants.ERROR_DESCRIPTION, LoggerErrorDescription.INVALID_ZIP); - if (contentMap.getFileList().size() == 0) { + if (contentMap.getFileList().isEmpty()) { ErrorMessage.ErrorMessageUtil.addMessage(SdcCommon.UPLOAD_FILE, errors) .add(new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage())); } @@ -119,21 +102,13 @@ public class VendorSoftwareProductUtils { } - private static boolean isTrapOrPoll(MonitoringUploadType type) { - return type.equals(MonitoringUploadType.SNMP_POLL) || - type.equals(MonitoringUploadType.SNMP_TRAP); - } - - /** * Sets errors into logger. - * - * @param errors the errors - * @param serviceName the service name + * @param errors the errors * @param targetServiceName the target service name */ public static void setErrorsIntoLogger(Map<String, List<ErrorMessage>> errors, - LoggerServiceName serviceName, String targetServiceName) { + String targetServiceName) { MdcDataErrorMessage mdcDataErrorMessage = new MdcDataErrorMessage(targetServiceName, LoggerConstants.TARGET_ENTITY_DB, ErrorLevel.ERROR.name(), null, null); @@ -153,13 +128,11 @@ public class VendorSoftwareProductUtils { /** * Sets errors into logger. - * - * @param errors the errors - * @param serviceName the service name + * @param errors the errors * @param targetServiceName the target service name */ public static void setErrorsIntoLogger(Collection<ErrorCode> errors, - LoggerServiceName serviceName, String targetServiceName) { + String targetServiceName) { MdcDataErrorMessage mdcDataErrorMessage = new MdcDataErrorMessage(targetServiceName, LoggerConstants.TARGET_ENTITY_DB, ErrorLevel.ERROR.name(), null, null); @@ -173,14 +146,4 @@ public class VendorSoftwareProductUtils { logger.error(error.message()); } } - - /*public static boolean isManual(String vspId, Version version, VendorSoftwareProductInfoDao - vspInfoDao) { - String onboardingMethod = vspInfoDao.get(new VspDetails(vspId, version)).getOnboardingMethod(); - if (MANUAL.equals(onboardingMethod)) { - return true; - } - return false; - }*/ - } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/common/utils/CommonUtil.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/common/utils/CommonUtil.java deleted file mode 100644 index 29b404664e..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/common/utils/CommonUtil.java +++ /dev/null @@ -1,36 +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.common.utils; - -import org.openecomp.core.utilities.file.FileContentHandler; -import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; - -import java.io.IOException; - -public class CommonUtil { - - public static FileContentHandler validateAndUploadFileContent(OnboardingTypesEnum type, - byte[] uploadedFileData) - throws IOException { - throw new IOException(); - } - -} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/CandidateServiceImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/CandidateServiceImplTest.java index 1c9d61b51b..5c4557360e 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/CandidateServiceImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/CandidateServiceImplTest.java @@ -66,19 +66,19 @@ public class CandidateServiceImplTest { @Test public void shouldReturnOptionalPresentIfInputStreamIsNull() { - assertTrue(candidateService.validateNonEmptyFileToUpload(null).isPresent()); + assertTrue(candidateService.validateNonEmptyFileToUpload(null, "zip").isPresent()); } // end validateNonEmptyFileToUpload tests // start validateNonEmptyFileToUpload tests @Test public void shouldReturnOptionalEmptyIfUploadedFileDataIsNotNull() { - assertEquals(candidateService.validateRawZipData(new byte[]{}), Optional.empty()); + assertEquals(candidateService.validateRawZipData("zip", new byte[]{}), Optional.empty()); } @Test public void shouldReturnOptionalPresentIfUploadedFileDataIsNull() { - assertTrue(candidateService.validateRawZipData(null).isPresent()); + assertTrue(candidateService.validateRawZipData("zip", null).isPresent()); } // end validateNonEmptyFileToUpload tests // start heatStructureTreeToFileDataStructure tests diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java index 046163515f..bd3b0b433a 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java @@ -17,6 +17,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.upload.csar; +import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.Spy; @@ -35,6 +36,8 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.function.Predicate; @@ -58,12 +61,14 @@ public class UploadCSARFileTest { @Mock private ManifestCreatorNamingConventionImpl manifestCreator; + @InjectMocks private OrchestrationTemplateCandidateManagerImpl candidateManager; - public static String id001 = null; - - public static Version activeVersion002 = null; + private static String id001 = "dummyId"; + private static Version activeVersion002 = new Version("dummyVersion"); + private static final String BASE_DIR = "/vspmanager.csar"; + private static final String CSAR = "csar"; @BeforeMethod @@ -76,115 +81,90 @@ public class UploadCSARFileTest { @Test public void testSuccessfulUploadFile() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + VspDetails vspDetails = new VspDetails(id001, activeVersion002); doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmock.csar")) { - UploadFileResponse uploadFileResponse = - candidateManager.upload(id001, activeVersion002, is, "csar", "SDCmock"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); - assertEquals(0, uploadFileResponse.getErrors().size()); - assertTrue(uploadFileResponse.getErrors().isEmpty()); - } + testCsarUpload("successfulUpload.csar", 0); } @Test - public void testFail1UploadFile() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + public void testIllegalUploadInvalidFileInRoot() throws Exception { + VspDetails vspDetails = new VspDetails(id001, activeVersion002); doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail1.csar")) { - UploadFileResponse uploadFileResponse = - candidateManager.upload(id001, activeVersion002, is, - "csar", "SDCmockFail1"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); - assertEquals(1, uploadFileResponse.getErrors().size()); - assertTrue(uploadFileResponse.getErrors().values().stream().anyMatch( - getListPredicate(Messages.CSAR_FILES_NOT_ALLOWED.getErrorMessage().substring(0, 7)))); - } - } - - private Predicate<List<ErrorMessage>> getListPredicate(String substring) { - return error -> isEquals(substring, error); - } - - private boolean isEquals(String substring, List<ErrorMessage> error) { - return error.iterator().next().getMessage().contains(substring); + UploadFileResponse response = testCsarUpload("invalidFileInRoot.csar", 1); + assertTrue(response.getErrors().values().stream().anyMatch( + getListPredicate(Messages.CSAR_FILES_NOT_ALLOWED.getErrorMessage().substring(0, 7)))); } @Test - public void testFail2UploadFile() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + public void testIllegalUploadMissingMainServiceTemplate() throws Exception { + VspDetails vspDetails = new VspDetails(id001, activeVersion002); doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail2.csar")) { - UploadFileResponse uploadFileResponse = - candidateManager.upload(id001, activeVersion002, is, - "csar", "SDCmockFail2"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); - assertEquals(1, uploadFileResponse.getErrors().size()); - assertTrue(uploadFileResponse.getErrors().values().stream().anyMatch( - getListPredicate(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage().substring(0, 7)))); - } - } - - @Test - public void testFail3UploadFile() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); - doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail3.csar")) { - UploadFileResponse uploadFileResponse = - candidateManager.upload(id001, activeVersion002, is, - "csar", "SDCmockFail3"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); - assertEquals(1, uploadFileResponse.getErrors().size()); - } + UploadFileResponse response = testCsarUpload("missingMainServiceTemplate.csar", 1); + assertTrue(response.getErrors().values().stream().anyMatch( + getListPredicate(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage().substring(0, 7)))); } @Test public void testUploadFileIsNotZip() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + VspDetails vspDetails = new VspDetails(id001, activeVersion002); doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - try (InputStream is = new ByteArrayInputStream("Thia is not a zip file".getBytes());) { - UploadFileResponse uploadFileResponse = - candidateManager.upload(id001, activeVersion002, is, - "csar", "file"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); - assertFalse(uploadFileResponse.getErrors().isEmpty()); - assertTrue(uploadFileResponse.getErrors().values().stream().anyMatch( - getListPredicate(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage().substring(0, 7)))); - } + UploadFileResponse response = testCsarUpload("notCsar.txt", 1); + assertEquals("no csar file was uploaded or file doesn't exist", + response.getErrors().values().iterator().next().get(0).getMessage()); } @Test public void testUploadFileIsEmpty() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + VspDetails vspDetails = new VspDetails(id001, activeVersion002); doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); try (InputStream is = new ByteArrayInputStream(new byte[]{})) { UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, "csar", "file"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); assertEquals(1, uploadFileResponse.getErrors().size()); } } @Test - public void testMFError() throws Exception { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + public void testInvalidManifestContent() throws Exception { + VspDetails vspDetails = new VspDetails(id001, activeVersion002); doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockBrokenMF.csar")) { - UploadFileResponse uploadFileResponse = - candidateManager.upload(id001, activeVersion002, is, "csar", "SDCmockBrokenMF"); - assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); - assertEquals(1, uploadFileResponse.getErrors().size()); - assertTrue(uploadFileResponse.getErrors().values().stream() - .anyMatch(getListPredicate(Messages.MANIFEST_NO_METADATA.getErrorMessage()))); + try (InputStream is = getClass() + .getResourceAsStream(BASE_DIR + "/invalidManifestContent.csar")) { + UploadFileResponse response = + candidateManager.upload(id001, activeVersion002, is, "csar", "invalidManifestContent"); + assertEquals(1, response.getErrors().size()); + assertEquals(response.getErrors().values().iterator().next().get(0).getMessage(), + "Manifest " + + "contains invalid line : aaa: vCSCF"); + + } + } + + private Predicate<List<ErrorMessage>> getListPredicate(String substring) { + return error -> isEquals(substring, error); + } + + private boolean isEquals(String substring, List<ErrorMessage> error) { + return error.iterator().next().getMessage().contains(substring); + } + + private UploadFileResponse testCsarUpload(String csarFileName, int expectedErrorsNumber) + throws IOException { + UploadFileResponse uploadFileResponse; + try (InputStream is = getClass() + .getResourceAsStream(BASE_DIR + File.separator + csarFileName)) { + uploadFileResponse = + candidateManager.upload(id001, activeVersion002, is, CSAR, csarFileName); + assertEquals(expectedErrorsNumber, uploadFileResponse.getErrors().size()); } + return uploadFileResponse; } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/validation/UploadFileValidationTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/validation/UploadFileValidationTest.java index 0be5bef352..0aa3e4037d 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/validation/UploadFileValidationTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/validation/UploadFileValidationTest.java @@ -77,7 +77,7 @@ public class UploadFileValidationTest { USER1); Assert.assertEquals(uploadFileResponse.getErrors().get(SdcCommon.UPLOAD_FILE).get(0) .getMessage(), - Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage()); + Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage()); } @Test(dependsOnMethods = "testUploadEmptyFile") diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar Binary files differdeleted file mode 100644 index f69efd2bb8..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar +++ /dev/null diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar Binary files differdeleted file mode 100644 index 02593a1d2f..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar +++ /dev/null diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar Binary files differdeleted file mode 100644 index 5e3ee6f387..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar +++ /dev/null diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar Binary files differdeleted file mode 100644 index 4874578ad9..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar +++ /dev/null diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar Binary files differdeleted file mode 100644 index c009a042e4..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar +++ /dev/null diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/invalidFileInRoot.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/invalidFileInRoot.csar Binary files differnew file mode 100644 index 0000000000..95adb41d22 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/invalidFileInRoot.csar diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/invalidManifestContent.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/invalidManifestContent.csar Binary files differnew file mode 100644 index 0000000000..75ed22187c --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/invalidManifestContent.csar diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/missingMainServiceTemplate.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/missingMainServiceTemplate.csar Binary files differnew file mode 100644 index 0000000000..86269fef15 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/missingMainServiceTemplate.csar diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/notCsar.txt b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/notCsar.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/notCsar.txt diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/successfulUpload.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/successfulUpload.csar Binary files differnew file mode 100644 index 0000000000..6a203ddbfd --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/successfulUpload.csar diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java index 038778be88..f994652751 100644 --- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java @@ -53,7 +53,7 @@ public enum Messages { MODULE_IN_MANIFEST_VOL_ENV_NO_VOL("Module '%s', has volume Env. reference with no Volume " + "reference"), ILLEGAL_MANIFEST("Illegal Manifest"), - NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST("no zip file was uploaded or zip file doesn't exist"), + NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST("no %s file was uploaded or file doesn't exist"), MAPPING_OBJECTS_FAILURE("Failed to map object %s to %s. Exception message: %s"), MORE_THEN_ONE_VOL_FOR_HEAT("heat contains more then one vol. selecting only first vol"), FILE_CONTENT_MAP("failed to load %s content"), diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java index 697dab27e9..08dc908a3f 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/filedatastructuremodule/CandidateService.java @@ -40,9 +40,10 @@ import java.util.Map; import java.util.Optional; public interface CandidateService { - Optional<ErrorMessage> validateNonEmptyFileToUpload(InputStream heatFileToUpload); + Optional<ErrorMessage> validateNonEmptyFileToUpload(InputStream heatFileToUpload, + String fileSuffix); - Optional<ErrorMessage> validateRawZipData(byte[] uploadedFileData); + Optional<ErrorMessage> validateRawZipData(String fileSuffix, byte[] uploadedFileData); OrchestrationTemplateCandidateData createCandidateDataEntity( CandidateDataEntityTo candidateDataEntityTo, InputStream zipFileManifest, diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java index 45746ed84e..e6e89a6cd4 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java @@ -71,6 +71,8 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; + public class CandidateServiceImpl implements CandidateService { protected static final Logger logger = LoggerFactory.getLogger(CandidateServiceImpl.class); private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); @@ -90,27 +92,32 @@ public class CandidateServiceImpl implements CandidateService { } @Override - public Optional<ErrorMessage> validateNonEmptyFileToUpload(InputStream fileToUpload) { + public Optional<ErrorMessage> validateNonEmptyFileToUpload(InputStream fileToUpload, + String fileSuffix) { mdcDataDebugMessage.debugEntryMessage(null); + String errorMessage = + getErrorWithParameters(Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(), + fileSuffix); + if (Objects.isNull(fileToUpload)) { return Optional.of(new ErrorMessage(ErrorLevel.ERROR, - Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); + errorMessage)); } else { try { int available = fileToUpload.available(); if (available == 0) { mdcDataDebugMessage.debugExitMessage(null); return Optional.of(new ErrorMessage(ErrorLevel.ERROR, - Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); + errorMessage)); } } catch (IOException e) { logger.debug(e.getMessage(), e); mdcDataDebugMessage.debugExitMessage(null); return Optional.of(new ErrorMessage(ErrorLevel.ERROR, - Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); + errorMessage)); } } @@ -119,10 +126,12 @@ public class CandidateServiceImpl implements CandidateService { } @Override - public Optional<ErrorMessage> validateRawZipData(byte[] uploadedFileData) { + public Optional<ErrorMessage> validateRawZipData(String fileSuffix, + byte[] uploadedFileData) { if (Objects.isNull(uploadedFileData)) { return Optional.of(new ErrorMessage(ErrorLevel.ERROR, - Messages.NO_ZIP_FILE_WAS_UPLOADED_OR_ZIP_NOT_EXIST.getErrorMessage())); + getErrorWithParameters(Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(), + fileSuffix))); } return Optional.empty(); } |