Improved the UT coverage
[holmes/common.git] / holmes-actions / src / main / java / org / onap / holmes / common / dmaap / DmaapService.java
index f19b89c..ba52262 100644 (file)
@@ -15,6 +15,7 @@
  */
 package org.onap.holmes.common.dmaap;
 
+import java.util.Map.Entry;
 import java.util.Optional;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
@@ -69,19 +70,9 @@ public class DmaapService {
         if (rootAlarm.getAlarmIsCleared() == PolicyMassgeConstant.POLICY_MESSAGE_ONSET) {
             enrichVnfInfo(vmEntity, childAlarm, policyMsg);
             policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ONSET);
-            try {
-                policyMsg.getAai().put("vserver.in-maint", Boolean.valueOf(vmEntity.getInMaint()).booleanValue());
-            } catch (Exception e) {
-                log.error("Failed to parse the field \"in-maint\". A boolean string (\"true\"/\"false\")"
-                        + " is expected but the actual value is " + vmEntity.getInMaint() + ".", e);
-            }
-            try {
-                policyMsg.getAai().put("vserver.is-closed-loop-disabled",
-                        Boolean.valueOf(vmEntity.getClosedLoopDisable()).booleanValue());
-            } catch (Exception e) {
-                log.error("Failed to parse the field \"is-closed-loop-disabled\". A boolean string (\"true\"/\"false\")"
-                        + " is expected but the actual value is " + vmEntity.getClosedLoopDisable() + ".", e);
-            }
+            policyMsg.getAai().put("vserver.in-maint", vmEntity.getInMaint());
+            policyMsg.getAai().put("vserver.is-closed-loop-disabled",
+                        vmEntity.getClosedLoopDisable());
             policyMsg.getAai().put("vserver.prov-status", vmEntity.getProvStatus());
             policyMsg.getAai().put("vserver.resource-version", vmEntity.getResourceVersion());
         } else {
@@ -186,15 +177,16 @@ public class DmaapService {
     }
 
     private void deleteRequestId(PolicyMsg policyMsg){
-        String status = policyMsg.getClosedLoopEventStatus().toString();
-        if(status == "ABATED"){
+       EVENT_STATUS status = policyMsg.getClosedLoopEventStatus();
+        if(EVENT_STATUS.ABATED.equals(status)) {
             String requestId = policyMsg.getRequestID();
-            for(String key: alarmUniqueRequestID.keySet()){
-                if(alarmUniqueRequestID.get(key).equals(requestId)){
-                    alarmUniqueRequestID.remove(key);
+            for(Entry<String, String> kv: alarmUniqueRequestID.entrySet()) {
+                if(kv.getValue().equals(requestId)) {
+                    alarmUniqueRequestID.remove(kv.getKey());
+                    break;
                 }
             }
-            log.info("Clear alarm, requestId deleted successful");
+            log.info("An alarm is cleared and the corresponding requestId is deleted successfully");
         }
     }
 }