Retrieve an Anchor for a given dataspace by anchor name - Service layer 67/117067/2
authorRishi.Chail <rishi.chail@est.tech>
Thu, 21 Jan 2021 19:14:24 +0000 (19:14 +0000)
committerRishi Chail <rishi.chail@est.tech>
Fri, 22 Jan 2021 16:03:47 +0000 (16:03 +0000)
Part of story already done in CPS-135

Issue-ID: CPS-55

Signed-off-by: Rishi.Chail <rishi.chail@est.tech>
Change-Id: I0c4ae551f5c85866ce543fbb27b18ffff7d80462

cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java [changed mode: 0644->0755]
cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java [changed mode: 0644->0755]
cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy

old mode 100644 (file)
new mode 100755 (executable)
index 853bd95..ed89c43
@@ -57,4 +57,14 @@ public interface CpsAdminService {
      */
     @NonNull
     Collection<Anchor> getAnchors(@NonNull String dataspaceName);
      */
     @NonNull
     Collection<Anchor> getAnchors(@NonNull String dataspaceName);
+
+    /**
+     * Get an anchor in the given dataspace using the anchor name.
+     *
+     * @param dataspaceName dataspace name
+     * @param anchorName anchor name
+     * @return an anchor
+     */
+    @NonNull
+    Anchor getAnchor(@NonNull String dataspaceName, @NonNull String anchorName);
 }
 }
old mode 100644 (file)
new mode 100755 (executable)
index 0cb85fd..09550f1
@@ -47,4 +47,9 @@ public class CpsAdminServiceImpl implements CpsAdminService {
     public Collection<Anchor> getAnchors(final String dataspaceName) {
         return cpsAdminPersistenceService.getAnchors(dataspaceName);
     }
     public Collection<Anchor> getAnchors(final String dataspaceName) {
         return cpsAdminPersistenceService.getAnchors(dataspaceName);
     }
-}
+
+    @Override
+    public Anchor getAnchor(final String dataspaceName, final String anchorName) {
+        return cpsAdminPersistenceService.getAnchor(dataspaceName, anchorName);
+    }
+}
\ No newline at end of file
index 5aaa340..7c0c626 100755 (executable)
@@ -32,25 +32,33 @@ class CpsAdminServiceImplSpec extends Specification {
         objectUnderTest.cpsAdminPersistenceService = mockCpsAdminPersistenceService
     }
 
         objectUnderTest.cpsAdminPersistenceService = mockCpsAdminPersistenceService
     }
 
-    def 'Create dataspace method invokes persistence service'() {
+    def 'Create dataspace method invokes persistence service.'() {
         when: 'Create dataspace method is invoked'
             objectUnderTest.createDataspace('someDataspace')
         then: 'The persistence service method is invoked with same parameters'
             1 * mockCpsAdminPersistenceService.createDataspace('someDataspace')
     }
 
         when: 'Create dataspace method is invoked'
             objectUnderTest.createDataspace('someDataspace')
         then: 'The persistence service method is invoked with same parameters'
             1 * mockCpsAdminPersistenceService.createDataspace('someDataspace')
     }
 
-    def 'Create anchor method invokes persistence service'() {
+    def 'Create anchor method invokes persistence service.'() {
         when: 'Create anchor method is invoked'
             objectUnderTest.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName')
         then: 'The persistence service method is invoked with same parameters'
             1 * mockCpsAdminPersistenceService.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName')
     }
 
         when: 'Create anchor method is invoked'
             objectUnderTest.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName')
         then: 'The persistence service method is invoked with same parameters'
             1 * mockCpsAdminPersistenceService.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName')
     }
 
-    def 'Retrieve all anchors for dataspace'() {
+    def 'Retrieve all anchors for dataspace.'() {
         given: 'that anchor is associated with the dataspace'
             Collection<Anchor> anchorCollection = Arrays.asList(new Anchor())
             mockCpsAdminPersistenceService.getAnchors('someDataspace') >> { anchorCollection }
         expect: 'the collection provided by persistence service is returned as result'
             objectUnderTest.getAnchors('someDataspace') == anchorCollection
     }
         given: 'that anchor is associated with the dataspace'
             Collection<Anchor> anchorCollection = Arrays.asList(new Anchor())
             mockCpsAdminPersistenceService.getAnchors('someDataspace') >> { anchorCollection }
         expect: 'the collection provided by persistence service is returned as result'
             objectUnderTest.getAnchors('someDataspace') == anchorCollection
     }
-}
+    
+    def 'Retrieve anchor for dataspace and provided anchor name.'() {
+        given: 'that anchor name is associated with the dataspace'
+            Anchor anchor = new Anchor()
+            mockCpsAdminPersistenceService.getAnchor('someDataspace','someAnchor') >>  anchor 
+        expect: 'the anchor provided by persistence service is returned as result'
+            objectUnderTest.getAnchor('someDataspace','someAnchor') == anchor
+    }   
+}
\ No newline at end of file