/*
- * ============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.
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
@SpringBean
CpsModulePersistenceService mockModuleStoreService = Mock()
+ @SpringBean
+ CpsValidator mockCpsValidator = Mock(CpsValidator)
+
@Autowired
YangTextSchemaSourceSetCache objectUnderTest
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'() {
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)
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'() {
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) {