summaryrefslogtreecommitdiffstats
path: root/cps-service/src
diff options
context:
space:
mode:
authorRishi Chail <rishi.chail@est.tech>2020-12-17 12:55:49 +0000
committerGerrit Code Review <gerrit@onap.org>2020-12-17 12:55:49 +0000
commit1d9845679de45007db30eee42c105edcffd972fb (patch)
tree51434e7dfb545150d31c832690b1fd4464bc06a6 /cps-service/src
parentb9f857d3bf6d7fa8f9d0d5fa1796113d43e6e50d (diff)
parent8a1e3c9f90d2111835460fc042b4a63f93b80384 (diff)
Merge "Associate anchor to schema set"
Diffstat (limited to 'cps-service/src')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java13
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java4
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java13
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/model/Anchor.java22
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy43
5 files changed, 38 insertions, 57 deletions
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 a2c05bfe5a..5090e3a3c4 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<Anchor> getAnchors(String dataspaceName);
+ @NonNull
+ Collection<Anchor> 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 5d9bc015fd..f93a827079 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 4e88d49a63..1b7ddb724c 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<Anchor> getAnchors(String dataspaceName);
+ @NonNull
+ Collection<Anchor> 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 cd1c774476..456f733935 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<String, String> 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 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<Anchor> anchorCollection = Arrays.asList(anchor)
+ def 'Retrieve all anchors for dataspace'() {
+ given: 'that anchor is associated with the dataspace'
+ Collection<Anchor> 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
- }
}