summaryrefslogtreecommitdiffstats
path: root/cps-rest/src/test
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2023-06-29 10:42:23 +0100
committerToineSiebelink <toine.siebelink@est.tech>2023-06-29 10:47:38 +0100
commit0169e178887d220b88338f72a3eab39065c780e6 (patch)
treeb1d32ecf8d1efa0e047a0d5f864121a85baa8c03 /cps-rest/src/test
parent300860865a8dd616083543f7c88cf2c8233c2701 (diff)
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 <toine.siebelink@est.tech> Change-Id: Ie8dc7f6802bb6ff0a256dc05df73da6af75409f3
Diffstat (limited to 'cps-rest/src/test')
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/utils/MultipartFileUtilSpec.groovy37
1 files changed, 26 insertions, 11 deletions
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 572db005b3..e9d559c31d 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())