Improved code coverage (branches) around multipart file utils
[cps.git] / cps-rest / src / test / groovy / org / onap / cps / rest / utils / MultipartFileUtilSpec.groovy
index 572db00..e9d559c 100644 (file)
@@ -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())