aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
authorputhuparambil.aditya <aditya.puthuparambil@bell.ca>2020-12-10 16:49:53 +0000
committerputhuparambil.aditya <aditya.puthuparambil@bell.ca>2020-12-10 16:55:54 +0000
commite182a6b6cb4a87b4f461adf83fe60a65948fc230 (patch)
tree1a8dbc71794cf742e5f9dd2ce6346c308cc1afc4 /cps-service
parenta66dd4e82e8ef5b2cfe956a9a88a90154889635a (diff)
Retrieve All anchors for a given Dataspace
Issue-ID: CPS-8 Signed-off-by: puthuparambil.aditya <aditya.puthuparambil@bell.ca> Change-Id: Idb2e4f83d390f078345e556d89781e0bf4a9a41f
Diffstat (limited to 'cps-service')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java9
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java6
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java10
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy22
4 files changed, 46 insertions, 1 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 98ea8ebd8..a2c05bfe5 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
@@ -20,6 +20,7 @@
package org.onap.cps.api;
+import java.util.Collection;
import org.onap.cps.spi.exceptions.CpsException;
import org.onap.cps.spi.model.Anchor;
@@ -36,4 +37,12 @@ public interface CpsAdminService {
* @throws CpsException if input data is invalid.
*/
String createAnchor(Anchor anchor);
+
+ /**
+ * Read all anchors in the given a dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @return a collection of anchors
+ */
+ Collection<Anchor> getAnchors(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 b4deef678..5d9bc015f 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
@@ -20,6 +20,7 @@
package org.onap.cps.api.impl;
+import java.util.Collection;
import org.onap.cps.api.CpsAdminService;
import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.model.Anchor;
@@ -36,4 +37,9 @@ public class CpsAdminServiceImpl implements CpsAdminService {
public String createAnchor(final Anchor anchor) {
return cpsAdminPersistenceService.createAnchor(anchor);
}
+
+ @Override
+ public Collection<Anchor> getAnchors(final String dataspaceName) {
+ return cpsAdminPersistenceService.getAnchors(dataspaceName);
+ }
}
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 6709c1fb0..4e88d49a6 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
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation. All rights reserved.
+ * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +21,7 @@
package org.onap.cps.spi;
+import java.util.Collection;
import org.onap.cps.spi.model.Anchor;
/*
@@ -34,4 +36,12 @@ public interface CpsAdminPersistenceService {
* @return the anchor name.
*/
String createAnchor(Anchor anchor);
+
+ /**
+ * Read all anchors in the given a dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @return a collection of anchors
+ */
+ Collection<Anchor> getAnchors(String dataspaceName);
}
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 65a8e71bc..d31a2f72d 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
@@ -20,8 +20,8 @@
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
@@ -52,4 +52,24 @@ class CpsAdminServiceImplSpec extends Specification {
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)
+ mockCpsAdminPersistenceService.getAnchors('dummyDataspace') >> { anchorCollection }
+ expect: 'we try to retrieve an anchor, a collection of anchor is returned by the service'
+ 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
+ }
}