From 594a37fa17c3b9adfa9825510e0a7128fcf5632d Mon Sep 17 00:00:00 2001 From: talio Date: Wed, 3 Jan 2018 17:49:51 +0200 Subject: fix failing tests fix failing tests in uploadCSARFileTest.java, and changing error messages Change-Id: Ied1384d87551242d3eb48987990a6e8a72b26916 Issue-ID: SDC-874 Signed-off-by: talio --- .../org/openecomp/sdc/common/utils/CommonUtil.java | 36 ------ .../services/impl/CandidateServiceImplTest.java | 6 +- .../upload/csar/UploadCSARFileTest.java | 132 +++++++++------------ .../validation/UploadFileValidationTest.java | 2 +- .../test/resources/vspmanager.csar/SDCmock.csar | Bin 4211 -> 0 bytes .../resources/vspmanager.csar/SDCmockBrokenMF.csar | Bin 4022 -> 0 bytes .../resources/vspmanager.csar/SDCmockFail1.csar | Bin 4372 -> 0 bytes .../resources/vspmanager.csar/SDCmockFail2.csar | Bin 3263 -> 0 bytes .../resources/vspmanager.csar/SDCmockFail3.csar | Bin 4521 -> 0 bytes .../vspmanager.csar/invalidFileInRoot.csar | Bin 0 -> 7335 bytes .../vspmanager.csar/invalidManifestContent.csar | Bin 0 -> 5260 bytes .../missingMainServiceTemplate.csar | Bin 0 -> 4013 bytes .../src/test/resources/vspmanager.csar/notCsar.txt | 0 .../vspmanager.csar/successfulUpload.csar | Bin 0 -> 5681 bytes 14 files changed, 60 insertions(+), 116 deletions(-) delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/common/utils/CommonUtil.java delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar delete mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/invalidFileInRoot.csar create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/invalidManifestContent.csar create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/missingMainServiceTemplate.csar create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/notCsar.txt create mode 100644 openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/successfulUpload.csar (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test') 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> getListPredicate(String substring) { - return error -> isEquals(substring, error); - } - - private boolean isEquals(String substring, List 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> getListPredicate(String substring) { + return error -> isEquals(substring, error); + } + + private boolean isEquals(String substring, List 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 deleted file mode 100644 index f69efd2bb8..0000000000 Binary files a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar and /dev/null differ 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 deleted file mode 100644 index 02593a1d2f..0000000000 Binary files a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar and /dev/null differ 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 deleted file mode 100644 index 5e3ee6f387..0000000000 Binary files a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar and /dev/null differ 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 deleted file mode 100644 index 4874578ad9..0000000000 Binary files a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar and /dev/null differ 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 deleted file mode 100644 index c009a042e4..0000000000 Binary files a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar and /dev/null differ 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 new file mode 100644 index 0000000000..95adb41d22 Binary files /dev/null and b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/invalidFileInRoot.csar differ 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 new file mode 100644 index 0000000000..75ed22187c Binary files /dev/null and b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/invalidManifestContent.csar differ 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 new file mode 100644 index 0000000000..86269fef15 Binary files /dev/null and b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/missingMainServiceTemplate.csar differ 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 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 new file mode 100644 index 0000000000..6a203ddbfd Binary files /dev/null and b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/successfulUpload.csar differ -- cgit 1.2.3-korg