summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test
diff options
context:
space:
mode:
authoraribeiro <anderson.ribeiro@est.tech>2019-09-03 08:37:55 +0000
committerAvi Gaffa <avi.gaffa@amdocs.com>2019-09-03 13:38:08 +0000
commitccc1f364baea63733e93c6f4eb26ea97eeb77960 (patch)
tree2ce098bd1d4a28e611dd91f2eea6605a51cbf463 /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test
parente79935cbaa180a86eea2c7631de14c16bef9b3d8 (diff)
Onboard Package Handling
Retain the original onboarded package when it comes in zip/csar format. Issue-ID: SDC-2510 Change-Id: Ie293db25eca8872be26ffc8475b25ccace1aab6f Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java77
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java44
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java57
3 files changed, 102 insertions, 76 deletions
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);
+ }
}