diff options
author | 2018-01-03 17:49:51 +0200 | |
---|---|---|
committer | 2018-01-04 09:25:28 +0000 | |
commit | 594a37fa17c3b9adfa9825510e0a7128fcf5632d (patch) | |
tree | 96306be375076989ed6d758759ccfa95abe5824e /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp | |
parent | b85fc88176d7cce7c9a7c7955cafe5f9f8bf4644 (diff) |
fix failing tests
fix failing tests in uploadCSARFileTest.java, and changing error messages
Change-Id: Ied1384d87551242d3eb48987990a6e8a72b26916
Issue-ID: SDC-874
Signed-off-by: talio <tali.orenbach@amdocs.com>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp')
4 files changed, 60 insertions, 116 deletions
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") |