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%2FFileExistenceValidatorTest.java;h=22ca62c0ebf7c3669fe34c76ddb43f43f16531b1;hb=HEAD;hp=2b6e369b7b25b2020e5f1ac5ca1efa73151eb26a;hpb=4b54b7ed29e736b2f80878bab90acaedb4e7117e;p=nonrtric%2Fplt%2Frappmanager.git diff --git a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/FileExistenceValidatorTest.java b/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/FileExistenceValidatorTest.java deleted file mode 100755 index 2b6e369..0000000 --- a/rapp-manager-models/src/test/java/com/oransc/rappmanager/models/csar/validator/FileExistenceValidatorTest.java +++ /dev/null @@ -1,87 +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.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import com.fasterxml.jackson.databind.ObjectMapper; -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 org.apache.http.entity.ContentType; -import org.junit.jupiter.api.Test; -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 = {FileExistenceValidator.class, RappValidationUtils.class, ObjectMapper.class, - RappCsarConfigurationHandler.class}) -class FileExistenceValidatorTest { - - @Autowired - FileExistenceValidator fileExistenceValidator; - String validCsarFileLocation = "src/test/resources/"; - String validRappFile = "valid-rapp-package.csar"; - String invalidRappFile = "invalid-rapp-package.csar"; - String invalidRappFileNoTosca = "invalid-rapp-package-no-tosca.csar"; - - @Test - void testFileExistenceValidationSuccess() throws IOException { - String rappCsarPath = validCsarFileLocation + File.separator + validRappFile; - MultipartFile multipartFile = - new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(), - new FileInputStream(rappCsarPath)); - assertDoesNotThrow(() -> fileExistenceValidator.validate(multipartFile, null)); - } - - @Test - void testFileExistenceNoCompositionValidation() throws IOException { - String rappCsarPath = validCsarFileLocation + File.separator + invalidRappFile; - MultipartFile multipartFile = - new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(), - new FileInputStream(rappCsarPath)); - RappValidationException rappValidationException = - assertThrows(RappValidationException.class, () -> fileExistenceValidator.validate(multipartFile, null)); - assertEquals(HttpStatus.BAD_REQUEST, rappValidationException.getStatusCode()); - assertEquals("rApp package missing a file Files/Acm/definition/compositions.json", - rappValidationException.getMessage()); - } - - @Test - void testFileExistenceNoToscaValidation() throws IOException { - String rappCsarPath = validCsarFileLocation + File.separator + invalidRappFileNoTosca; - MultipartFile multipartFile = - new MockMultipartFile(rappCsarPath, rappCsarPath, ContentType.MULTIPART_FORM_DATA.getMimeType(), - new FileInputStream(rappCsarPath)); - RappValidationException rappValidationException = - assertThrows(RappValidationException.class, () -> fileExistenceValidator.validate(multipartFile, null)); - assertEquals(HttpStatus.BAD_REQUEST, rappValidationException.getStatusCode()); - assertEquals("rApp package missing a file TOSCA-Metadata/TOSCA.meta", rappValidationException.getMessage()); - } -}