From 8a1e3c9f90d2111835460fc042b4a63f93b80384 Mon Sep 17 00:00:00 2001 From: Ruslan Kashapov Date: Tue, 24 Nov 2020 11:13:43 +0200 Subject: Associate anchor to schema set - db schema updated - db layer tests provided for ancor create and reading by dataspace - anchor model is removed from rest api as extra - api/spi updated to use string references instead of object Issue-ID: CPS-99 Change-Id: Ideeb83fa9e91ec1816308d8327a6589b999c64c5 Signed-off-by: Ruslan Kashapov --- .../cps/api/impl/CpsAdminServiceImplSpec.groovy | 43 +++++----------------- 1 file changed, 9 insertions(+), 34 deletions(-) (limited to 'cps-service/src/test/groovy') diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy index d31a2f72d2..9e13c771d3 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy @@ -21,55 +21,30 @@ package org.onap.cps.api.impl import org.onap.cps.spi.CpsAdminPersistenceService -import org.onap.cps.spi.exceptions.DataspaceNotFoundException import org.onap.cps.spi.model.Anchor import spock.lang.Specification class CpsAdminServiceImplSpec extends Specification { def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService) def objectUnderTest = new CpsAdminServiceImpl() - def anchor = new Anchor() def setup() { objectUnderTest.cpsAdminPersistenceService = mockCpsAdminPersistenceService } - def 'Create an anchor'() { - given: 'that the persistence service returns the name of the anchor' - def anchorName = 'some anchor name' - mockCpsAdminPersistenceService.createAnchor(_) >> anchorName - expect: 'the same anchor name is returned by CPS Admin service' - objectUnderTest.createAnchor(anchor) == anchorName + def 'Create anchor method invokes persistence service'() { + when: 'Create anchor method is invoked' + objectUnderTest.createAnchor('dummyDataspace', 'dummySchemaSet', 'dummyAnchorName') + then: 'The persistence service method is invoked with same parameters' + 1 * mockCpsAdminPersistenceService.createAnchor('dummyDataspace', 'dummySchemaSet', 'dummyAnchorName') } - def 'Create an anchor with some exception in the persistence layer'() { - given: 'that the persistence service throws some exception' - def exceptionThrownInPersistenceLayer = new RuntimeException() - mockCpsAdminPersistenceService.createAnchor(_) >> { throw exceptionThrownInPersistenceLayer } - when: 'we try to create an anchor' - objectUnderTest.createAnchor(anchor) - then: 'the same exception is thrown by the CPS Admin Service' - def exceptionThrownInServiceLayer = thrown(Exception) - exceptionThrownInServiceLayer == exceptionThrownInPersistenceLayer - } - - def 'Retrieve all anchors for an existing dataspace'() { - given: 'that the dataspace exist and an anchor is associated with the dataspace' - Collection anchorCollection = Arrays.asList(anchor) + def 'Retrieve all anchors for dataspace'() { + given: 'that anchor is associated with the dataspace' + Collection anchorCollection = Arrays.asList(new Anchor()) mockCpsAdminPersistenceService.getAnchors('dummyDataspace') >> { anchorCollection } - expect: 'we try to retrieve an anchor, a collection of anchor is returned by the service' + expect: 'the collection provided by persistence service is returned as result' objectUnderTest.getAnchors('dummyDataspace') == anchorCollection } - def 'Retrieve all anchors for a non existing dataspace'() { - given: 'that the dataspace does not exist, service throws an exception' - def exceptionThrownInPersistenceLayer = new DataspaceNotFoundException(_ as String) - mockCpsAdminPersistenceService.getAnchors('dummyDataspace') >> - { throw exceptionThrownInPersistenceLayer } - when: 'we try to retrieve a anchor with a non-existant dataspace' - objectUnderTest.getAnchors('dummyDataspace') - then: 'the same exception is thrown by CPS' - def exceptionThrownInServiceLayer = thrown(Exception) - exceptionThrownInServiceLayer == exceptionThrownInPersistenceLayer - } } -- cgit 1.2.3-korg