Improved the UT coverage 58/79058/1
authorGuangrongFu <fu.guangrong@zte.com.cn>
Sat, 23 Feb 2019 07:12:48 +0000 (15:12 +0800)
committerGuangrongFu <fu.guangrong@zte.com.cn>
Sat, 23 Feb 2019 07:12:48 +0000 (15:12 +0800)
Change-Id: I97c82fac9a9e11095c7d0eab4339ec9633a1090c
Issue-ID: HOLMES-203
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
16 files changed:
holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java
holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java
holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java
holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java
holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceEntity.java
holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java
holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode4Query.java
holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java
holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java
holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java
holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java
holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java
holmes-actions/src/test/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParserTest.java
holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java
holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java
pom.xml

index d60a31b..4cf2aba 100644 (file)
@@ -34,6 +34,9 @@ import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
 public class AaiQuery4Ccvpn {
 
     private MultivaluedMap<String, Object> headers;
@@ -42,6 +45,10 @@ public class AaiQuery4Ccvpn {
         return new AaiQuery4Ccvpn();
     }
 
+    private static final String EMPTY_STR = "";
+
+    private static final JSONObject EMPTY_JSON = new JSONObject();
+
     private AaiQuery4Ccvpn() {
         headers = new MultivaluedHashMap<>();
         headers.add("X-TransactionId", AaiConfig.X_TRANSACTION_ID);
@@ -71,6 +78,11 @@ public class AaiQuery4Ccvpn {
         Response response = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_LINK_QUERY, params)
                 + (status == null ? "" : String.format("&operational-status=%s", status)));
         JSONObject linkInfo = getInfo(response.readEntity(String.class), "p-interface", "logical-link");
+        if (linkInfo == null) {
+            log.warn(String.format("Link information is missing from AAI. Method: [getLogicLink], " +
+                    "params: [networkId - %s, pnfName - %s, ifName - %s].", networkId, pnfName, ifName));
+            return EMPTY_STR;
+        }
         return extractValueFromJsonArray(linkInfo.getJSONArray("relationship-data"), "logical-link.link-name");
     }
 
@@ -90,12 +102,30 @@ public class AaiQuery4Ccvpn {
     public JSONObject getServiceInstance(String networkId, String pnfName, String ifName, String status) {
         try {
             JSONObject vpnBindingInfo = getVpnBindingInfo(networkId, pnfName, ifName, status);
+            if (vpnBindingInfo == null) {
+                log.warn(String.format("VPN binding information is missing from AAI. " +
+                        "Method: [getServiceInstance], params: [networkId - %s, pnfName - %s, " +
+                        "ifName - %s, status - %s].", networkId, pnfName, ifName, status));
+                return EMPTY_JSON;
+            }
             String vpnBindingId = extractValueFromJsonArray(vpnBindingInfo.getJSONArray("relationship-data"),
-                                                            "vpn-binding.vpn-id");
+                    "vpn-binding.vpn-id");
             JSONObject connectivityInfo = getConnectivityInfo(vpnBindingId);
+            if (connectivityInfo == null) {
+                log.warn(String.format("Connectivity information is missing from AAI. " +
+                        "Method: [getServiceInstance], params: [networkId - %s, pnfName - %s, " +
+                        "ifName - %s, status - %s].", networkId, pnfName, ifName, status));
+                return EMPTY_JSON;
+            }
             String connectivityId = extractValueFromJsonArray(connectivityInfo.getJSONArray("relationship-data"),
-                                                              "connectivity.connectivity-id");
+                    "connectivity.connectivity-id");
             JSONObject serviceInstanceInfo = getServiceInstanceByConn(connectivityId);
+            if (serviceInstanceInfo == null) {
+                log.warn(String.format("Service instance information is missing from AAI. " +
+                        "Method: [getServiceInstance], params: [networkId - %s, pnfName - %s, " +
+                        "ifName - %s, status - %s].", networkId, pnfName, ifName, status));
+                return EMPTY_JSON;
+            }
             String serviceInstancePath = serviceInstanceInfo.getString("related-link");
 
             Response response = get(getHostAddr(), getPath(serviceInstancePath));
@@ -103,8 +133,8 @@ public class AaiQuery4Ccvpn {
 
             String[] params = new String[2];
             Pattern pattern = Pattern.compile("/aai/v\\d+/business/customers/customer/(.+)" +
-                                                      "/service-subscriptions/service-subscription/(.+)" +
-                                                      "/service-instances/service-instance/(.+)");
+                    "/service-subscriptions/service-subscription/(.+)" +
+                    "/service-instances/service-instance/(.+)");
             Matcher matcher = pattern.matcher(serviceInstancePath);
             if (matcher.find()) {
                 params[0] = matcher.group(1);
@@ -157,7 +187,7 @@ public class AaiQuery4Ccvpn {
 
     private JSONObject getServiceInstanceByConn(String connectivityId) throws CorrelationException {
         Response response = get(getHostAddr(), getPath(AaiConfig.MsbConsts.AAI_SERVICE_INSTANCE_ADDR_4_CCVPN,
-                                                       "connectivityId", connectivityId));
+                "connectivityId", connectivityId));
         return getInfo(response.readEntity(String.class), "connectivity", "service-instance");
     }
 
@@ -171,7 +201,7 @@ public class AaiQuery4Ccvpn {
 
     private String getPath(String urlTemplate, Map<String, String> pathParams) {
         String url = urlTemplate;
-        for(Map.Entry<String, String> entry : pathParams.entrySet()){
+        for (Map.Entry<String, String> entry : pathParams.entrySet()) {
             url = url.replaceAll("\\{" + entry.getKey() + "\\}", entry.getValue());
         }
         return url;
@@ -199,15 +229,15 @@ public class AaiQuery4Ccvpn {
             Response response = target.request().headers(getAaiHeaders()).get();
             if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
                 throw new CorrelationException("Failed to connect to AAI. \nCause: "
-                                                       + response.getStatusInfo().getReasonPhrase() + "\nDetails: \n"
-                                                       + getErrorMsg(String.format("%s%s", host, path), null, response));
+                        + response.getStatusInfo().getReasonPhrase() + "\nDetails: \n"
+                        + getErrorMsg(String.format("%s%s", host, path), null, response));
             }
             return response;
         } catch (CorrelationException e) {
             throw e;
         } catch (Exception e) {
             throw new CorrelationException(e.getMessage() + "More info: "
-                                                   + getErrorMsg(String.format("%s%s", host, path), null, null), e);
+                    + getErrorMsg(String.format("%s%s", host, path), null, null), e);
         }
     }
 
@@ -219,14 +249,14 @@ public class AaiQuery4Ccvpn {
                     .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true).invoke();
             if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
                 throw new CorrelationException("Failed to connect to AAI. \nCause: "
-                                                       + response.getStatusInfo().getReasonPhrase() + "\nDetails: \n"
-                                                       + getErrorMsg(String.format("%s%s", host, path), body, response));
+                        + response.getStatusInfo().getReasonPhrase() + "\nDetails: \n"
+                        + getErrorMsg(String.format("%s%s", host, path), body, response));
             }
         } catch (CorrelationException e) {
             throw e;
         } catch (Exception e) {
             throw new CorrelationException(e.getMessage() + "More info: "
-                                                   + getErrorMsg(String.format("%s%s", host, path), body, null), e);
+                    + getErrorMsg(String.format("%s%s", host, path), body, null), e);
         }
     }
 
@@ -272,10 +302,12 @@ public class AaiQuery4Ccvpn {
     }
 
     private String extractValueFromJsonArray(JSONArray relationshipData, String keyName) {
-        for (int i = 0; i < relationshipData.size(); ++i) {
-            JSONObject item = relationshipData.getJSONObject(i);
-            if (item.getString("relationship-key").equals(keyName)) {
-                return item.getString("relationship-value");
+        if (relationshipData != null) {
+            for (int i = 0; i < relationshipData.size(); ++i) {
+                JSONObject item = relationshipData.getJSONObject(i);
+                if (item.getString("relationship-key").equals(keyName)) {
+                    return item.getString("relationship-value");
+                }
             }
         }
         return null;
index fe1f677..c7881d1 100644 (file)
@@ -17,9 +17,12 @@ package org.onap.holmes.common.api.entity;
 \r
 import com.google.gson.annotations.SerializedName;\r
 import lombok.Data;\r
+import lombok.Getter;\r
 import lombok.NoArgsConstructor;\r
+import lombok.Setter;\r
 \r
-@Data\r
+@Getter\r
+@Setter\r
 @NoArgsConstructor\r
 public class AlarmInfo {\r
 \r
index 4cbd6bf..e21f97d 100644 (file)
@@ -18,9 +18,12 @@ package org.onap.holmes.common.api.entity;
 import com.google.gson.annotations.SerializedName;\r
 import java.util.Date;\r
 import lombok.Data;\r
+import lombok.Getter;\r
 import lombok.NoArgsConstructor;\r
+import lombok.Setter;\r
 \r
-@Data\r
+@Getter\r
+@Setter\r
 @NoArgsConstructor\r
 public class AlarmsCorrelation {\r
 \r
@@ -47,4 +50,18 @@ public class AlarmsCorrelation {
     private long reserve2 = -1;\r
 \r
     private long reserve3 = -1;\r
+\r
+    @Override\r
+    public String toString() {\r
+        StringBuilder sb = new StringBuilder("[");\r
+        sb.append("ruleId=").append(ruleId).append(",");\r
+        sb.append("ruleInfo=").append(ruleInfo).append(",");\r
+        sb.append("createTime=").append(createTime == null ? null : createTime.toString()).append(",");\r
+        sb.append("parentAlarmId=").append(parentAlarmId).append(",");\r
+        sb.append("childAlarmId=").append(childAlarmId).append(",");\r
+        sb.append("reserve1=").append(reserve1).append(",");\r
+        sb.append("reserve2=").append(reserve2).append(",");\r
+        sb.append("reserve3=").append(reserve3).append("]");\r
+        return sb.toString();\r
+    }\r
 }\r
index db6c19f..14a3f07 100644 (file)
@@ -61,23 +61,23 @@ public class CorrelationRule implements Cloneable {
             throw new InternalError(e);\r
         }\r
 \r
-        r.rid = rid == null ? null : rid;\r
-        r.name = name == null ? null : name;\r
-        r.description = description == null ? null : description;\r
+        r.rid = rid;\r
+        r.name = name;\r
+        r.description = description;\r
         r.enabled = enabled;\r
         r.templateID = templateID;\r
-        r.engineID = engineID == null ? null : engineID;\r
-        r.engineType = engineType == null ? null : engineType;\r
-        r.creator = creator == null ? null : creator;\r
-        r.modifier = modifier  == null ? null : modifier;\r
+        r.engineID = engineID;\r
+        r.engineType = engineType;\r
+        r.creator = creator;\r
+        r.modifier = modifier;\r
         r.params = params == null ? null : (Properties) params.clone();\r
-        r.content = content  == null ? null : content;\r
-        r.vendor = vendor  == null ? null : vendor;\r
+        r.content = content;\r
+        r.vendor = vendor;\r
         r.createTime = createTime == null ? null : (Date) createTime.clone();\r
         r.updateTime = updateTime == null ? null : (Date) updateTime.clone();\r
-        r.packageName = packageName == null ? null : packageName;\r
-        r.closedControlLoopName = closedControlLoopName == null ? null : closedControlLoopName;\r
-        r.engineInstance = engineInstance == null ? null : engineInstance;\r
+        r.packageName = packageName;\r
+        r.closedControlLoopName = closedControlLoopName;\r
+        r.engineInstance = engineInstance;\r
 \r
         return r;\r
     }\r
index 0244f84..4bfb3cf 100644 (file)
 package org.onap.holmes.common.api.entity;
 
 
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
+import lombok.*;
 
 import java.util.List;
 
-
-@Data
 @NoArgsConstructor
 @AllArgsConstructor
+@Getter
+@Setter
 public class ServiceEntity {
 
     private String serviceName;
index 205126d..98e5506 100644 (file)
  */
 package org.onap.holmes.common.api.entity;
 
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
+import lombok.*;
 
-@Data
+@Getter
+@Setter
 @NoArgsConstructor
 @AllArgsConstructor
 public class ServiceNode4Query {
index a8045ec..4b90dd7 100644 (file)
@@ -21,7 +21,6 @@ import java.util.HashMap;
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
-import lombok.NoArgsConstructor;\r
 \r
 public class DcaeConfigurations extends HashMap<String, Object>{\r
 \r
index e3f6e58..ba52262 100644 (file)
@@ -70,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", vmEntity.getInMaint());
-            } 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",
+            policyMsg.getAai().put("vserver.in-maint", vmEntity.getInMaint());
+            policyMsg.getAai().put("vserver.is-closed-loop-disabled",
                         vmEntity.getClosedLoopDisable());
-            } 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.prov-status", vmEntity.getProvStatus());
             policyMsg.getAai().put("vserver.resource-version", vmEntity.getResourceVersion());
         } else {
@@ -196,7 +186,7 @@ public class DmaapService {
                     break;
                 }
             }
-            log.info("Clear alarm, requestId deleted successful");
+            log.info("An alarm is cleared and the corresponding requestId is deleted successfully");
         }
     }
 }
index dd940c4..822d74c 100644 (file)
@@ -110,7 +110,6 @@ public class AlarmsCorrelationTest {
         assertThat(alarmsCorrelation.getReserve3(), equalTo(reserve3));
     }
 
-
     @Test
     public void testToString() throws Exception {
         final AlarmsCorrelation alarmsCorrelationTemp = new AlarmsCorrelation();
@@ -119,14 +118,4 @@ public class AlarmsCorrelationTest {
         alarmsCorrelation.setRuleId(ruleId);
         assertThat(alarmsCorrelation.toString(), equalTo(alarmsCorrelationTemp.toString()));
     }
-
-
-    @Test
-    public void testEqualsAndHashCode() throws Exception {
-        final AlarmsCorrelation alarmsCorrelationTemp = new AlarmsCorrelation();
-        String ruleId = "ruleId";
-        alarmsCorrelationTemp.setRuleId(ruleId);
-        alarmsCorrelation.setRuleId(ruleId);
-        assertThat(alarmsCorrelation, equalTo(alarmsCorrelationTemp));
-    }
-} 
+}
index 1a25a35..c4b605a 100644 (file)
@@ -150,4 +150,19 @@ public class CorrelationRuleTest {
         correlationRule.setEngineInstance(engineInstance);
         assertThat(correlationRule.getEngineInstance(), equalTo(engineInstance));
     }
+
+    @Test
+    public void getterAndSetter4ClosedControlLoopName(){
+        final String closedControlLoopName = "closedControlLoopName";
+        correlationRule.setClosedControlLoopName(closedControlLoopName);
+        assertThat(correlationRule.getClosedControlLoopName(), equalTo(closedControlLoopName));
+    }
+
+    @Test
+    public void testClone() {
+        final String rid = "rid";
+        correlationRule.setRid(rid);
+        CorrelationRule rule = (CorrelationRule) correlationRule.clone();
+        assertThat(rule.getRid(), equalTo(rid));
+    }
 } 
index 827220c..c441942 100644 (file)
@@ -27,12 +27,19 @@ import java.io.IOException;
 import java.net.URI;\r
 import java.net.URISyntaxException;\r
 import java.net.URL;\r
+\r
+import org.junit.Rule;\r
 import org.junit.Test;\r
+import org.junit.rules.ExpectedException;\r
 import org.onap.holmes.common.dcae.entity.DcaeConfigurations;\r
 import org.onap.holmes.common.dcae.entity.SecurityInfo;\r
+import org.onap.holmes.common.exception.CorrelationException;\r
 \r
 public class DcaeConfigurationParserTest {\r
 \r
+    @Rule\r
+    public ExpectedException thrown = ExpectedException.none();\r
+\r
     @Test\r
     public void parse() throws Exception {\r
         DcaeConfigurations obj = DcaeConfigurationParser.parse(readConfigurationsFromFile("dcae.config.json"));\r
@@ -43,6 +50,19 @@ public class DcaeConfigurationParserTest {
         assertThat(((SecurityInfo) obj.getPubSecInfo("sec_measurement")).getDmaapInfo().getLocation(), equalTo("mtl5"));\r
     }\r
 \r
+    @Test\r
+    public void parse_with_empty_contents_excption() throws CorrelationException {\r
+        thrown.expect(CorrelationException.class);\r
+        thrown.expectMessage("Can not resolve configurations from DCAE. The configuration string is empty.");\r
+        DcaeConfigurationParser.parse("");\r
+    }\r
+\r
+    @Test\r
+    public void parse_with_illegal_dcae_response_excption() throws CorrelationException {\r
+        thrown.expect(CorrelationException.class);\r
+        DcaeConfigurationParser.parse("This is an ordinary string.");\r
+    }\r
+\r
     private String readConfigurationsFromFile(String fileName) throws URISyntaxException, FileNotFoundException {\r
         URL url = DcaeConfigurationParserTest.class.getClassLoader().getResource(fileName);\r
         File configFile = new File(new URI(url.toString()).getPath());\r
index b47a16f..6494cd8 100644 (file)
@@ -18,11 +18,18 @@ package org.onap.holmes.common.dmaap;
 import static org.easymock.EasyMock.anyObject;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
 
+import java.io.*;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
+
+import org.easymock.EasyMock;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -34,6 +41,8 @@ import org.onap.holmes.common.aai.entity.RelationshipList.RelationshipData;
 import org.onap.holmes.common.aai.entity.VmEntity;
 import org.onap.holmes.common.aai.entity.VnfEntity;
 import org.onap.holmes.common.api.stat.VesAlarm;
+import org.onap.holmes.common.dcae.DcaeConfigurationsCache;
+import org.onap.holmes.common.dcae.utils.DcaeConfigurationParser;
 import org.onap.holmes.common.dmaap.entity.PolicyMsg;
 import org.onap.holmes.common.dmaap.entity.PolicyMsg.EVENT_STATUS;
 import org.onap.holmes.common.exception.CorrelationException;
@@ -183,7 +192,7 @@ public class DmaapServiceTest {
     }
 
     @Test
-    public void testDmaapService_getEnrichedPolicyMsg_ok() throws Exception {
+    public void testDmaapService_getEnrichedPolicyMsg_onset() throws Exception {
         PowerMock.resetAll();
         VmEntity vmEntity = new VmEntity();
         vmEntity.setInMaint(false);
@@ -204,9 +213,94 @@ public class DmaapServiceTest {
                 .invokeMethod(dmaapService, "getEnrichedPolicyMsg", vmEntity, vesAlarm, vesAlarm, "loopName");
         PowerMock.verifyAll();
 
-        assertThat(actual.getClosedLoopControlName(), equalTo(null));
+        assertThat(actual.getClosedLoopControlName(), nullValue());
         assertThat(actual.getAai().get("vserver.prov-status"), equalTo("prov"));
-        assertThat(actual.getAai().get("vserver.vserver-name2") == null, equalTo(true));
+        assertThat(actual.getAai().get("vserver.vserver-name2"), nullValue());
         assertThat(actual.getAai().get("generic-vnf.service-instance-id"), equalTo(""));
     }
+
+    @Test
+    public void testDmaapService_getEnrichedPolicyMsg_abated() throws Exception {
+        PowerMock.resetAll();
+        VmEntity vmEntity = new VmEntity();
+        vmEntity.setInMaint(false);
+        vmEntity.setClosedLoopDisable(true);
+        vmEntity.setProvStatus("prov");
+        vmEntity.setResourceVersion("kkkk");
+        VesAlarm vesAlarm = new VesAlarm();
+        vesAlarm.setEventId("11111");
+        vesAlarm.setEventName("3333");
+        vesAlarm.setSourceId("111");
+        vesAlarm.setStartEpochMicrosec(11111L);
+        vesAlarm.setLastEpochMicrosec(21111L);
+        vesAlarm.setAlarmIsCleared(PolicyMassgeConstant.POLICY_MESSAGE_ABATED);
+
+        PowerMock.expectPrivate(dmaapService, "getVnfEntity", anyObject(String.class),
+                anyObject(String.class)).andReturn(null).anyTimes();
+
+        PowerMock.replayAll();
+        PolicyMsg actual = Whitebox
+                .invokeMethod(dmaapService, "getEnrichedPolicyMsg", vmEntity, vesAlarm, vesAlarm, "loopName");
+        PowerMock.verifyAll();
+
+        assertThat(actual.getClosedLoopControlName(), nullValue());
+        assertThat(actual.getAai().get("vserver.prov-status"), nullValue());
+        assertThat(actual.getAai().get("vserver.vserver-name2"), nullValue());
+        assertThat(actual.getAai().get("generic-vnf.service-instance-id"), nullValue());
+    }
+
+    @Test
+    public void testPublishPolicyMsg_onset() throws Exception {
+        PowerMock.resetAll();
+        Publisher publisher = PowerMock.createPartialMock(Publisher.class, "publish", PolicyMsg.class);
+        PolicyMsg policyMsg = new PolicyMsg();
+        policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ONSET);
+        PowerMock.expectNew(Publisher.class).andReturn(publisher);
+        EasyMock.expect(publisher.publish(policyMsg)).andReturn(true);
+
+        DcaeConfigurationsCache.setDcaeConfigurations(
+                DcaeConfigurationParser.parse(readConfigurationsFromFile("dcae.config.json")));
+
+        PowerMock.replayAll();
+        dmaapService.publishPolicyMsg(policyMsg, "sec_fault_unsecure");
+        PowerMock.verifyAll();
+
+    }
+
+    @Test
+    public void testPublishPolicyMsg_abated() throws Exception {
+        PowerMock.resetAll();
+        Publisher publisher = PowerMock.createPartialMock(Publisher.class, "publish", PolicyMsg.class);
+        PolicyMsg policyMsg = new PolicyMsg();
+        policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ABATED);
+        policyMsg.setRequestID("testRequestid");
+        DmaapService.alarmUniqueRequestID.put("testAlarmId", "testRequestid");
+        PowerMock.expectNew(Publisher.class).andReturn(publisher);
+        EasyMock.expect(publisher.publish(policyMsg)).andReturn(true);
+
+        DcaeConfigurationsCache.setDcaeConfigurations(
+                DcaeConfigurationParser.parse(readConfigurationsFromFile("dcae.config.json")));
+
+        PowerMock.replayAll();
+        dmaapService.publishPolicyMsg(policyMsg, "sec_fault_unsecure");
+        PowerMock.verifyAll();
+
+    }
+
+    private String readConfigurationsFromFile(String fileName) throws URISyntaxException, FileNotFoundException {
+        URL url = DmaapServiceTest.class.getClassLoader().getResource(fileName);
+        File configFile = new File(new URI(url.toString()).getPath());
+        BufferedReader br = new BufferedReader(new FileReader(configFile));
+
+        final StringBuilder sb = new StringBuilder();
+        br.lines().forEach(line -> {
+            sb.append(line);
+        });
+        try {
+            br.close();
+        } catch (IOException e) {
+            // Do nothing
+        }
+        return sb.toString();
+    }
 }
\ No newline at end of file
index 76aad81..ab75e06 100644 (file)
@@ -35,6 +35,7 @@ public class MSBRegisterUtilTest {
 \r
     @Rule\r
     public PowerMockRule powerMockRule = new PowerMockRule();\r
+\r
     private MSBRegisterUtil msbRegisterUtil = new MSBRegisterUtil();\r
 \r
     @Test\r
diff --git a/pom.xml b/pom.xml
index c7cb10c..8135422 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\r
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>\r
         <maven.test.skip>false</maven.test.skip>\r
+        <powermock.version>1.7.1</powermock.version>\r
         <maven.test.failure.ignore>false</maven.test.failure.ignore>\r
         <finalName>${project.artifactId}-${project.version}</finalName>\r
         <release.dir>${basedir}/target</release.dir>\r
         <bundle.name>${project.artifactId}-${project.version}</bundle.name>\r
         <pkgzip.dir>${basedir}/../release/pkgzip</pkgzip.dir>\r
         <excludesFile>**/*$*</excludesFile>\r
-        <nexusproxy>https://nexus.open-o.org/content</nexusproxy>\r
 \r
         <stringtemplate.version>3.2.1</stringtemplate.version>\r
         <dropwizard.version>1.3.0</dropwizard.version>\r
@@ -46,6 +46,7 @@
         <slf4j.version>1.7.25</slf4j.version>\r
         <quartz.version>2.2.1</quartz.version>\r
     </properties>\r
+\r
     <dependencyManagement>\r
         <dependencies>\r
             <dependency>\r
             <dependency>\r
                 <groupId>org.powermock</groupId>\r
                 <artifactId>powermock-module-junit4</artifactId>\r
-                <version>1.6.5</version>\r
+                <version>${powermock.version}</version>\r
                 <scope>test</scope>\r
             </dependency>\r
             <dependency>\r
             <dependency>\r
                 <groupId>org.powermock</groupId>\r
                 <artifactId>powermock-api-easymock</artifactId>\r
-                <version>1.6.5</version>\r
+                <version>${powermock.version}</version>\r
                 <scope>test</scope>\r
             </dependency>\r
             <dependency>\r
                 <groupId>org.powermock</groupId>\r
                 <artifactId>powermock-api-mockito</artifactId>\r
-                <version>1.7.1</version>\r
+                <version>${powermock.version}</version>\r
                 <scope>test</scope>\r
             </dependency>\r
             <dependency>\r
                 <groupId>org.powermock</groupId>\r
                 <artifactId>powermock-module-junit4-rule</artifactId>\r
-                <version>1.6.5</version>\r
+                <version>${powermock.version}</version>\r
                 <scope>test</scope>\r
             </dependency>\r
             <dependency>\r
                 <groupId>org.powermock</groupId>\r
                 <artifactId>powermock-classloading-xstream</artifactId>\r
-                <version>1.6.5</version>\r
+                <version>${powermock.version}</version>\r
                 <scope>test</scope>\r
             </dependency>\r
             <dependency>\r