From 14d1bae3cb5d3453f8a1c4a561981fd84a40c040 Mon Sep 17 00:00:00 2001 From: Renu Kumari Date: Fri, 23 Jul 2021 09:54:05 -0400 Subject: Renamed UnitSpec to Spec Issue-ID: CPS-501 Signed-off-by: Renu Kumari Change-Id: Ie1878c6a271a335320e854b81b7f664762d64fbf --- .../spi/impl/CpsDataPersistenceServiceSpec.groovy | 72 ++++++++++++++++++++++ .../impl/CpsDataPersistenceServiceUnitSpec.groovy | 72 ---------------------- 2 files changed, 72 insertions(+), 72 deletions(-) create mode 100644 cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy delete mode 100644 cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceUnitSpec.groovy 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 new file mode 100644 index 0000000000..5ed3ae3e8c --- /dev/null +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy @@ -0,0 +1,72 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2021 Bell Canada. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= +*/ + +package org.onap.cps.spi.impl + +import org.hibernate.StaleStateException +import org.onap.cps.spi.entities.FragmentEntity +import org.onap.cps.spi.exceptions.ConcurrencyException +import org.onap.cps.spi.model.DataNodeBuilder +import org.onap.cps.spi.repository.AnchorRepository +import org.onap.cps.spi.repository.DataspaceRepository +import org.onap.cps.spi.repository.FragmentRepository +import spock.lang.Specification + + +class CpsDataPersistenceServiceSpec extends Specification { + + def mockDataspaceRepository = Mock(DataspaceRepository) + def mockAnchorRepository = Mock(AnchorRepository) + def mockFragmentRepository = Mock(FragmentRepository) + + def objectUnderTest = new CpsDataPersistenceServiceImpl( + mockDataspaceRepository, mockAnchorRepository, mockFragmentRepository) + + def 'Handling of StaleStateException (caused by concurrent updates) during data node tree update.'() { + + def parentXpath = 'parent-01' + def myDataspaceName = 'my-dataspace' + def myAnchorName = 'my-anchor' + + given: 'data node object' + def submittedDataNode = new DataNodeBuilder() + .withXpath(parentXpath) + .withLeaves(['leaf-name': 'leaf-value']) + .build() + and: 'fragment to be updated' + mockFragmentRepository.getByDataspaceAndAnchorAndXpath(_, _, _) >> { + def fragmentEntity = new FragmentEntity() + fragmentEntity.setXpath(parentXpath) + fragmentEntity.setChildFragments(Collections.emptySet()) + return fragmentEntity + } + and: 'data node is concurrently updated by another transaction' + mockFragmentRepository.save(_) >> { throw new StaleStateException("concurrent updates") } + + when: 'attempt to update data node' + objectUnderTest.replaceDataNodeTree(myDataspaceName, myAnchorName, submittedDataNode) + + then: 'concurrency exception is thrown' + def concurrencyException = thrown(ConcurrencyException) + assert concurrencyException.getDetails().contains(myDataspaceName) + assert concurrencyException.getDetails().contains(myAnchorName) + assert concurrencyException.getDetails().contains(parentXpath) + } + + +} diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceUnitSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceUnitSpec.groovy deleted file mode 100644 index 5257e62a6a..0000000000 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceUnitSpec.groovy +++ /dev/null @@ -1,72 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (c) 2021 Bell Canada. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= -*/ - -package org.onap.cps.spi.impl - -import org.hibernate.StaleStateException -import org.onap.cps.spi.entities.FragmentEntity -import org.onap.cps.spi.exceptions.ConcurrencyException -import org.onap.cps.spi.model.DataNodeBuilder -import org.onap.cps.spi.repository.AnchorRepository -import org.onap.cps.spi.repository.DataspaceRepository -import org.onap.cps.spi.repository.FragmentRepository -import spock.lang.Specification - - -class CpsDataPersistenceServiceUnitSpec extends Specification { - - def mockDataspaceRepository = Mock(DataspaceRepository) - def mockAnchorRepository = Mock(AnchorRepository) - def mockFragmentRepository = Mock(FragmentRepository) - - def objectUnderTest = new CpsDataPersistenceServiceImpl( - mockDataspaceRepository, mockAnchorRepository, mockFragmentRepository) - - def 'Handling of StaleStateException (caused by concurrent updates) during data node tree update.'() { - - def parentXpath = 'parent-01' - def myDataspaceName = 'my-dataspace' - def myAnchorName = 'my-anchor' - - given: 'data node object' - def submittedDataNode = new DataNodeBuilder() - .withXpath(parentXpath) - .withLeaves(['leaf-name': 'leaf-value']) - .build() - and: 'fragment to be updated' - mockFragmentRepository.getByDataspaceAndAnchorAndXpath(_, _, _) >> { - def fragmentEntity = new FragmentEntity() - fragmentEntity.setXpath(parentXpath) - fragmentEntity.setChildFragments(Collections.emptySet()) - return fragmentEntity - } - and: 'data node is concurrently updated by another transaction' - mockFragmentRepository.save(_) >> { throw new StaleStateException("concurrent updates") } - - when: 'attempt to update data node' - objectUnderTest.replaceDataNodeTree(myDataspaceName, myAnchorName, submittedDataNode) - - then: 'concurrency exception is thrown' - def concurrencyException = thrown(ConcurrencyException) - assert concurrencyException.getDetails().contains(myDataspaceName) - assert concurrencyException.getDetails().contains(myAnchorName) - assert concurrencyException.getDetails().contains(parentXpath) - } - - -} -- cgit 1.2.3-korg