X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-service%2Fsrc%2Ftest%2Fgroovy%2Forg%2Fonap%2Fcps%2Fapi%2Fimpl%2FYangTextSchemaSourceSetCacheSpec.groovy;h=a9f50ee5b02ee7606186d7a2e77c3847485fb9e3;hb=1322b0f69d5e5401a14a728e45a289311ec7ac4a;hp=860b7399d25bdd9f2fabe8c1407a9a7c95028212;hpb=4e1d5e0a179857bfe14296ae1153b2c1173278c8;p=cps.git diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/YangTextSchemaSourceSetCacheSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/YangTextSchemaSourceSetCacheSpec.groovy index 860b7399d..a9f50ee5b 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/YangTextSchemaSourceSetCacheSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/YangTextSchemaSourceSetCacheSpec.groovy @@ -1,6 +1,7 @@ /* - * ============LICENSE_START======================================================= + * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada + * Modifications Copyright (C) 2022 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,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 @@ -42,6 +45,9 @@ class YangTextSchemaSourceSetCacheSpec extends Specification { @SpringBean CpsModulePersistenceService mockModuleStoreService = Mock() + @SpringBean + CpsValidator mockCpsValidator = Mock(CpsValidator) + @Autowired YangTextSchemaSourceSetCache objectUnderTest @@ -72,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'() { @@ -97,9 +105,11 @@ class YangTextSchemaSourceSetCacheSpec extends Specification { then: 'cached value is same as expected' def cachedValue = getCachedValue('my-dataspace', 'my-schemaset') cachedValue.getModuleReferences() == yangTextSchemaSourceSet.getModuleReferences() + and: 'the CpsValidator is called on the dataspaceName and schemaSetName' + 1 * mockCpsValidator.validateNameCharacters('my-dataspace', 'my-schemaset') } - def 'Cache Evict: remove when exist'() { + def 'Cache Evict:with invalid #scenario'() { given: 'a schema set exists in cache' def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang') def yangTextSchemaSourceSet = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap) @@ -110,6 +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 + 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'() { @@ -119,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) {