summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/test/groovy/org
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri/src/test/groovy/org')
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/cache/AnchorDataCacheConfigSpec.groovy52
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/cache/AnchorDataCacheEntrySpec.groovy40
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy7
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy10
4 files changed, 107 insertions, 2 deletions
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/cache/AnchorDataCacheConfigSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/cache/AnchorDataCacheConfigSpec.groovy
new file mode 100644
index 0000000000..a77db1be88
--- /dev/null
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/cache/AnchorDataCacheConfigSpec.groovy
@@ -0,0 +1,52 @@
+/*
+ * ============LICENSE_START=======================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.cache
+import com.hazelcast.core.Hazelcast
+import com.hazelcast.map.IMap
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.test.context.ContextConfiguration
+import spock.lang.Specification
+
+@SpringBootTest
+@ContextConfiguration(classes = [AnchorDataCacheConfig])
+class AnchorDataCacheConfigSpec extends Specification {
+
+ @Autowired
+ private IMap<String, AnchorDataCacheEntry> anchorDataCache
+
+ def 'Embedded (hazelcast) cache for Anchor Data.'() {
+ expect: 'system is able to create an instance of the Anchor data cache'
+ assert null != anchorDataCache
+ and: 'there is at least 1 instance'
+ assert Hazelcast.allHazelcastInstances.size() > 0
+ and: 'anchorDataCache is present'
+ assert Hazelcast.allHazelcastInstances.name.contains('hazelCastInstanceCpsRi')
+ }
+
+ def 'Verify configs for Distributed Caches'(){
+ given: 'the Anchor Data Cache config'
+ def anchorDataCacheConfig = Hazelcast.getHazelcastInstanceByName('hazelCastInstanceCpsRi').config.mapConfigs.get('anchorDataCacheMapConfig')
+ expect: 'system created instance with correct config'
+ assert anchorDataCacheConfig.backupCount == 3
+ assert anchorDataCacheConfig.asyncBackupCount == 3
+ }
+}
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/cache/AnchorDataCacheEntrySpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/cache/AnchorDataCacheEntrySpec.groovy
new file mode 100644
index 0000000000..103631ec2f
--- /dev/null
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/cache/AnchorDataCacheEntrySpec.groovy
@@ -0,0 +1,40 @@
+/*
+ * ============LICENSE_START=======================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.cache
+
+import org.onap.cps.spi.cache.AnchorDataCacheEntry
+import spock.lang.Specification
+
+class AnchorDataCacheEntrySpec extends Specification {
+
+ def objectUnderTest = new AnchorDataCacheEntry()
+
+ def 'Anchor Data Cache Properties Management.'() {
+ when: 'a property named "sample" is added to the cache'
+ objectUnderTest.setProperty('sample', 123)
+ then: 'the cache has that property'
+ assert objectUnderTest.hasProperty('sample')
+ and: 'the value is correct'
+ assert objectUnderTest.getProperty('sample') == 123
+ and: 'the cache does not have an an object called "something else"'
+ assert objectUnderTest.hasProperty('something else') == false
+ }
+}
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
index 470b03afdf..3b15b7607f 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
@@ -22,6 +22,7 @@ package org.onap.cps.spi.impl
import com.fasterxml.jackson.databind.ObjectMapper
import org.hibernate.StaleStateException
import org.onap.cps.spi.FetchDescendantsOption
+import org.onap.cps.spi.cache.AnchorDataCacheEntry
import org.onap.cps.spi.entities.AnchorEntity
import org.onap.cps.spi.entities.FragmentEntity
import org.onap.cps.spi.entities.SchemaSetEntity
@@ -37,6 +38,7 @@ import org.onap.cps.spi.utils.SessionManager
import org.onap.cps.utils.JsonObjectMapper
import spock.lang.Shared
import spock.lang.Specification
+import com.hazelcast.map.IMap;
class CpsDataPersistenceServiceSpec extends Specification {
@@ -45,9 +47,10 @@ class CpsDataPersistenceServiceSpec extends Specification {
def mockFragmentRepository = Mock(FragmentRepository)
def jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
def mockSessionManager = Mock(SessionManager)
+ def mockAnchorDataCache = Mock(IMap<String, AnchorDataCacheEntry>)
def objectUnderTest = new CpsDataPersistenceServiceImpl(
- mockDataspaceRepository, mockAnchorRepository, mockFragmentRepository, jsonObjectMapper,mockSessionManager)
+ mockDataspaceRepository, mockAnchorRepository, mockFragmentRepository, jsonObjectMapper, mockSessionManager, mockAnchorDataCache)
@Shared
def NEW_RESOURCE_CONTENT = 'module stores {\n' +
@@ -211,4 +214,4 @@ class CpsDataPersistenceServiceSpec extends Specification {
}
return dataNode
}
-} \ No newline at end of file
+}
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy
index d6f10d809d..1fbff654f8 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy
@@ -23,7 +23,11 @@
package org.onap.cps.spi.impl
import com.fasterxml.jackson.databind.ObjectMapper
+import com.hazelcast.config.Config
+import com.hazelcast.instance.impl.HazelcastInstanceFactory
+import com.hazelcast.map.IMap
import org.onap.cps.DatabaseTestContainer
+import org.onap.cps.spi.cache.AnchorDataCacheEntry
import org.onap.cps.spi.repository.AnchorRepository
import org.onap.cps.spi.repository.DataspaceRepository
import org.onap.cps.spi.repository.FragmentRepository
@@ -58,6 +62,12 @@ class CpsPersistenceSpecBase extends Specification {
@SpringBean
JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
+ // Instantiate Hazelcast with different name for testing purposes!
+ @SpringBean
+ IMap<String, AnchorDataCacheEntry> anchorDataCache = HazelcastInstanceFactory
+ .getOrCreateHazelcastInstance(new Config('hazelcastTestInstance'))
+ .getMap('testAnchorDataCacheMap')
+
static final String CLEAR_DATA = '/data/clear-all.sql'
static final String DATASPACE_NAME = 'DATASPACE-001'