CPS Validator Changes
[cps.git] / cps-service / src / test / groovy / org / onap / cps / api / impl / YangTextSchemaSourceSetCacheSpec.groovy
index 06c675a..a9f50ee 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * ============LICENSE_START=======================================================
+ *  ============LICENSE_START=======================================================
  *  Copyright (C) 2022 Bell Canada
  *  Modifications Copyright (C) 2022 Nordix Foundation
  *  ================================================================================
@@ -23,7 +23,6 @@ package org.onap.cps.api.impl
 
 import org.onap.cps.TestUtils
 import org.onap.cps.spi.CpsModulePersistenceService
-import org.onap.cps.spi.exceptions.DataValidationException
 import org.onap.cps.yang.YangTextSchemaSourceSet
 import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
 import org.spockframework.spring.SpringBean
@@ -35,6 +34,8 @@ import org.springframework.cache.annotation.EnableCaching
 import org.springframework.cache.caffeine.CaffeineCacheManager
 import org.springframework.test.context.ContextConfiguration
 import spock.lang.Specification
+import org.onap.cps.spi.utils.CpsValidator
+
 
 @SpringBootTest
 @EnableCaching
@@ -44,6 +45,9 @@ class YangTextSchemaSourceSetCacheSpec extends Specification {
     @SpringBean
     CpsModulePersistenceService mockModuleStoreService = Mock()
 
+    @SpringBean
+    CpsValidator mockCpsValidator = Mock(CpsValidator)
+
     @Autowired
     YangTextSchemaSourceSetCache objectUnderTest
 
@@ -74,6 +78,8 @@ class YangTextSchemaSourceSetCacheSpec extends Specification {
             assert cachedValue.getModuleReferences() == expectedYangTextSchemaSourceSet.getModuleReferences()
         and: 'the response is as expected'
             assert result.getModuleReferences() == expectedYangTextSchemaSourceSet.getModuleReferences()
+        and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
+            1 * mockCpsValidator.validateNameCharacters('my-dataspace', 'my-schemaset')
     }
 
     def 'Cache Hit: Respond from cache'() {
@@ -90,20 +96,6 @@ class YangTextSchemaSourceSetCacheSpec extends Specification {
             0 * mockModuleStoreService.getYangSchemaResources(_, _)
     }
 
-    def 'Cache Hit: with invalid #scenario'() {
-        when: 'schema-set information is asked'
-            objectUnderTest.get(dataspaceName, schemaSetName)
-        then: 'an data validation exception is thrown'
-            thrown(DataValidationException)
-        and: 'module persistence is not invoked'
-            0 * mockModuleStoreService.getYangSchemaResources(_, _)
-        where: 'the following parameters are used'
-            scenario                        | dataspaceName                 | schemaSetName
-            'dataspace name'                | 'dataspace names with spaces' | 'schemaSetName'
-            'schema set name'               | 'dataspaceName'               | 'schema set name with spaces'
-            'dataspace and schema set name' | 'dataspace name with spaces'  | 'schema set name with spaces'
-    }
-
     def 'Cache Update: when no data exist in the cache'() {
         given: 'a schema set exists'
             def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang')
@@ -113,23 +105,8 @@ class YangTextSchemaSourceSetCacheSpec extends Specification {
         then: 'cached value is same as expected'
             def cachedValue = getCachedValue('my-dataspace', 'my-schemaset')
             cachedValue.getModuleReferences() == yangTextSchemaSourceSet.getModuleReferences()
-    }
-
-    def 'Cache Update: with invalid #scenario'() {
-        given: 'a schema set exists'
-            def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang')
-            def yangTextSchemaSourceSet = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)
-        when: 'schema-set information is asked'
-            objectUnderTest.updateCache(dataspaceName, schemaSetName, yangTextSchemaSourceSet)
-        then: 'an data validation exception is thrown'
-            thrown(DataValidationException)
-        and: 'module persistence is not invoked'
-            0 * mockModuleStoreService.getYangSchemaResources(_, _)
-        where: 'the following parameters are used'
-            scenario                        | dataspaceName                 | schemaSetName
-            'dataspace name'                | 'dataspace names with spaces' | 'schemaSetName'
-            'schema set name'               | 'dataspaceName'               | 'schema set name with spaces'
-            'dataspace and schema set name' | 'dataspace name with spaces'  | 'schema set name with spaces'
+        and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
+            1 * mockCpsValidator.validateNameCharacters('my-dataspace', 'my-schemaset')
     }
 
     def 'Cache Evict:with invalid #scenario'() {
@@ -143,18 +120,8 @@ class YangTextSchemaSourceSetCacheSpec extends Specification {
             objectUnderTest.removeFromCache('my-dataspace', 'my-schemaset')
         then: 'cached does not have value'
             assert getCachedValue('my-dataspace', 'my-schemaset') == null
-    }
-
-    def 'Cache Evict: remove when exist'() {
-        when: 'cache is evicted for schemaset'
-            objectUnderTest.removeFromCache(dataspaceName, schemaSetName)
-        then: 'an data validation exception is thrown'
-            thrown(DataValidationException)
-        where: 'the following parameters are used'
-            scenario                        | dataspaceName                 | schemaSetName
-            'dataspace name'                | 'dataspace names with spaces' | 'schemaSetName'
-            'schema set name'               | 'dataspaceName'               | 'schema set name with spaces'
-            'dataspace and schema set name' | 'dataspace name with spaces'  | 'schema set name with spaces'
+        and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
+            1 * mockCpsValidator.validateNameCharacters('my-dataspace', 'my-schemaset')
     }
 
     def 'Cache Evict: remove when does not exist'() {
@@ -164,6 +131,8 @@ class YangTextSchemaSourceSetCacheSpec extends Specification {
             objectUnderTest.removeFromCache('my-dataspace', 'my-schemaset')
         then: 'cached does not have value'
             assert getCachedValue('my-dataspace', 'my-schemaset') == null
+        and: 'the CpsValidator is called on the dataspaceName and schemaSetName'
+            1 * mockCpsValidator.validateNameCharacters('my-dataspace', 'my-schemaset')
     }
 
     def getCachedValue(dataSpace, schemaSet) {