deleting namespace and permission implementation

Change-Id: If9e3dc12da186cfee42ae0816e39ba868cb82ad5
Issue-ID: DMAAP-1217
Signed-off-by: piotr.karas <piotr.karas@nokia.com>
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
index 0000000..87e56c4
--- /dev/null
+++ b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafEmpty.java
@@ -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 "";
+    }
+}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/aaf/AafService.java b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafService.java
index 2444d49..c49ffb6 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/aaf/AafService.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafService.java
@@ -33,7 +33,7 @@
 
     int addPerm(DmaapPerm perm);
 
-    int delPerm(DmaapPerm perm);
+    int delPerm(DmaapPerm perm, boolean force);
 
     int addGrant(DmaapGrant grant);
 
@@ -45,5 +45,5 @@
 
     int addNamespace(AafNamespace ns);
 
-    int delNamespace(AafNamespace ns);
+    int delNamespace(AafNamespace ns, boolean force);
 }
diff --git a/src/main/java/org/onap/dmaap/dbcapi/aaf/AafServiceImpl.java b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafServiceImpl.java
index edce4f0..4848a69 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/aaf/AafServiceImpl.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafServiceImpl.java
@@ -23,10 +23,13 @@
 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;
+    private static final String FORCE = "?force=true";
     private final String aafUrl;
     private final String identity;
     private final boolean useAAF;
@@ -51,8 +54,11 @@
     }
 
     @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
@@ -86,8 +92,11 @@
     }
 
     @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) {
diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/AafTopicSetupService.java b/src/main/java/org/onap/dmaap/dbcapi/service/AafTopicSetupService.java
index d9dd4fd..9480b6a 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/service/AafTopicSetupService.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/service/AafTopicSetupService.java
@@ -149,7 +149,7 @@
 
     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",
@@ -159,7 +159,7 @@
 
     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",
diff --git a/src/test/java/org/onap/dmaap/dbcapi/aaf/AafServiceImplTest.java b/src/test/java/org/onap/dmaap/dbcapi/aaf/AafServiceImplTest.java
index fd70a16..69b320a 100644
--- a/src/test/java/org/onap/dmaap/dbcapi/aaf/AafServiceImplTest.java
+++ b/src/test/java/org/onap/dmaap/dbcapi/aaf/AafServiceImplTest.java
@@ -33,6 +33,7 @@
 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)
@@ -165,4 +166,44 @@
 
         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
diff --git a/src/test/java/org/onap/dmaap/dbcapi/service/AafTopicSetupServiceTest.java b/src/test/java/org/onap/dmaap/dbcapi/service/AafTopicSetupServiceTest.java
index 1317b97..8fd8c6f 100644
--- a/src/test/java/org/onap/dmaap/dbcapi/service/AafTopicSetupServiceTest.java
+++ b/src/test/java/org/onap/dmaap/dbcapi/service/AafTopicSetupServiceTest.java
@@ -336,7 +336,7 @@
         }
 
         @Override
-        public int delPerm(DmaapPerm perm) {
+        public int delPerm(DmaapPerm perm, boolean force) {
             removedPerms.add(perm);
             return removePermStatus;
         }
@@ -370,7 +370,7 @@
         }
 
         @Override
-        public int delNamespace(AafNamespace namespace) {
+        public int delNamespace(AafNamespace namespace, boolean force) {
             this.removedNamespace = namespace;
             return removeNamespaceStatus;
         }