diff options
Diffstat (limited to 'cps-ri')
4 files changed, 17 insertions, 31 deletions
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 78983ee0d..16ec270c2 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 @@ -82,7 +82,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService private final JsonObjectMapper jsonObjectMapper; private final SessionManager sessionManager; - private static final String REG_EX_FOR_OPTIONAL_LIST_INDEX = "(\\[@[\\s\\S]+?])?)"; + private static final String REG_EX_FOR_OPTIONAL_LIST_INDEX = "(\\[@.+?])?)"; private static final String QUERY_ACROSS_ANCHORS = null; private static final AnchorEntity ALL_ANCHORS = null; @@ -171,11 +171,6 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService } @Override - public void storeDataNode(final String dataspaceName, final String anchorName, final DataNode dataNode) { - storeDataNodes(dataspaceName, anchorName, Collections.singletonList(dataNode)); - } - - @Override public void storeDataNodes(final String dataspaceName, final String anchorName, final Collection<DataNode> dataNodes) { final AnchorEntity anchorEntity = getAnchorEntity(dataspaceName, anchorName); @@ -438,8 +433,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService final CpsPathQuery cpsPathQuery) { final Set<String> ancestorXpath = new HashSet<>(); final Pattern pattern = - Pattern.compile("([\\s\\S]*/" + Pattern.quote(cpsPathQuery.getAncestorSchemaNodeIdentifier()) - + REG_EX_FOR_OPTIONAL_LIST_INDEX + "/[\\s\\S]*"); + Pattern.compile("(.*/" + Pattern.quote(cpsPathQuery.getAncestorSchemaNodeIdentifier()) + + REG_EX_FOR_OPTIONAL_LIST_INDEX + "/.*"); for (final FragmentEntity fragmentEntity : fragmentEntities) { final Matcher matcher = pattern.matcher(fragmentEntity.getXpath()); if (matcher.matches()) { 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 93d766201..67ccc805a 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 @@ -170,7 +170,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { when: 'the new data node (list elements) are added to an existing parent node' objectUnderTest.addMultipleLists(DATASPACE_NAME, ANCHOR_NAME3, '/parent-201', [listElements]) then: 'new entries are successfully persisted, parent node now contains 5 children (2 new + 3 existing before)' - def parentFragment = fragmentRepository.getById(LIST_DATA_NODE_PARENT201_FRAGMENT_ID) + def parentFragment = fragmentRepository.getReferenceById(LIST_DATA_NODE_PARENT201_FRAGMENT_ID) def allChildXpaths = parentFragment.childFragments.collect { it.xpath } assert allChildXpaths.size() == 5 assert allChildXpaths.containsAll(listElementXpaths) @@ -325,7 +325,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { objectUnderTest.updateDataLeaves(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, '/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 updatedFragment = fragmentRepository.getReferenceById(DATA_NODE_202_FRAGMENT_ID) def updatedLeaves = getLeavesMap(updatedFragment) assert updatedLeaves.size() == 1 assert updatedLeaves.'leaf-value' == 'new' @@ -356,7 +356,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { when: 'update data nodes and descendants is performed' objectUnderTest.updateDataNodesAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNodes) then: 'leaves have been updated for selected data node' - def updatedFragment = fragmentRepository.getById(DATA_NODE_202_FRAGMENT_ID) + def updatedFragment = fragmentRepository.getReferenceById(DATA_NODE_202_FRAGMENT_ID) def updatedLeaves = getLeavesMap(updatedFragment) assert updatedLeaves.size() == 1 assert updatedLeaves.'leaf-value' == 'new' @@ -375,7 +375,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { when: 'update is performed including descendants' objectUnderTest.updateDataNodesAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNodes) then: 'leaves have been updated for selected data node' - def updatedFragment = fragmentRepository.getById(DATA_NODE_202_FRAGMENT_ID) + def updatedFragment = fragmentRepository.getReferenceById(DATA_NODE_202_FRAGMENT_ID) def updatedLeaves = getLeavesMap(updatedFragment) assert updatedLeaves.size() == 1 assert updatedLeaves.'leaf-value' == 'new' @@ -395,7 +395,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { when: 'update is performed including descendants' objectUnderTest.updateDataNodesAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNodes) then: 'leaves have been updated for selected data node' - def updatedFragment = fragmentRepository.getById(DATA_NODE_202_FRAGMENT_ID) + def updatedFragment = fragmentRepository.getReferenceById(DATA_NODE_202_FRAGMENT_ID) def updatedLeaves = getLeavesMap(updatedFragment) assert updatedLeaves.size() == 1 assert updatedLeaves.'leaf-value' == 'new' @@ -415,7 +415,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { when: 'update is performed including descendants' objectUnderTest.updateDataNodesAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNodes) then: 'leaves have been updated for selected data node' - def updatedFragment = fragmentRepository.getById(DATA_NODE_202_FRAGMENT_ID) + def updatedFragment = fragmentRepository.getReferenceById(DATA_NODE_202_FRAGMENT_ID) def updatedLeaves = getLeavesMap(updatedFragment) assert updatedLeaves.size() == 1 assert updatedLeaves.'leaf-value' == 'new' @@ -451,13 +451,13 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { objectUnderTest.addListElements(DATASPACE_NAME, ANCHOR_NAME1, parentXpath, originalListEntriesAsDataNodes) } and: 'each original list element has one child' - def originalParentFragment = fragmentRepository.getById(PARENT_3_FRAGMENT_ID) + def originalParentFragment = fragmentRepository.getReferenceById(PARENT_3_FRAGMENT_ID) originalParentFragment.childFragments.each {assert it.childFragments.size() == 1 } when: 'it is updated with #scenario' def replacementListEntriesAsDataNodes = createChildListAllHavingAttributeValue(parentXpath, 'new value', replacementKeys, false) objectUnderTest.replaceListContent(DATASPACE_NAME, ANCHOR_NAME1, parentXpath, replacementListEntriesAsDataNodes) then: 'the result list ONLY contains the expected replacement elements' - def parentFragment = fragmentRepository.getById(PARENT_3_FRAGMENT_ID) + def parentFragment = fragmentRepository.getReferenceById(PARENT_3_FRAGMENT_ID) def allChildXpaths = parentFragment.childFragments.collect { it.xpath } def expectedListEntriesAfterUpdateAsXpaths = keysToXpaths(parentXpath, replacementKeys) assert allChildXpaths.size() == replacementKeys.size() @@ -485,7 +485,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { def replacementListEntriesAsDataNodes = createChildListAllHavingAttributeValue(parentXpath, 'new', ['A'], true) objectUnderTest.replaceListContent(DATASPACE_NAME, ANCHOR_NAME1, parentXpath, replacementListEntriesAsDataNodes) then: 'The updated fragment has a child-list with ONLY element "A"' - def parentFragment = fragmentRepository.getById(PARENT_3_FRAGMENT_ID) + def parentFragment = fragmentRepository.getReferenceById(PARENT_3_FRAGMENT_ID) parentFragment.childFragments.size() == 1 def childListElementA = parentFragment.childFragments[0] childListElementA.xpath == "/parent-3/child-list[@key='A']" @@ -506,7 +506,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { def replacementListEntriesAsDataNodes = createChildListAllHavingAttributeValue(XPATH_DATA_NODE_WITH_DESCENDANTS, 'new', ['A','B'], false) objectUnderTest.replaceListContent(DATASPACE_NAME, ANCHOR_NAME1, XPATH_DATA_NODE_WITH_DESCENDANTS, replacementListEntriesAsDataNodes) then: 'the parent will have 3 children after the replacement' - def parentFragment = fragmentRepository.getById(ID_DATA_NODE_WITH_DESCENDANTS) + def parentFragment = fragmentRepository.getReferenceById(ID_DATA_NODE_WITH_DESCENDANTS) parentFragment.childFragments.size() == 3 def xpaths = parentFragment.childFragments.collect {it.xpath} and: 'one of the children is the original child fragment' @@ -539,7 +539,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { when: 'deleting list is executed for: #scenario.' objectUnderTest.deleteListDataNode(DATASPACE_NAME, ANCHOR_NAME3, targetXpaths) and: 'remaining children are fetched' - def parentFragment = fragmentRepository.getById(parentFragmentId) + def parentFragment = fragmentRepository.getReferenceById(parentFragmentId) def remainingChildXpaths = parentFragment.childFragments.collect { it.xpath } then: 'only the expected children remain' assert remainingChildXpaths.size() == expectedRemainingChildXpaths.size() @@ -557,7 +557,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { when: 'deleting nodes is executed for: #scenario.' objectUnderTest.deleteDataNodes(DATASPACE_NAME, ANCHOR_NAME3, targetXpaths) and: 'remaining children are fetched' - def parentFragment = fragmentRepository.getById(LIST_DATA_NODE_PARENT203_FRAGMENT_ID) + def parentFragment = fragmentRepository.getReferenceById(LIST_DATA_NODE_PARENT203_FRAGMENT_ID) def remainingChildXpaths = parentFragment.childFragments.collect { it.xpath } then: 'only the expected children remain' assert remainingChildXpaths.size() == expectedRemainingChildXpaths.size() 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 c8e3283a9..8a5838827 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 @@ -68,15 +68,6 @@ class CpsDataPersistenceServiceSpec extends Specification { 2 * mockFragmentRepository.save(_) } - def 'Store single data node.'() { - given: 'a data node' - def dataNode = new DataNode() - when: 'storing a single data node' - objectUnderTest.storeDataNode('dataspace1', 'anchor1', dataNode) - then: 'the call is redirected to storing a collection of data nodes with just the given data node' - 1 * objectUnderTest.storeDataNodes('dataspace1', 'anchor1', [dataNode]) - } - def 'Handling of StaleStateException (caused by concurrent updates) during update data nodes and descendants.'() { given: 'the system can update one datanode and has two more datanodes that throw an exception while updating' def dataNodes = createDataNodesAndMockRepositoryMethodSupportingThem([ diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy index 53f42f5a9..3a5d9ef76 100644 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy @@ -260,10 +260,10 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase objectUnderTest.deleteUnusedYangResourceModules() then: 'any orphaned (not used by any schema set anymore) yang resources are deleted' def orphanedResourceId = 3100L - yangResourceRepository.findById(orphanedResourceId).isPresent() == false + assert !yangResourceRepository.findById(orphanedResourceId).isPresent() and: 'any shared (still in use by other schema set) yang resources still persists' def sharedResourceId = 3003L - yangResourceRepository.findById(sharedResourceId).isPresent() + assert yangResourceRepository.findById(sharedResourceId).isPresent() } @Sql([CLEAR_DATA, SET_DATA]) |