diff options
author | Claudio David Gasparini <claudio.gasparini@pantheon.tech> | 2021-01-13 19:12:25 +0100 |
---|---|---|
committer | Claudio David Gasparini <claudio.gasparini@pantheon.tech> | 2021-01-21 18:52:55 +0100 |
commit | 1b8a4dd237077944df7bef5fa04c412da01029f0 (patch) | |
tree | 5b3d9f62011f82b0d78c9a43a1363de635af21f8 /cps-service/src/test/groovy | |
parent | cd9f368b1f3c5e25e17e21649e582d84a909ac79 (diff) |
Introduce caffeine cache
Issue-ID: CPS-163
Signed-off-by: Claudio David Gasparini <claudio.gasparini@pantheon.tech>
Change-Id: Iff9b831c2d895d82aff419f60a8dd86a38b545d0
Diffstat (limited to 'cps-service/src/test/groovy')
-rw-r--r-- | cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy | 39 | ||||
-rwxr-xr-x | cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy | 3 |
2 files changed, 33 insertions, 9 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 f380d106c7..5f2168aeb9 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 @@ -21,23 +21,35 @@ package org.onap.cps.api.impl import org.onap.cps.TestUtils -import org.onap.cps.spi.CascadeDeleteAllowed -import org.onap.cps.spi.CpsModulePersistenceService; +import org.onap.cps.api.CpsAdminService +import org.onap.cps.spi.CpsModulePersistenceService import org.onap.cps.spi.exceptions.ModelValidationException 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.caffeine.CaffeineCacheManager +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.context.ContextConfiguration import spock.lang.Specification import spock.lang.Unroll import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED +@SpringBootTest +@ComponentScan("org.onap.cps") +@ContextConfiguration(classes = CpsModuleServiceImplSpec.class) class CpsModuleServiceImplSpec extends Specification { - def mockModuleStoreService = Mock(CpsModulePersistenceService) - def objectUnderTest = new CpsModuleServiceImpl() - - def setup() { - objectUnderTest.cpsModulePersistenceService = mockModuleStoreService - } + @SpringBean + CpsModulePersistenceService mockModuleStoreService = Mock() + @SpringBean + CpsAdminService mockCpsAdminService = Mock() + @Autowired + CpsModuleServiceImpl objectUnderTest = new CpsModuleServiceImpl() + @SpringBean + CacheManager cacheManager = new CaffeineCacheManager("yangSchema"); def 'Create schema set'() { given: 'Valid yang resource as name-to-content map' @@ -69,6 +81,17 @@ class CpsModuleServiceImplSpec extends Specification { result.getModuleReferences().contains(new ModuleReference('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 + } + @Unroll def 'Delete set by name and dataspace with #cascadeDeleteOption.'(){ when: 'schema set deletion is requested' diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy index 22dc39ad90..d6751bb4e2 100755 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy @@ -24,13 +24,14 @@ import org.onap.cps.TestUtils import org.onap.cps.spi.CpsModulePersistenceService
import spock.lang.Specification
-
class E2ENetworkSliceSpec extends Specification {
def mockModuleStoreService = Mock(CpsModulePersistenceService)
+ def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache)
def objectUnderTest = new CpsModuleServiceImpl()
def setup() {
objectUnderTest.cpsModulePersistenceService = mockModuleStoreService
+ objectUnderTest.yangTextSchemaSourceSetCache = mockYangTextSchemaSourceSetCache
}
def 'E2E model can be parsed by CPS.'() {
|