From 0169e178887d220b88338f72a3eab39065c780e6 Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Thu, 29 Jun 2023 10:42:23 +0100 Subject: Improved code coverage (branches) around multipart file utils - added test - moved wrongly placed test (from MultipartFileUtilSpec to DataMapUtilsSpec) - applied curent conventions to DataMapUtilsSpec Issue-ID: CPS-475 Signed-off-by: ToineSiebelink Change-Id: Ie8dc7f6802bb6ff0a256dc05df73da6af75409f3 --- .../cps/rest/utils/MultipartFileUtilSpec.groovy | 37 +++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'cps-rest/src/test/groovy') diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/utils/MultipartFileUtilSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/utils/MultipartFileUtilSpec.groovy index 572db005b..e9d559c31 100644 --- a/cps-rest/src/test/groovy/org/onap/cps/rest/utils/MultipartFileUtilSpec.groovy +++ b/cps-rest/src/test/groovy/org/onap/cps/rest/utils/MultipartFileUtilSpec.groovy @@ -22,23 +22,12 @@ package org.onap.cps.rest.utils import org.onap.cps.spi.exceptions.CpsException import org.onap.cps.spi.exceptions.ModelValidationException -import org.onap.cps.spi.model.DataNodeBuilder -import org.onap.cps.utils.DataMapUtils import org.springframework.mock.web.MockMultipartFile import org.springframework.web.multipart.MultipartFile import spock.lang.Specification class MultipartFileUtilSpec extends Specification { - def 'Data node without leaves and without children.'() { - given: 'a datanode with no leaves and no children' - def dataNodeWithoutData = new DataNodeBuilder().withXpath('some xpath').build() - when: 'it is converted to a map' - def result = DataMapUtils.toDataMap(dataNodeWithoutData) - then: 'an empty object map is returned' - result.isEmpty() - } - def 'Extract yang resource from yang file.'() { given: 'uploaded yang file' def multipartFile = new MockMultipartFile("file", "filename.yang", "text/plain", "content".getBytes()) @@ -116,6 +105,32 @@ class MultipartFileUtilSpec extends Specification { fileType << ['YANG', 'ZIP'] } + def 'Resource name extension checks, with #scenario.'() { + expect: 'extension check returns expected result' + assert MultipartFileUtil.resourceNameEndsWithExtension(resourceName, '.test') == expectedResult + where: 'following resource names are tested' + scenario | resourceName || expectedResult + 'correct extension'| 'file.test' || true + 'mixed case' | 'file.TesT' || true + 'other extension' | 'file.other' || false + 'no extension' | 'file' || false + 'null' | null || false + } + + def 'Extract resourcename, with #scenario.'() { + expect: 'extension check returns expected result' + assert MultipartFileUtil.extractResourceNameFromPath(path) == expectedResoureName + where: 'following resource names are tested' + scenario | path || expectedResoureName + 'no folder' | 'file.test' || 'file.test' + 'single folder' | 'folder/file.test' || 'file.test' + 'multiple folders' | 'f1/f2/file.test' || 'file.test' + 'with root' | '/f1/f2/file.test' || 'file.test' + 'windows notation' | 'c:\\f2\\file.test' || 'file.test' + 'empty path' | '' || '' + 'null path' | null || '' + } + def multipartZipFileFromResource(resourcePath) { return new MockMultipartFile("file", "TEST.ZIP", "application/zip", getClass().getResource(resourcePath).getBytes()) -- cgit 1.2.3-korg