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 --- .../java/org/onap/cps/api/CpsAdminService.java | 13 ++++--- .../org/onap/cps/api/impl/CpsAdminServiceImpl.java | 4 +- .../onap/cps/spi/CpsAdminPersistenceService.java | 13 +++++-- .../main/java/org/onap/cps/spi/model/Anchor.java | 22 +++++------ .../cps/api/impl/CpsAdminServiceImplSpec.groovy | 43 +++++----------------- 5 files changed, 38 insertions(+), 57 deletions(-) (limited to 'cps-service') diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java index a2c05bfe5..5090e3a3c 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java @@ -21,6 +21,7 @@ package org.onap.cps.api; import java.util.Collection; +import org.checkerframework.checker.nullness.qual.NonNull; import org.onap.cps.spi.exceptions.CpsException; import org.onap.cps.spi.model.Anchor; @@ -30,13 +31,14 @@ import org.onap.cps.spi.model.Anchor; public interface CpsAdminService { /** - * Create an anchor using provided anchorDetails object. + * Create an Anchor. * - * @param anchor the anchor details object. - * @return the anchor name. + * @param dataspaceName dataspace name + * @param schemaSetName schema set name + * @param anchorName anchor name * @throws CpsException if input data is invalid. */ - String createAnchor(Anchor anchor); + void createAnchor(@NonNull String dataspaceName, @NonNull String schemaSetName, @NonNull String anchorName); /** * Read all anchors in the given a dataspace. @@ -44,5 +46,6 @@ public interface CpsAdminService { * @param dataspaceName dataspace name * @return a collection of anchors */ - Collection getAnchors(String dataspaceName); + @NonNull + Collection getAnchors(@NonNull String dataspaceName); } diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java index 5d9bc015f..f93a82707 100644 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java @@ -34,8 +34,8 @@ public class CpsAdminServiceImpl implements CpsAdminService { private CpsAdminPersistenceService cpsAdminPersistenceService; @Override - public String createAnchor(final Anchor anchor) { - return cpsAdminPersistenceService.createAnchor(anchor); + public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) { + cpsAdminPersistenceService.createAnchor(dataspaceName, schemaSetName, anchorName); } @Override diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java index 4e88d49a6..1b7ddb724 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java @@ -22,6 +22,7 @@ package org.onap.cps.spi; import java.util.Collection; +import org.checkerframework.checker.nullness.qual.NonNull; import org.onap.cps.spi.model.Anchor; /* @@ -32,10 +33,12 @@ public interface CpsAdminPersistenceService { /** * Create an Anchor. * - * @param anchor the anchorDetails object. - * @return the anchor name. + * @param dataspaceName dataspace name + * @param schemaSetName schema set name + * @param anchorName anchor name */ - String createAnchor(Anchor anchor); + void createAnchor(@NonNull String dataspaceName, @NonNull String schemaSetName, @NonNull String anchorName); + /** * Read all anchors in the given a dataspace. @@ -43,5 +46,7 @@ public interface CpsAdminPersistenceService { * @param dataspaceName dataspace name * @return a collection of anchors */ - Collection getAnchors(String dataspaceName); + @NonNull + Collection getAnchors(@NonNull String dataspaceName); + } diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/Anchor.java b/cps-service/src/main/java/org/onap/cps/spi/model/Anchor.java index cd1c77447..456f73393 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/model/Anchor.java +++ b/cps-service/src/main/java/org/onap/cps/spi/model/Anchor.java @@ -21,23 +21,21 @@ package org.onap.cps.spi.model; import java.io.Serializable; -import java.util.Map; -import lombok.Getter; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; import lombok.NoArgsConstructor; -import lombok.Setter; -@Setter -@Getter +@Data +@Builder @NoArgsConstructor +@AllArgsConstructor public class Anchor implements Serializable { - // anchor will support both a single module and schema set until CPS-99 is complete private static final long serialVersionUID = 1464791260718603291L; - private String anchorName; + + private String name; private String dataspaceName; - private String namespace; - private String revision; - private String moduleSetName; - private Map externalReferences; - private String xpath; + private String schemaSetName; + } \ No newline at end of file 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 d31a2f72d..9e13c771d 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