diff options
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager')
12 files changed, 296 insertions, 179 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java index 238dbc08d0..5cf66874c4 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java @@ -16,21 +16,19 @@ package org.openecomp.sdc.vendorsoftwareproduct; +import java.io.IOException; +import java.util.Optional; import org.apache.commons.lang3.tuple.Pair; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; import org.openecomp.sdc.versioning.dao.types.Version; -import java.io.IOException; -import java.io.InputStream; -import java.util.Optional; - public interface OrchestrationTemplateCandidateManager { - UploadFileResponse upload(String vspId, Version version, InputStream heatFileToUpload, - String fileSuffix, String networkPackageName); OrchestrationTemplateActionResponse process(String vspId, Version version); @@ -44,4 +42,6 @@ public interface OrchestrationTemplateCandidateManager { Optional<OrchestrationTemplateCandidateData> getInfo(String vspId, Version version); void abort(String vspId, Version version); + + UploadFileResponse upload(final VspDetails vspDetails, final OnboardPackageInfo onboardPackageInfo); } 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 57f6b672be..d5d5c8045b 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 @@ -16,6 +16,11 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; @@ -34,19 +39,14 @@ import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationT import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUploadFactory; import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationProcessFactory; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage; +import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; import org.openecomp.sdc.versioning.dao.types.Version; -import java.io.IOException; -import java.io.InputStream; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; - public class OrchestrationTemplateCandidateManagerImpl implements OrchestrationTemplateCandidateManager { @@ -61,18 +61,16 @@ public class OrchestrationTemplateCandidateManagerImpl } @Override - public UploadFileResponse upload(String vspId, Version version, InputStream fileToUpload, - String fileSuffix, String networkPackageName) { - OrchestrationTemplateFileHandler orchestrationTemplateFileHandler = - OrchestrationUploadFactory.createOrchestrationTemplateFileHandler(fileSuffix); - - VspDetails vspDetails = getVspDetails(vspId, version); - - UploadFileResponse uploadResponse = orchestrationTemplateFileHandler - .upload(vspDetails, fileToUpload, fileSuffix, networkPackageName, candidateService); - - uploadResponse.setNetworkPackageName(networkPackageName); - return uploadResponse; + public UploadFileResponse upload(final VspDetails vspDetails, + final OnboardPackageInfo onboardPackageInfo) { + final OnboardPackage onboardPackage = onboardPackageInfo.getOnboardPackage(); + final OrchestrationTemplateFileHandler orchestrationTemplateFileHandler = + OrchestrationUploadFactory.createOrchestrationTemplateFileHandler(onboardPackage.getFileExtension()); + + final UploadFileResponse uploadFileResponse = + orchestrationTemplateFileHandler.upload(vspDetails, onboardPackageInfo, candidateService); + uploadFileResponse.setNetworkPackageName(onboardPackage.getFilename()); + return uploadFileResponse; } @Override @@ -153,4 +151,4 @@ public class OrchestrationTemplateCandidateManagerImpl private VspDetails getVspDetails(String vspId, Version version) { return vspInfoDao.get(new VspDetails(vspId, version)); } -} +}
\ No newline at end of file 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 87dd29d095..d87c9c8dbb 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 @@ -20,9 +20,12 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; + +import java.io.ByteArrayInputStream; +import java.util.Optional; import org.apache.commons.collections4.MapUtils; import org.openecomp.core.utilities.file.FileContentHandler; -import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.common.utils.SdcCommon; @@ -32,33 +35,32 @@ import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage; +import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; -import java.io.InputStream; -import java.util.Optional; - -import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; - public abstract class BaseOrchestrationTemplateHandler implements OrchestrationTemplateFileHandler { - protected static final Logger logger = - LoggerFactory.getLogger(BaseOrchestrationTemplateHandler.class); + protected static final Logger logger = LoggerFactory.getLogger(BaseOrchestrationTemplateHandler.class); + @Override - public UploadFileResponse upload(VspDetails vspDetails, InputStream fileToUpload, - String fileSuffix, String networkPackageName, - CandidateService candidateService) { - UploadFileResponse uploadFileResponse = new UploadFileResponse(); + public UploadFileResponse upload(final VspDetails vspDetails, + final OnboardPackageInfo onboardPackageInfo, + final CandidateService candidateService) { + final OnboardPackage onboardPackage = onboardPackageInfo.getOnboardPackage(); + final UploadFileResponse uploadFileResponse = new UploadFileResponse(); uploadFileResponse.setOnboardingType(getHandlerType()); - if (isNotEmptyFileToUpload(fileSuffix, fileToUpload, uploadFileResponse, candidateService)) { + if (isFileFileToUploadEmpty(onboardPackage, uploadFileResponse, candidateService)) { return uploadFileResponse; } - byte[] uploadedFileData = FileUtils.toByteArray(fileToUpload); - if (isInvalidRawZipData(fileSuffix, uploadFileResponse, uploadedFileData, candidateService)) { + final byte[] fileContentByteArray = onboardPackage.getFileContent().array(); + if (isInvalidRawZipData(onboardPackage.getFileExtension(), + uploadFileResponse, fileContentByteArray, candidateService)) { return uploadFileResponse; } - Optional<FileContentHandler> optionalContentMap = - getFileContentMap(uploadFileResponse, uploadedFileData); + final Optional<FileContentHandler> optionalContentMap = + getFileContentMap(uploadFileResponse, fileContentByteArray); if (!optionalContentMap.isPresent()) { logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), getHandlerType().toString())); @@ -71,27 +73,27 @@ public abstract class BaseOrchestrationTemplateHandler implements OrchestrationT if (!MapUtils.isEmpty(uploadFileResponse.getErrors())) { return uploadFileResponse; } - if (updateCandidateData(vspDetails, uploadedFileData, optionalContentMap.get(), fileSuffix, - networkPackageName, candidateService, uploadFileResponse)) { + if (updateCandidateData(vspDetails, onboardPackageInfo, candidateService, uploadFileResponse, + optionalContentMap.get())) { return uploadFileResponse; } return uploadFileResponse; } - protected abstract boolean updateCandidateData(VspDetails vspDetails, - byte[] uploadedFileData, - FileContentHandler contentMap, - String fileSuffix, - String networkPackageName, - CandidateService candidateService, - UploadFileResponse uploadFileResponse); + protected abstract boolean updateCandidateData(final VspDetails vspDetails, + final OnboardPackageInfo onboardPackageInfo, + final CandidateService candidateService, + final UploadFileResponse uploadFileResponse, + final FileContentHandler contentMap); - private boolean isNotEmptyFileToUpload(String fileSuffix, InputStream fileToUpload, - UploadFileResponse uploadFileResponse, - CandidateService candidateService) { + private boolean isFileFileToUploadEmpty(final OnboardPackage onboardPackage, + final UploadFileResponse uploadFileResponse, + final CandidateService candidateService) { + final ByteArrayInputStream fileToUpload = new ByteArrayInputStream( + onboardPackage.getFileContent().array()); Optional<ErrorMessage> errorMessage = - candidateService.validateNonEmptyFileToUpload(fileToUpload, fileSuffix); + candidateService.validateNonEmptyFileToUpload(fileToUpload, onboardPackage.getFileExtension()); 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 669efa6dc5..61d1799aa0 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 @@ -20,6 +20,11 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; + +import java.io.IOException; +import java.util.List; +import java.util.Optional; import org.apache.commons.lang3.tuple.Pair; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; @@ -34,19 +39,13 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.Validator; import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.ValidatorFactory; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage; +import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.List; -import java.util.Optional; - -import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; - public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateHandler implements OrchestrationTemplateFileHandler { - @Override public Optional<FileContentHandler> getFileContentMap(UploadFileResponse uploadFileResponse, byte[] uploadedFileData) { @@ -74,16 +73,20 @@ public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateH } @Override - protected boolean updateCandidateData(VspDetails vspDetails, byte[] uploadedFileData, - FileContentHandler contentMap, - String fileSuffix, String networkPackageName, - CandidateService candidateService, - UploadFileResponse uploadFileResponse) { + protected boolean updateCandidateData(final VspDetails vspDetails, + final OnboardPackageInfo onboardPackageInfo, + final CandidateService candidateService, + final UploadFileResponse uploadFileResponse, + final FileContentHandler contentMap) { try { + final OnboardPackage csarPackage = onboardPackageInfo.getOnboardPackage(); + final OnboardPackage originalOnboardPackage = onboardPackageInfo.getOriginalOnboardPackage(); candidateService.updateCandidateUploadData(vspDetails.getId(), vspDetails.getVersion(), - new OrchestrationTemplateCandidateData(ByteBuffer.wrap(uploadedFileData), "", fileSuffix, - networkPackageName)); - } catch (Exception exception) { + new OrchestrationTemplateCandidateData(csarPackage.getFileContent(), + "", csarPackage.getFileExtension(), + csarPackage.getFilename(), originalOnboardPackage.getFilename(), originalOnboardPackage.getFileExtension(), + originalOnboardPackage.getFileContent())); + } catch (final Exception exception) { logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), getHandlerType().toString()), exception); uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java index 953d88bc4d..2d2f1ae92b 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java @@ -18,14 +18,13 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; -import java.io.InputStream; - @FunctionalInterface public interface OrchestrationTemplateFileHandler { - UploadFileResponse upload(VspDetails vspDetails, InputStream fileToUpload, - String fileSuffix, String networkPackageName, - CandidateService candidateService); + UploadFileResponse upload(final VspDetails vspDetails, + final OnboardPackageInfo onboardPackageInfo, + final CandidateService candidateService); } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java index 7e323928e1..bc4fb668b0 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java @@ -20,6 +20,9 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; + +import java.util.Optional; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.common.errors.Messages; @@ -30,12 +33,10 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCan import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder; +import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage; +import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; -import java.util.Optional; - -import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; - public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHandler implements OrchestrationTemplateFileHandler { @@ -47,22 +48,22 @@ public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHa } @Override - protected boolean updateCandidateData(VspDetails vspDetails, byte[] uploadedFileData, - FileContentHandler contentMap, - String fileSuffix, String networkPackageName, - CandidateService candidateService, - UploadFileResponse uploadFileResponse) { + protected boolean updateCandidateData(final VspDetails vspDetails, + final OnboardPackageInfo onboardPackageInfo, + final CandidateService candidateService, + final UploadFileResponse uploadFileResponse, + final FileContentHandler contentMap) { try { - OrchestrationTemplateCandidateData candidateData = + final OnboardPackage zipPackage = onboardPackageInfo.getOnboardPackage(); + final OrchestrationTemplateCandidateData candidateData = new CandidateEntityBuilder(candidateService) - .buildCandidateEntityFromZip(vspDetails, uploadedFileData, contentMap, + .buildCandidateEntityFromZip(vspDetails, zipPackage.getFileContent().array(), contentMap, uploadFileResponse.getErrors()); - candidateData.setFileSuffix(fileSuffix); - candidateData.setFileName(networkPackageName); - + candidateData.setFileName(zipPackage.getFilename()); + candidateData.setFileSuffix(zipPackage.getFileExtension()); candidateService .updateCandidateUploadData(vspDetails.getId(), vspDetails.getVersion(), candidateData); - } catch (Exception exception) { + } catch (final Exception exception) { logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), getHandlerType().toString()), exception); uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java index a86ce33e47..875d6f2953 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java @@ -16,6 +16,14 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import org.apache.commons.collections4.MapUtils; import org.openecomp.core.impl.AbstractToscaSolConverter; import org.openecomp.core.impl.ToscaConverterImpl; @@ -47,15 +55,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIServiceImp import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTemplateProcessHandler { private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateProcessCsarHandler.class); @@ -133,8 +132,13 @@ public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTem ETSIService etsiService = new ETSIServiceImpl(); ToscaServiceModel toscaServiceModel; if (etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)) { - fileContentHandler.addFile(SDC_ONBOARDED_PACKAGE_DIR + candidateData.getFileName() + - EXT_SEPARATOR + candidateData.getFileSuffix(), candidateData.getContentData().array()); + if (OnboardingTypesEnum.CSAR.toString().equalsIgnoreCase(candidateData.getFileSuffix())) { + fileContentHandler.addFile(SDC_ONBOARDED_PACKAGE_DIR + candidateData.getOriginalFileName() + + EXT_SEPARATOR + candidateData.getOriginalFileSuffix(), candidateData.getOriginalFileContentData().array()); + } else { + fileContentHandler.addFile(SDC_ONBOARDED_PACKAGE_DIR + candidateData.getFileName() + + EXT_SEPARATOR + candidateData.getFileSuffix(), candidateData.getContentData().array()); + } final ResourceTypeEnum resourceType = etsiService.getResourceType(fileContentHandler); toscaServiceModel = instantiateToscaConverterFor(resourceType).convert(fileContentHandler); } else { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackage.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackage.java new file mode 100644 index 0000000000..b8ef598d65 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackage.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.types; + +import java.nio.ByteBuffer; +import lombok.Getter; + +@Getter +public class OnboardPackage { + + private final String filename; + private final String fileExtension; + private final ByteBuffer fileContent; + + public OnboardPackage(final String filename, final String fileExtension, final ByteBuffer fileContent) { + this.filename = filename; + this.fileExtension = fileExtension; + this.fileContent = fileContent; + } + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackageInfo.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackageInfo.java new file mode 100644 index 0000000000..308db035db --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackageInfo.java @@ -0,0 +1,46 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.types; + +import java.nio.ByteBuffer; +import lombok.Getter; + +@Getter +public class OnboardPackageInfo { + + private final OnboardPackage originalOnboardPackage; + private final OnboardPackage onboardPackage; + + public OnboardPackageInfo(final String filename, + final String fileExtension, + final ByteBuffer fileContent, + final OnboardPackage onboardPackage) { + originalOnboardPackage = new OnboardPackage(filename, fileExtension, fileContent); + this.onboardPackage = onboardPackage; + } + + public OnboardPackageInfo(final String filename, + final String fileExtension, + final ByteBuffer fileContent) { + originalOnboardPackage = new OnboardPackage(filename, fileExtension, fileContent); + this.onboardPackage = originalOnboardPackage; + } + +}
\ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java index ee4b2fa26c..b922da9b46 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java @@ -21,62 +21,50 @@ package org.openecomp.sdc.vendorsoftwareproduct; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.List; +import java.util.Objects; import org.apache.commons.collections4.MapUtils; +import org.apache.commons.io.IOUtils; import org.junit.Assert; import org.junit.Before; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.openecomp.core.model.dao.ServiceModelDao; -import org.openecomp.core.model.types.ServiceElement; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.core.validation.util.MessageContainerUtil; -import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.datatypes.error.ErrorLevel; -import org.openecomp.sdc.healing.api.HealingManager; -import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData; import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService; -import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; -import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; import org.openecomp.sdc.vendorsoftwareproduct.tree.UploadFileTest; +import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire; import org.openecomp.sdc.versioning.dao.types.Version; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import java.util.Objects; - public class QuestionnaireDataServiceTest { + private static final Logger LOGGER = LoggerFactory.getLogger(QuestionnaireDataServiceTest.class); + public static final Version VERSION = new Version(0, 1); private QuestionnaireDataService questionnaireDataService;// = new QuestionnaireDataServiceImpl(); - @Mock - private CandidateService candidateServiceMock; - @Mock - private HealingManager healingManagerMock; - @Mock - private CompositionDataExtractor compositionDataExtractorMock; - @Mock - private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock; - @Mock - private CompositionEntityDataManager compositionEntityDataManagerMock; - - @Captor - private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg; - @InjectMocks private OrchestrationTemplateCandidateManagerImpl candidateManager; private UploadFileTest uploadFileTest = new UploadFileTest(); + private OnboardPackageInfo onboardPackageInfo; private static String vspId; private static Version vspActiveVersion; private static final String USER1 = "vspTestUser1"; + private static final VspDetails vspDetails = new VspDetails(vspId, VERSION); + private static final String CSAR = "csar"; + private static final String ZIP = "zip"; @Before public void setUp() throws Exception { @@ -101,38 +89,39 @@ public class QuestionnaireDataServiceTest { // TODO: 3/15/2017 fix and enable //@Test public void testQuestionnaireDataAfterIllegalUpload() throws IOException { try (InputStream zipInputStream = uploadFileTest.getZipInputStream("/missingYml")) { + onboardPackageInfo = new OnboardPackageInfo("missingYml", CSAR, convertFileInputStream(zipInputStream)); UploadFileResponse uploadFileResponse = - candidateManager.upload(vspId, VERSION, zipInputStream, "zip", "missingYml"); + candidateManager.upload(vspDetails, onboardPackageInfo); } InformationArtifactData informationArtifactData = questionnaireDataService .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion); } - private InformationArtifactData uploadFileAndValidateInformationArtifactData(String filePath, - int listSizeToCheck) - throws IOException { + private InformationArtifactData uploadFileAndValidateInformationArtifactData(final String filePath, + final int listSizeToCheck) + throws IOException { - try (InputStream zipInputStream = uploadFileTest.getZipInputStream(filePath)) { - UploadFileResponse uploadFileResponse = - candidateManager.upload(vspId, VERSION, zipInputStream, "zip", "file"); + try (final InputStream zipInputStream = uploadFileTest.getZipInputStream(filePath)) { + onboardPackageInfo = new OnboardPackageInfo("file", OnboardingTypesEnum.CSAR.toString(), + convertFileInputStream(zipInputStream)); + final UploadFileResponse uploadFileResponse = candidateManager.upload(vspDetails, onboardPackageInfo); candidateManager.process(vspId, VERSION); Assert.assertTrue(MapUtils.isEmpty( MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors()))); } - InformationArtifactData informationArtifactData = questionnaireDataService + final InformationArtifactData informationArtifactData = questionnaireDataService .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion); Assert.assertNotNull(informationArtifactData); - List<ComponentQuestionnaire> componentQuestionnaireList = + final List<ComponentQuestionnaire> componentQuestionnaireList = informationArtifactData.getComponentQuestionnaires(); Assert.assertEquals(componentQuestionnaireList.size(), listSizeToCheck); return informationArtifactData; } - private void assertQuestionnaireValuesAreAsExpected( InformationArtifactData informationArtifactData, boolean condition) { Assert.assertEquals( @@ -143,4 +132,14 @@ public class QuestionnaireDataServiceTest { condition); } + private ByteBuffer convertFileInputStream(final InputStream fileInputStream) { + byte[] fileContent = new byte[0]; + try { + fileContent = IOUtils.toByteArray(fileInputStream); + } catch (final IOException e) { + LOGGER.error(String.format("Could not convert %s into byte[]", fileInputStream), e); + } + return ByteBuffer.wrap(fileContent); + } + } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java index c21358519a..8081184f68 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java @@ -31,8 +31,9 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.ByteBuffer; import java.util.zip.ZipOutputStream; - +import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -43,6 +44,8 @@ import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.healing.api.HealingManager; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; @@ -52,11 +55,14 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon; import org.openecomp.sdc.versioning.dao.types.Version; public class UploadFileTest { + private static final Logger LOGGER = LoggerFactory.getLogger(UploadFileTest.class); + private static final String USER1 = "vspTestUser1"; public static final Version VERSION01 = new Version(0, 1); @@ -76,15 +82,15 @@ public class UploadFileTest { @Mock private VendorSoftwareProductInfoDao vspInfoDaoMock; + private OnboardPackageInfo onboardPackageInfo; + @InjectMocks private OrchestrationTemplateCandidateManagerImpl candidateManager; - private static String vlm1Id; - public static String id001 = null; - public static String id002 = null; - - public static Version activeVersion002 = null; + public static String id001 = "dummyId"; + public static Version activeVersion002 = new Version(1, 0); + private final VspDetails vspDetails = new VspDetails(id001, activeVersion002); @Before public void setUp() throws Exception { @@ -92,17 +98,20 @@ public class UploadFileTest { } @Test - public void testUploadFile() { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + public void testUploadFile() throws IOException { doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - candidateManager.upload(id001, activeVersion002, getZipInputStream("/legalUpload"), - OnboardingTypesEnum.ZIP.toString(), "legalUpload"); - } + try (final InputStream inputStream = getZipInputStream("/legalUpload")) { + onboardPackageInfo = new OnboardPackageInfo("legalUpload", OnboardingTypesEnum.ZIP.toString(), + convertFileInputStream(inputStream)); + candidateManager.upload(vspDetails, onboardPackageInfo); + } + } private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { - UploadFileResponse uploadFileResponse = candidateManager.upload(vspId, activeVersion002, - upload, OnboardingTypesEnum.ZIP.toString(), "file"); + onboardPackageInfo = new OnboardPackageInfo("file", OnboardingTypesEnum.ZIP.toString(), + convertFileInputStream(upload)); + final UploadFileResponse uploadFileResponse = candidateManager.upload(vspDetails, onboardPackageInfo); assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.ZIP); OrchestrationTemplateEntity uploadData = orchestrationTemplateDataDaoMock.get(vspId, version); @@ -121,5 +130,14 @@ public class UploadFileTest { return new ByteArrayInputStream(baos.toByteArray()); } + private ByteBuffer convertFileInputStream(final InputStream fileInputStream) { + byte[] fileContent = new byte[0]; + try { + fileContent = IOUtils.toByteArray(fileInputStream); + } catch (final IOException e) { + LOGGER.error(String.format("Could not convert %s into byte[]", fileInputStream), e); + } + return ByteBuffer.wrap(fileContent); + } } 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 b772c69f4a..77e519c502 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 @@ -22,33 +22,37 @@ import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.ByteBuffer; import java.util.List; import java.util.function.Predicate; - +import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.Spy; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl; import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl; import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.ManifestCreatorNamingConventionImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.versioning.dao.types.Version; public class UploadCSARFileTest { - public static final Version VERSION01 = new Version("0.1"); + private static final Logger LOGGER = LoggerFactory.getLogger(UploadCSARFileTest.class); @Spy private CandidateServiceImpl candidateService; @@ -62,11 +66,12 @@ public class UploadCSARFileTest { @InjectMocks private OrchestrationTemplateCandidateManagerImpl candidateManager; + private OnboardPackageInfo onboardPackageInfo; + private final VspDetails vspDetails = new VspDetails(id001, activeVersion002); 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"; @Before @@ -79,7 +84,6 @@ public class UploadCSARFileTest { @Test public void testSuccessfulUploadFile() throws Exception { - VspDetails vspDetails = new VspDetails(id001, activeVersion002); doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); testCsarUpload("successfulUpload.csar", 0); @@ -87,7 +91,6 @@ public class UploadCSARFileTest { @Test public void testIllegalUploadInvalidFileInRoot() throws Exception { - VspDetails vspDetails = new VspDetails(id001, activeVersion002); doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); UploadFileResponse response = testCsarUpload("invalidFileInRoot.csar", 1); @@ -97,7 +100,6 @@ public class UploadCSARFileTest { @Test public void testIllegalUploadMissingMainServiceTemplate() throws Exception { - VspDetails vspDetails = new VspDetails(id001, activeVersion002); doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); UploadFileResponse response = testCsarUpload("missingMainServiceTemplate.csar", 1); @@ -107,7 +109,6 @@ public class UploadCSARFileTest { @Test public void testUploadFileIsNotZip() throws Exception { - VspDetails vspDetails = new VspDetails(id001, activeVersion002); doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); UploadFileResponse response = testCsarUpload("notCsar.txt", 1); @@ -117,26 +118,24 @@ public class UploadCSARFileTest { @Test public void testUploadFileIsEmpty() throws Exception { - 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(1, uploadFileResponse.getErrors().size()); - } + onboardPackageInfo = new OnboardPackageInfo("file", OnboardingTypesEnum.CSAR.toString(), + ByteBuffer.wrap(new byte[]{})); + UploadFileResponse uploadFileResponse = candidateManager.upload(vspDetails, onboardPackageInfo); + assertEquals(1, uploadFileResponse.getErrors().size()); } @Test public void testInvalidManifestContent() throws Exception { - VspDetails vspDetails = new VspDetails(id001, activeVersion002); - doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - try (InputStream is = getClass() + try (InputStream inputStream = getClass() .getResourceAsStream(BASE_DIR + "/invalidManifestContent.csar")) { + onboardPackageInfo = new OnboardPackageInfo("invalidManifestContent", + OnboardingTypesEnum.CSAR.toString(), convertFileInputStream(inputStream)); UploadFileResponse response = - candidateManager.upload(id001, activeVersion002, is, "csar", "invalidManifestContent"); + candidateManager.upload(vspDetails, onboardPackageInfo); assertEquals(1, response.getErrors().size()); assertEquals(response.getErrors().values().iterator().next().get(0).getMessage(), "Manifest " + @@ -153,17 +152,27 @@ public class UploadCSARFileTest { return error.iterator().next().getMessage().contains(substring); } - private UploadFileResponse testCsarUpload(String csarFileName, int expectedErrorsNumber) - throws IOException { + private UploadFileResponse testCsarUpload(final String csarFileName, + final int expectedErrorsNumber) throws IOException { UploadFileResponse uploadFileResponse; - try (InputStream is = getClass() + try (final InputStream inputStream = getClass() .getResourceAsStream(BASE_DIR + File.separator + csarFileName)) { - uploadFileResponse = - candidateManager.upload(id001, activeVersion002, is, CSAR, csarFileName); + onboardPackageInfo = new OnboardPackageInfo(csarFileName, OnboardingTypesEnum.CSAR.toString(), + convertFileInputStream(inputStream)); + uploadFileResponse = candidateManager.upload(vspDetails, onboardPackageInfo); assertEquals(expectedErrorsNumber, uploadFileResponse.getErrors().size()); } return uploadFileResponse; } + private ByteBuffer convertFileInputStream(final InputStream fileInputStream) { + byte[] fileContent = new byte[0]; + try { + fileContent = IOUtils.toByteArray(fileInputStream); + } catch (final IOException e) { + LOGGER.error(String.format("Could not convert %s into byte[]", fileInputStream), e); + } + return ByteBuffer.wrap(fileContent); + } } |