X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=inline;f=rapp-manager-models%2Fsrc%2Ftest%2Fjava%2Fcom%2Foransc%2Frappmanager%2Fmodels%2Fcsar%2Fvalidator%2FRappValidationHandlerTest.java;h=9487739da4957f6f07bacbf224f4c9d1bb5f3f57;hb=HEAD;hp=21664196ae5da6ed16c21de831b4292a5ef3c59a;hpb=7e301b523d66508f8493f6873e36f0d60e8caaf4;p=nonrtric%2Fplt%2Frappmanager.git diff --git a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/RappValidationHandlerTest.java b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/RappValidationHandlerTest.java deleted file mode 100755 index 2166419..0000000 --- a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/RappValidationHandlerTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * ============LICENSE_START====================================================================== - * Copyright (C) 2024 OpenInfra Foundation Europe. 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 com.oransc.rappmanager.models.csar.validator; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.oransc.rappmanager.models.BeanTestConfiguration; -import com.oransc.rappmanager.models.cache.RappCacheService; -import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler; -import com.oransc.rappmanager.models.exception.RappValidationException; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.stream.Stream; -import org.apache.http.entity.ContentType; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.HttpStatus; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.web.multipart.MultipartFile; - -@SpringBootTest -@ContextConfiguration(classes = {BeanTestConfiguration.class, RappValidationHandler.class, NamingValidator.class, - FileExistenceValidator.class, ArtifactDefinitionValidator.class, AsdDescriptorValidator.class, - RappValidationUtils.class, RappCsarConfigurationHandler.class, ObjectMapper.class, RappCacheService.class}) -class RappValidationHandlerTest { - - @Autowired - RappValidationHandler rappValidationHandler; - String validCsarFileLocation = "src/test/resources/"; - private final String validRappFile = "valid-rapp-package.csar"; - - @Test - void testCsarPackageValidationSuccess() throws IOException { - String rappCsarPath = validCsarFileLocation + File.separator + validRappFile; - MultipartFile multipartFile = - new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(), - new FileInputStream(rappCsarPath)); - assertEquals(Boolean.TRUE, rappValidationHandler.isValidRappPackage(multipartFile)); - } - - @ParameterizedTest - @MethodSource("getInvalidCsarPackage") - void testCsarPackageValidationFailure(MultipartFile multipartFile, String errorMessage) { - RappValidationException exception = assertThrows(RappValidationException.class, - () -> rappValidationHandler.isValidRappPackage(multipartFile)); - assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode()); - assertEquals(errorMessage, exception.getMessage()); - } - - private static Stream getInvalidCsarPackage() throws IOException { - String validCsarFileLocation = "src/test/resources"; - String errorMsgMissingAcmComposition = "rApp package missing a file Files/Acm/definition/compositions.json"; - String rappCsarPath = validCsarFileLocation + File.separator + "invalid-rapp-package.csar"; - MultipartFile multipartFile = - new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(), - new FileInputStream(rappCsarPath)); - String rappCsarPathNoTosca = validCsarFileLocation + File.separator + "invalid-rapp-package-no-tosca.csar"; - MultipartFile multipartFileNoTosca = new MockMultipartFile(rappCsarPathNoTosca, rappCsarPathNoTosca, - ContentType.MULTIPART_FORM_DATA.getMimeType(), new FileInputStream(rappCsarPathNoTosca)); - String rappCsarPathNoAsdYaml = validCsarFileLocation + File.separator + "invalid-rapp-package-no-asd-yaml.csar"; - MultipartFile multipartFileNoAsdYaml = new MockMultipartFile(rappCsarPathNoAsdYaml, rappCsarPathNoAsdYaml, - ContentType.MULTIPART_FORM_DATA.getMimeType(), new FileInputStream(rappCsarPathNoAsdYaml)); - String rappCsarPathMissingArtifact = - validCsarFileLocation + File.separator + "invalid-rapp-package-missing-artifact.csar"; - MultipartFile multipartFileMissingArtifact = - new MockMultipartFile(rappCsarPathMissingArtifact, rappCsarPathMissingArtifact, - ContentType.MULTIPART_FORM_DATA.getMimeType(), - new FileInputStream(rappCsarPathMissingArtifact)); - String rappCsarPathNoComposition = - validCsarFileLocation + File.separator + "invalid-rapp-package-no-acm-composition.csar"; - MultipartFile multipartFileNoComposition = - new MockMultipartFile(rappCsarPathNoComposition, rappCsarPathNoComposition, - ContentType.MULTIPART_FORM_DATA.getMimeType(), new FileInputStream(rappCsarPathNoComposition)); - return Stream.of(Arguments.of(multipartFile, errorMsgMissingAcmComposition), - Arguments.of(multipartFileNoTosca, "rApp package missing a file TOSCA-Metadata/TOSCA.meta"), - Arguments.of(multipartFileNoAsdYaml, "rApp package missing a file Definitions/asd.yaml"), - Arguments.of(multipartFileMissingArtifact, - "rApp package missing a file Artifacts/Deployment/HELM/orufhrecovery-1.0.0.tgz"), - Arguments.of(multipartFileNoComposition, errorMsgMissingAcmComposition)); - } - - @Test - void testCsarPackageValidationFailureWithoutOrginalName() { - MultipartFile multipartFile = mock(MultipartFile.class); - RappValidationException exception = assertThrows(RappValidationException.class, - () -> rappValidationHandler.isValidRappPackage(multipartFile)); - assertEquals(HttpStatus.BAD_REQUEST, exception.getStatusCode()); - assertEquals("rApp package name should end with .csar", exception.getMessage()); - } -}