aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy')
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy43
1 files changed, 11 insertions, 32 deletions
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy
index b0205705a..67dce1daf 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy
@@ -30,33 +30,18 @@ import org.onap.cps.spi.exceptions.SchemaSetInUseException
import org.onap.cps.spi.model.Anchor
import org.onap.cps.spi.model.ExtendedModuleReference
import org.onap.cps.spi.model.ModuleReference
-import org.spockframework.spring.SpringBean
-import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.test.context.SpringBootTest
-import org.springframework.cache.CacheManager
-import org.springframework.cache.annotation.EnableCaching
-import org.springframework.cache.caffeine.CaffeineCacheManager
-import org.springframework.test.context.ContextConfiguration
+import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
import spock.lang.Specification
import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED
import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED
-@SpringBootTest
-@EnableCaching
-@ContextConfiguration(classes = [YangTextSchemaSourceSetCache, CpsModuleServiceImpl])
class CpsModuleServiceImplSpec extends Specification {
- @SpringBean
- CpsModulePersistenceService mockModuleStoreService = Mock()
+ def mockModuleStoreService = Mock(CpsModulePersistenceService)
+ def mockCpsAdminService = Mock(CpsAdminService)
+ def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache)
- @SpringBean
- CpsAdminService mockCpsAdminService = Mock()
-
- @SpringBean
- CacheManager cacheManager = new CaffeineCacheManager("yangSchema")
-
- @Autowired
- CpsModuleServiceImpl objectUnderTest
+ def objectUnderTest = new CpsModuleServiceImpl(mockModuleStoreService, mockYangTextSchemaSourceSetCache, mockCpsAdminService)
def 'Create schema set.'() {
given: 'Valid yang resource as name-to-content map'
@@ -90,7 +75,8 @@ class CpsModuleServiceImplSpec extends Specification {
def 'Get schema set by name and dataspace.'() {
given: 'an already present schema set'
def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang')
- mockModuleStoreService.getYangSchemaResources('someDataspace', 'someSchemaSet') >> yangResourcesNameToContentMap
+ and: 'yang resource cache returns the expected schema set'
+ mockYangTextSchemaSourceSetCache.get('someDataspace', 'someSchemaSet') >> YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap)
when: 'get schema set method is invoked'
def result = objectUnderTest.getSchemaSet('someDataspace', 'someSchemaSet')
then: 'the correct schema set is returned'
@@ -99,17 +85,6 @@ class CpsModuleServiceImplSpec extends Specification {
result.getExtendedModuleReferences().contains(new ExtendedModuleReference('stores', 'org:onap:ccsdk:sample', '2020-09-15'))
}
- def 'Schema set caching.'() {
- given: 'an schema set'
- def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang')
- when: 'get schema set method is invoked twice'
- 2.times {
- objectUnderTest.getSchemaSet('someDataspace', 'someSchemaSet')
- }
- then: 'the persistency service called only once'
- 1 * mockModuleStoreService.getYangSchemaResources('someDataspace', 'someSchemaSet') >> yangResourcesNameToContentMap
- }
-
def 'Delete schema-set when cascade is allowed.'() {
given: '#numberOfAnchors anchors are associated with schemaset'
def associatedAnchors = createAnchors(numberOfAnchors)
@@ -120,6 +95,8 @@ class CpsModuleServiceImplSpec extends Specification {
numberOfAnchors * mockCpsAdminService.deleteAnchor('my-dataspace', _)
and: 'persistence service method is invoked with same parameters'
1 * mockModuleStoreService.deleteSchemaSet('my-dataspace', 'my-schemaset')
+ and: 'schema set will be removed from the cache'
+ 1 * mockYangTextSchemaSourceSetCache.removeFromCache('my-dataspace', 'my-schemaset')
and: 'orphan yang resources are deleted'
1 * mockModuleStoreService.deleteUnusedYangResourceModules()
where: 'following parameters are used'
@@ -135,6 +112,8 @@ class CpsModuleServiceImplSpec extends Specification {
0 * mockCpsAdminService.deleteAnchor(_, _)
and: 'persistence service method is invoked with same parameters'
1 * mockModuleStoreService.deleteSchemaSet('my-dataspace', 'my-schemaset')
+ and: 'schema set will be removed from the cache'
+ 1 * mockYangTextSchemaSourceSetCache.removeFromCache('my-dataspace', 'my-schemaset')
and: 'orphan yang resources are deleted'
1 * mockModuleStoreService.deleteUnusedYangResourceModules()
}