deleting namespace and permission implementation 61/89561/1
authorpkaras <piotr.karas@nokia.com>
Thu, 6 Jun 2019 05:28:05 +0000 (07:28 +0200)
committerpkaras <piotr.karas@nokia.com>
Fri, 7 Jun 2019 07:37:40 +0000 (09:37 +0200)
Change-Id: If9e3dc12da186cfee42ae0816e39ba868cb82ad5
Issue-ID: DMAAP-1217
Signed-off-by: piotr.karas <piotr.karas@nokia.com>
src/main/java/org/onap/dmaap/dbcapi/aaf/AafEmpty.java [new file with mode: 0644]
src/main/java/org/onap/dmaap/dbcapi/aaf/AafService.java
src/main/java/org/onap/dmaap/dbcapi/aaf/AafServiceImpl.java
src/main/java/org/onap/dmaap/dbcapi/service/AafTopicSetupService.java
src/test/java/org/onap/dmaap/dbcapi/aaf/AafServiceImplTest.java
src/test/java/org/onap/dmaap/dbcapi/service/AafTopicSetupServiceTest.java

diff --git a/src/main/java/org/onap/dmaap/dbcapi/aaf/AafEmpty.java b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafEmpty.java
new file mode 100644 (file)
index 0000000..87e56c4
--- /dev/null
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * Copyright (C) 2019 Nokia Intellectual Property. 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dmaap.dbcapi.aaf;
+
+class AafEmpty extends AafObject {
+    @Override
+    String toJSON() {
+        return "";
+    }
+}
index 2444d49..c49ffb6 100644 (file)
@@ -33,7 +33,7 @@ public interface AafService {
 
     int addPerm(DmaapPerm perm);
 
 
     int addPerm(DmaapPerm perm);
 
-    int delPerm(DmaapPerm perm);
+    int delPerm(DmaapPerm perm, boolean force);
 
     int addGrant(DmaapGrant grant);
 
 
     int addGrant(DmaapGrant grant);
 
@@ -45,5 +45,5 @@ public interface AafService {
 
     int addNamespace(AafNamespace ns);
 
 
     int addNamespace(AafNamespace ns);
 
-    int delNamespace(AafNamespace ns);
+    int delNamespace(AafNamespace ns, boolean force);
 }
 }
index edce4f0..4848a69 100644 (file)
@@ -23,10 +23,13 @@ package org.onap.dmaap.dbcapi.aaf;
 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
 import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
 
 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
 import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
 
+import static java.lang.String.format;
+
 public class AafServiceImpl extends BaseLoggingClass implements AafService {
 
     private static final int CREATED = 201;
     private static final int OK = 200;
 public class AafServiceImpl extends BaseLoggingClass implements AafService {
 
     private static final int CREATED = 201;
     private static final int OK = 200;
+    private static final String FORCE = "?force=true";
     private final String aafUrl;
     private final String identity;
     private final boolean useAAF;
     private final String aafUrl;
     private final String identity;
     private final boolean useAAF;
@@ -51,8 +54,11 @@ public class AafServiceImpl extends BaseLoggingClass implements AafService {
     }
 
     @Override
     }
 
     @Override
-    public int delPerm(DmaapPerm perm) {
-        return OK;
+    public int delPerm(DmaapPerm perm, boolean force) {
+        logger.info("entry: delPerm()");
+        return doDelete(new AafEmpty(), format(
+                "authz/perm/%s/%s/%s%s",
+                perm.getPermission(), perm.getPtype(), perm.getAction(), force ? FORCE : ""), OK);
     }
 
     @Override
     }
 
     @Override
@@ -86,8 +92,11 @@ public class AafServiceImpl extends BaseLoggingClass implements AafService {
     }
 
     @Override
     }
 
     @Override
-    public int delNamespace(AafNamespace ns) {
-        return OK;
+    public int delNamespace(AafNamespace ns, boolean force) {
+        logger.info("entry: delNamespace()");
+        return doDelete(new AafEmpty(), format(
+                "authz/ns/%s%s",
+                ns.getName(), force ? FORCE : ""), OK);
     }
 
     private int doPost(AafObject obj, String uri, int expect) {
     }
 
     private int doPost(AafObject obj, String uri, int expect) {
index d9dd4fd..9480b6a 100644 (file)
@@ -149,7 +149,7 @@ class AafTopicSetupService extends BaseLoggingClass {
 
     private void removePermission(String permission, String instance, String action) throws TopicSetupException {
         DmaapPerm perm = new DmaapPerm(permission, instance, action);
 
     private void removePermission(String permission, String instance, String action) throws TopicSetupException {
         DmaapPerm perm = new DmaapPerm(permission, instance, action);
-        int rc = aafService.delPerm(perm);
+        int rc = aafService.delPerm(perm, true);
         if (rc != 200 && rc != 404) {
             throw new TopicSetupException(500,
                     format("Unexpected response from AAF: %d permission=%s instance=%s action=%s",
         if (rc != 200 && rc != 404) {
             throw new TopicSetupException(500,
                     format("Unexpected response from AAF: %d permission=%s instance=%s action=%s",
@@ -159,7 +159,7 @@ class AafTopicSetupService extends BaseLoggingClass {
 
     private void removeNamespace(Topic topic) throws TopicSetupException {
         AafNamespace ns = new AafNamespace(topic.getFqtn(), aafService.getIdentity());
 
     private void removeNamespace(Topic topic) throws TopicSetupException {
         AafNamespace ns = new AafNamespace(topic.getFqtn(), aafService.getIdentity());
-        int rc = aafService.delNamespace(ns);
+        int rc = aafService.delNamespace(ns, true);
         if (rc != 200 && rc != 404) {
             throw new TopicSetupException(500,
                     format("Unexpected response from AAF: %d namespace=%s identity=%s",
         if (rc != 200 && rc != 404) {
             throw new TopicSetupException(500,
                     format("Unexpected response from AAF: %d namespace=%s identity=%s",
index fd70a16..69b320a 100644 (file)
@@ -33,6 +33,7 @@ import static org.mockito.BDDMockito.given;
 import static org.mockito.BDDMockito.then;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.BDDMockito.then;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.verifyZeroInteractions;
 
 @RunWith(JUnitParamsRunner.class)
 import static org.mockito.Mockito.verifyZeroInteractions;
 
 @RunWith(JUnitParamsRunner.class)
@@ -165,4 +166,44 @@ public class AafServiceImplTest {
 
         assertEquals(aafServiceReturnedCode, status);
     }
 
         assertEquals(aafServiceReturnedCode, status);
     }
+
+    @Test
+    public void shouldDeletePermission() {
+        DmaapPerm perm = new DmaapPerm("permName", "type", "action");
+
+        int status = aafService.delPerm(perm, false);
+
+        then(aafConnection).should().delAaf(any(AafEmpty.class), eq(AAF_URL + "authz/perm/permName/type/action"));
+        assertEquals(OK, status);
+    }
+
+    @Test
+    public void shouldDeletePermissionWithForce() {
+        DmaapPerm perm = new DmaapPerm("permName", "type", "action");
+
+        int status = aafService.delPerm(perm, true);
+
+        then(aafConnection).should().delAaf(any(AafEmpty.class), eq(AAF_URL + "authz/perm/permName/type/action?force=true"));
+        assertEquals(OK, status);
+    }
+
+    @Test
+    public void shouldDeleteNamespace() {
+        AafNamespace ns = new AafNamespace("nsName", "ident");
+
+        int status = aafService.delNamespace(ns, false);
+
+        then(aafConnection).should().delAaf(any(AafEmpty.class), eq(AAF_URL + "authz/ns/nsName"));
+        assertEquals(OK, status);
+    }
+
+    @Test
+    public void shouldDeleteNamespaceWithForce() {
+        AafNamespace ns = new AafNamespace("nsName", "ident");
+
+        int status = aafService.delNamespace(ns, true);
+
+        then(aafConnection).should().delAaf(any(AafEmpty.class), eq(AAF_URL + "authz/ns/nsName?force=true"));
+        assertEquals(OK, status);
+    }
 }
\ No newline at end of file
 }
\ No newline at end of file
index 1317b97..8fd8c6f 100644 (file)
@@ -336,7 +336,7 @@ public class AafTopicSetupServiceTest {
         }
 
         @Override
         }
 
         @Override
-        public int delPerm(DmaapPerm perm) {
+        public int delPerm(DmaapPerm perm, boolean force) {
             removedPerms.add(perm);
             return removePermStatus;
         }
             removedPerms.add(perm);
             return removePermStatus;
         }
@@ -370,7 +370,7 @@ public class AafTopicSetupServiceTest {
         }
 
         @Override
         }
 
         @Override
-        public int delNamespace(AafNamespace namespace) {
+        public int delNamespace(AafNamespace namespace, boolean force) {
             this.removedNamespace = namespace;
             return removeNamespaceStatus;
         }
             this.removedNamespace = namespace;
             return removeNamespaceStatus;
         }