aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2022-10-27 17:29:04 +0100
committerToineSiebelink <toine.siebelink@est.tech>2022-11-02 09:00:41 +0000
commit14e5bf958bb2b114e3e7d8876bd6f031900c79ec (patch)
treea72bcfee795ab6e27938e5e265327d6aace804e3 /cps-ri
parenta096a7faa35b345c765102201a5a09cc03ef541a (diff)
Ensure prefix is correct module prefix
- Moved Prefix logic from RI to Service layer - Prefix is no PREFIX propety, not the moduel name! == RI (DB Layer) Changes - Removed prefix logic incl hazelcast - Added new basic ri-test for getDataNode and assert prefix is null - Updated exsiting ri-test to us getDataNode - Updated existing ri-test to only use " where really needed == CPS Service Layer Changes - Introduced PrefixResolver with clear and limited responsibility - Use PrefixResolver where needed - Cache prefix map per anchor, use cached entry when available - Disabled SONAR on new Regex == REST Layer - Use PrefixResolver where needed Issue-ID: CPS-1353 Signed-off-by: ToineSiebelink <toine.siebelink@est.tech> Change-Id: Ie16f0e1ee1c280f3eb69c9e64fab69a780fb692a
Diffstat (limited to 'cps-ri')
-rw-r--r--cps-ri/pom.xml4
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/cache/AnchorDataCacheConfig.java72
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/cache/AnchorDataCacheEntry.java44
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java59
-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
-rwxr-xr-xcps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy57
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy11
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy10
9 files changed, 39 insertions, 310 deletions
diff --git a/cps-ri/pom.xml b/cps-ri/pom.xml
index a193baf9fb..824a8d9710 100644
--- a/cps-ri/pom.xml
+++ b/cps-ri/pom.xml
@@ -88,10 +88,6 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
- <dependency>
- <groupId>com.hazelcast</groupId>
- <artifactId>hazelcast-spring</artifactId>
- </dependency>
<!-- T E S T D E P E N D E N C I E S -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/cache/AnchorDataCacheConfig.java b/cps-ri/src/main/java/org/onap/cps/spi/cache/AnchorDataCacheConfig.java
deleted file mode 100644
index f956120e4a..0000000000
--- a/cps-ri/src/main/java/org/onap/cps/spi/cache/AnchorDataCacheConfig.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * ============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.config.Config;
-import com.hazelcast.config.MapConfig;
-import com.hazelcast.config.NamedConfig;
-import com.hazelcast.core.Hazelcast;
-import com.hazelcast.core.HazelcastInstance;
-import com.hazelcast.map.IMap;
-import java.util.concurrent.TimeUnit;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * Core infrastructure of the hazelcast distributed cache for anchor data config use cases.
- */
-@Configuration
-public class AnchorDataCacheConfig {
-
- public static final long ANCHOR_DATA_CACHE_TTL_SECS = TimeUnit.HOURS.toSeconds(1);
- private static final MapConfig anchorDataCacheMapConfig = createMapConfig("anchorDataCacheMapConfig");
-
- /**
- * Distributed instance of anchor data cache that contains module prefix by anchor name as properties.
- *
- * @return configured map of anchor data cache
- */
- @Bean
- public IMap<String, AnchorDataCacheEntry> anchorDataCache() {
- return createHazelcastInstance("hazelCastInstanceCpsRi", anchorDataCacheMapConfig)
- .getMap("anchorDataCache");
- }
-
- private HazelcastInstance createHazelcastInstance(final String hazelcastInstanceName,
- final NamedConfig namedConfig) {
- return Hazelcast.newHazelcastInstance(initializeConfig(hazelcastInstanceName, namedConfig));
- }
-
- private Config initializeConfig(final String instanceName, final NamedConfig namedConfig) {
- final Config config = new Config(instanceName);
- config.addMapConfig((MapConfig) namedConfig);
- config.setClusterName("cps-ri-caches");
- return config;
- }
-
- private static MapConfig createMapConfig(final String configName) {
- final MapConfig mapConfig = new MapConfig(configName);
- mapConfig.setBackupCount(3);
- mapConfig.setAsyncBackupCount(3);
- return mapConfig;
- }
-
-}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/cache/AnchorDataCacheEntry.java b/cps-ri/src/main/java/org/onap/cps/spi/cache/AnchorDataCacheEntry.java
deleted file mode 100644
index 98f6ec3f13..0000000000
--- a/cps-ri/src/main/java/org/onap/cps/spi/cache/AnchorDataCacheEntry.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * ============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 java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-public class AnchorDataCacheEntry implements Serializable {
-
- private static final long serialVersionUID = 2111243947810370698L;
-
- private Map<String, Object> properties = new HashMap<>();
-
- public Object getProperty(final String propertyName) {
- return properties.get(propertyName);
- }
-
- public void setProperty(final String propertyName, final Object value) {
- properties.put(propertyName, value);
- }
-
- public boolean hasProperty(final String propertyName) {
- return properties.containsKey(propertyName);
- }
-}
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
index 2a4a192260..5fe646ff82 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
@@ -24,7 +24,6 @@ package org.onap.cps.spi.impl;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
-import com.hazelcast.map.IMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -33,7 +32,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -46,15 +44,11 @@ import org.onap.cps.cpspath.parser.CpsPathUtil;
import org.onap.cps.cpspath.parser.PathParsingException;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
-import org.onap.cps.spi.cache.AnchorDataCacheConfig;
-import org.onap.cps.spi.cache.AnchorDataCacheEntry;
import org.onap.cps.spi.entities.AnchorEntity;
import org.onap.cps.spi.entities.DataspaceEntity;
import org.onap.cps.spi.entities.FragmentEntity;
import org.onap.cps.spi.entities.FragmentEntityArranger;
import org.onap.cps.spi.entities.FragmentExtract;
-import org.onap.cps.spi.entities.SchemaSetEntity;
-import org.onap.cps.spi.entities.YangResourceEntity;
import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.exceptions.AlreadyDefinedExceptionBatch;
import org.onap.cps.spi.exceptions.ConcurrencyException;
@@ -68,8 +62,6 @@ import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.FragmentRepository;
import org.onap.cps.spi.utils.SessionManager;
import org.onap.cps.utils.JsonObjectMapper;
-import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
@@ -83,7 +75,6 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
private final FragmentRepository fragmentRepository;
private final JsonObjectMapper jsonObjectMapper;
private final SessionManager sessionManager;
- private final IMap<String, AnchorDataCacheEntry> anchorDataCache;
private static final String REG_EX_FOR_OPTIONAL_LIST_INDEX = "(\\[@[\\s\\S]+?]){0,1})";
private static final Pattern REG_EX_PATTERN_FOR_LIST_ELEMENT_KEY_PREDICATE =
@@ -225,9 +216,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
final FetchDescendantsOption fetchDescendantsOption) {
final FragmentEntity fragmentEntity = getFragmentByXpath(dataspaceName, anchorName, xpath,
fetchDescendantsOption);
- final DataNode dataNode = toDataNode(fragmentEntity, fetchDescendantsOption);
- dataNode.setModuleNamePrefix(getRootModuleNamePrefix(fragmentEntity.getAnchor()));
- return dataNode;
+ return toDataNode(fragmentEntity, fetchDescendantsOption);
}
private FragmentEntity getFragmentWithoutDescendantsByXpath(final String dataspaceName,
@@ -285,12 +274,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
fragmentEntities = ancestorXpaths.isEmpty() ? Collections.emptyList()
: fragmentRepository.findAllByAnchorAndXpathIn(anchorEntity, ancestorXpaths);
}
- return fragmentEntities.stream()
- .map(fragmentEntity -> {
- final DataNode dataNode = toDataNode(fragmentEntity, fetchDescendantsOption);
- dataNode.setModuleNamePrefix(getRootModuleNamePrefix(anchorEntity));
- return dataNode;
- }).collect(Collectors.toUnmodifiableList());
+ return fragmentEntities.stream().map(fragmentEntity -> toDataNode(fragmentEntity, fetchDescendantsOption))
+ .collect(Collectors.toUnmodifiableList());
}
@Override
@@ -337,44 +322,6 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
.withChildDataNodes(childDataNodes).build();
}
- private String getRootModuleNamePrefix(final AnchorEntity anchorEntity) {
- final String cachedModuleNamePrefix = getModuleNamePrefixFromCache(anchorEntity.getName());
- if (cachedModuleNamePrefix != null) {
- return cachedModuleNamePrefix;
- }
- final String moduleNamePrefix = buildSchemaContextAndRetrieveModulePrefix(anchorEntity);
- cacheModuleNamePrefix(anchorEntity.getName(), moduleNamePrefix);
- return moduleNamePrefix;
- }
-
- private String buildSchemaContextAndRetrieveModulePrefix(final AnchorEntity anchorEntity) {
- final SchemaSetEntity schemaSetEntity = anchorEntity.getSchemaSet();
- final Map<String, String> yangResourceNameToContent =
- schemaSetEntity.getYangResources().stream().collect(
- Collectors.toMap(YangResourceEntity::getFileName, YangResourceEntity::getContent));
- final SchemaContext schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent)
- .getSchemaContext();
- return schemaContext.getModules().iterator().next().getName();
- }
-
- private void cacheModuleNamePrefix(final String anchorName, final String moduleNamePrefix) {
- final AnchorDataCacheEntry anchorDataCacheEntry = new AnchorDataCacheEntry();
- anchorDataCacheEntry.setProperty(TOP_LEVEL_MODULE_PREFIX_PROPERTY_NAME, moduleNamePrefix);
- if (anchorDataCache.putIfAbsent(anchorName, anchorDataCacheEntry,
- AnchorDataCacheConfig.ANCHOR_DATA_CACHE_TTL_SECS, TimeUnit.SECONDS) == null) {
- log.debug("Module name prefix for an anchor {} is cached", anchorName);
- }
- }
-
- private String getModuleNamePrefixFromCache(final String anchorName) {
- if (anchorDataCache.containsKey(anchorName)) {
- final AnchorDataCacheEntry anchorDataCacheEntry = anchorDataCache.get(anchorName);
- return anchorDataCacheEntry.hasProperty(TOP_LEVEL_MODULE_PREFIX_PROPERTY_NAME)
- ? anchorDataCacheEntry.getProperty(TOP_LEVEL_MODULE_PREFIX_PROPERTY_NAME).toString() : null;
- }
- return null;
- }
-
private List<DataNode> getChildDataNodes(final FragmentEntity fragmentEntity,
final FetchDescendantsOption fetchDescendantsOption) {
if (fetchDescendantsOption.hasNext()) {
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
deleted file mode 100644
index a77db1be88..0000000000
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/cache/AnchorDataCacheConfigSpec.groovy
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * ============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
deleted file mode 100644
index 103631ec2f..0000000000
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/cache/AnchorDataCacheEntrySpec.groovy
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * ============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/CpsDataPersistenceServiceIntegrationSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy
index 412c5aa7b9..a5e17cfefd 100755
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy
@@ -81,28 +81,41 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
}
@Sql([CLEAR_DATA, SET_DATA])
- def 'StoreDataNode with descendants.'() {
+ def 'Get existing datanode with descendants.'() {
+ when: 'the node is retrieved by its xpath'
+ def dataNode = objectUnderTest.getDataNode(DATASPACE_NAME, ANCHOR_NAME1, '/parent-1', INCLUDE_ALL_DESCENDANTS)
+ then: 'the path and prefix are populated correctly'
+ assert dataNode.xpath == '/parent-1'
+ and: 'dataNode has no prefix (to be addressed by CPS-1301'
+ assert dataNode.moduleNamePrefix == null
+ and: 'the child node has the correct path'
+ assert dataNode.childDataNodes[0].xpath == '/parent-1/child-1'
+ }
+
+ @Sql([CLEAR_DATA, SET_DATA])
+ def 'Storing and Retrieving a new DataNode with descendants.'() {
when: 'a fragment with descendants is stored'
- def parentXpath = "/parent-new"
- def childXpath = "/parent-new/child-new"
- def grandChildXpath = "/parent-new/child-new/grandchild-new"
+ def parentXpath = '/parent-new'
+ def childXpath = '/parent-new/child-new'
+ def grandChildXpath = '/parent-new/child-new/grandchild-new'
objectUnderTest.storeDataNode(DATASPACE_NAME, ANCHOR_NAME1,
createDataNodeTree(parentXpath, childXpath, grandChildXpath))
then: 'it can be retrieved by its xpath'
- def parentFragment = getFragmentByXpath(DATASPACE_NAME, ANCHOR_NAME1, parentXpath)
- and: 'it contains the children'
- parentFragment.childFragments.size() == 1
- def childFragment = parentFragment.childFragments[0]
- childFragment.xpath == childXpath
- and: "and its children's children"
- childFragment.childFragments.size() == 1
- def grandchildFragment = childFragment.childFragments[0]
- grandchildFragment.xpath == grandChildXpath
+ def dataNode = objectUnderTest.getDataNode(DATASPACE_NAME, ANCHOR_NAME1, parentXpath, INCLUDE_ALL_DESCENDANTS)
+ assert dataNode.xpath == parentXpath
+ and: 'it has the correct child'
+ assert dataNode.childDataNodes.size() == 1
+ def childDataNode = dataNode.childDataNodes[0]
+ assert childDataNode.xpath == childXpath
+ and: 'and its grandchild'
+ assert childDataNode.childDataNodes.size() == 1
+ def grandChildDataNode = childDataNode.childDataNodes[0]
+ assert grandChildDataNode.xpath == grandChildXpath
}
@Sql([CLEAR_DATA, SET_DATA])
def 'Store data node for multiple anchors using the same schema.'() {
- def xpath = "/parent-new"
+ def xpath = '/parent-new'
given: 'a fragment is stored for an anchor'
objectUnderTest.storeDataNode(DATASPACE_NAME, ANCHOR_NAME1, createDataNodeTree(xpath))
when: 'another fragment is stored for an other anchor, using the same schema set'
@@ -282,7 +295,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
def 'Update data node leaves.'() {
when: 'update is performed for leaves'
objectUnderTest.updateDataLeaves(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES,
- "/parent-200/child-201", ['leaf-value': 'new'])
+ '/parent-200/child-201', ['leaf-value': 'new'])
then: 'leaves are updated for selected data node'
def updatedFragment = fragmentRepository.getById(DATA_NODE_202_FRAGMENT_ID)
def updatedLeaves = getLeavesMap(updatedFragment)
@@ -311,7 +324,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
@Sql([CLEAR_DATA, SET_DATA])
def 'Update data node and descendants by removing descendants.'() {
given: 'data node object with leaves updated, no children'
- def submittedDataNode = buildDataNode("/parent-200/child-201", ['leaf-value': 'new'], [])
+ def submittedDataNode = buildDataNode('/parent-200/child-201', ['leaf-value': 'new'], [])
when: 'update data nodes and descendants is performed'
objectUnderTest.updateDataNodeAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNode)
then: 'leaves have been updated for selected data node'
@@ -328,8 +341,8 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
@Sql([CLEAR_DATA, SET_DATA])
def 'Update data node and descendants with new descendants'() {
given: 'data node object with leaves updated, having child with old content'
- def submittedDataNode = buildDataNode("/parent-200/child-201", ['leaf-value': 'new'], [
- buildDataNode("/parent-200/child-201/grand-child", ['leaf-value': 'original'], [])
+ def submittedDataNode = buildDataNode('/parent-200/child-201', ['leaf-value': 'new'], [
+ buildDataNode('/parent-200/child-201/grand-child', ['leaf-value': 'original'], [])
])
when: 'update is performed including descendants'
objectUnderTest.updateDataNodeAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNode)
@@ -348,8 +361,8 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
@Sql([CLEAR_DATA, SET_DATA])
def 'Update data node and descendants with same descendants but changed leaf value.'() {
given: 'data node object with leaves updated, having child with old content'
- def submittedDataNode = buildDataNode("/parent-200/child-201", ['leaf-value': 'new'], [
- buildDataNode("/parent-200/child-201/grand-child", ['leaf-value': 'new'], [])
+ def submittedDataNode = buildDataNode('/parent-200/child-201', ['leaf-value': 'new'], [
+ buildDataNode('/parent-200/child-201/grand-child', ['leaf-value': 'new'], [])
])
when: 'update is performed including descendants'
objectUnderTest.updateDataNodeAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNode)
@@ -368,8 +381,8 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
@Sql([CLEAR_DATA, SET_DATA])
def 'Update data node and descendants with different descendants xpath'() {
given: 'data node object with leaves updated, having child with old content'
- def submittedDataNode = buildDataNode("/parent-200/child-201", ['leaf-value': 'new'], [
- buildDataNode("/parent-200/child-201/grand-child-new", ['leaf-value': 'new'], [])
+ def submittedDataNode = buildDataNode('/parent-200/child-201', ['leaf-value': 'new'], [
+ buildDataNode('/parent-200/child-201/grand-child-new', ['leaf-value': 'new'], [])
])
when: 'update is performed including descendants'
objectUnderTest.updateDataNodeAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNode)
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 b124925aa8..e69cbee471 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,7 +22,6 @@ 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.FragmentExtract
@@ -35,9 +34,7 @@ import org.onap.cps.spi.repository.DataspaceRepository
import org.onap.cps.spi.repository.FragmentRepository
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 {
@@ -46,10 +43,8 @@ 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, mockAnchorDataCache)
+ def objectUnderTest = new CpsDataPersistenceServiceImpl(mockDataspaceRepository, mockAnchorRepository, mockFragmentRepository, jsonObjectMapper, mockSessionManager)
def 'Handling of StaleStateException (caused by concurrent updates) during update data node and descendants.'() {
given: 'the fragment repository returns a fragment entity'
@@ -191,10 +186,6 @@ class CpsDataPersistenceServiceSpec extends Specification {
def mockFragmentWithJson(json) {
def anchorName = 'some anchor'
- def anchorDataCacheEntry = new AnchorDataCacheEntry()
- anchorDataCacheEntry.setProperty(objectUnderTest.TOP_LEVEL_MODULE_PREFIX_PROPERTY_NAME, 'some prefix')
- mockAnchorDataCache.containsKey(anchorName) >> true
- mockAnchorDataCache.get(anchorName) >> anchorDataCacheEntry
def mockAnchor = Mock(AnchorEntity)
mockAnchor.getId() >> 123
mockAnchor.getName() >> anchorName
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 1fbff654f8..d6f10d809d 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,11 +23,7 @@
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
@@ -62,12 +58,6 @@ 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'