summaryrefslogtreecommitdiffstats
path: root/holmes-actions/src
diff options
context:
space:
mode:
authorGuangrongFu <fu.guangrong@zte.com.cn>2019-02-23 15:12:48 +0800
committerGuangrongFu <fu.guangrong@zte.com.cn>2019-02-23 15:12:48 +0800
commit953aee4dbbed4ce9edae8ca9914290b3164b077a (patch)
tree86626a68cb0ca74cf7e2d07977326242f51af420 /holmes-actions/src
parent76e5d677724b13160bb3360b734239192b7be20e (diff)
Improved the UT coverage
Change-Id: I97c82fac9a9e11095c7d0eab4339ec9633a1090c Issue-ID: HOLMES-203 Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'holmes-actions/src')
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java64
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java5
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java19
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java24
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceEntity.java8
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java1
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode4Query.java7
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java1
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java1
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java16
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java13
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java15
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParserTest.java20
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java100
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java1
15 files changed, 225 insertions, 70 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java
index d60a31b..4cf2aba 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn.java
@@ -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;
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java
index fe1f677..c7881d1 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmInfo.java
@@ -17,9 +17,12 @@ package org.onap.holmes.common.api.entity;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
+import lombok.Getter;
import lombok.NoArgsConstructor;
+import lombok.Setter;
-@Data
+@Getter
+@Setter
@NoArgsConstructor
public class AlarmInfo {
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java
index 4cbd6bf..e21f97d 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java
@@ -18,9 +18,12 @@ package org.onap.holmes.common.api.entity;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
import lombok.Data;
+import lombok.Getter;
import lombok.NoArgsConstructor;
+import lombok.Setter;
-@Data
+@Getter
+@Setter
@NoArgsConstructor
public class AlarmsCorrelation {
@@ -47,4 +50,18 @@ public class AlarmsCorrelation {
private long reserve2 = -1;
private long reserve3 = -1;
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("[");
+ sb.append("ruleId=").append(ruleId).append(",");
+ sb.append("ruleInfo=").append(ruleInfo).append(",");
+ sb.append("createTime=").append(createTime == null ? null : createTime.toString()).append(",");
+ sb.append("parentAlarmId=").append(parentAlarmId).append(",");
+ sb.append("childAlarmId=").append(childAlarmId).append(",");
+ sb.append("reserve1=").append(reserve1).append(",");
+ sb.append("reserve2=").append(reserve2).append(",");
+ sb.append("reserve3=").append(reserve3).append("]");
+ return sb.toString();
+ }
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java
index db6c19f..14a3f07 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/CorrelationRule.java
@@ -61,23 +61,23 @@ public class CorrelationRule implements Cloneable {
throw new InternalError(e);
}
- r.rid = rid == null ? null : rid;
- r.name = name == null ? null : name;
- r.description = description == null ? null : description;
+ r.rid = rid;
+ r.name = name;
+ r.description = description;
r.enabled = enabled;
r.templateID = templateID;
- r.engineID = engineID == null ? null : engineID;
- r.engineType = engineType == null ? null : engineType;
- r.creator = creator == null ? null : creator;
- r.modifier = modifier == null ? null : modifier;
+ r.engineID = engineID;
+ r.engineType = engineType;
+ r.creator = creator;
+ r.modifier = modifier;
r.params = params == null ? null : (Properties) params.clone();
- r.content = content == null ? null : content;
- r.vendor = vendor == null ? null : vendor;
+ r.content = content;
+ r.vendor = vendor;
r.createTime = createTime == null ? null : (Date) createTime.clone();
r.updateTime = updateTime == null ? null : (Date) updateTime.clone();
- r.packageName = packageName == null ? null : packageName;
- r.closedControlLoopName = closedControlLoopName == null ? null : closedControlLoopName;
- r.engineInstance = engineInstance == null ? null : engineInstance;
+ r.packageName = packageName;
+ r.closedControlLoopName = closedControlLoopName;
+ r.engineInstance = engineInstance;
return r;
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceEntity.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceEntity.java
index 0244f84..4bfb3cf 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceEntity.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceEntity.java
@@ -16,16 +16,14 @@
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;
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java
index 2c2b793..a8fc04d 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode.java
@@ -23,7 +23,6 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
-@Data
@NoArgsConstructor
@AllArgsConstructor
@Getter
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode4Query.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode4Query.java
index 205126d..98e5506 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode4Query.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceNode4Query.java
@@ -15,11 +15,10 @@
*/
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 {
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java
index f5dca01..eba7544 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/ServiceRegisterEntity.java
@@ -24,7 +24,6 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
-@Data
@NoArgsConstructor
@AllArgsConstructor
@Setter
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java
index a8045ec..4b90dd7 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/dcae/entity/DcaeConfigurations.java
@@ -21,7 +21,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import lombok.NoArgsConstructor;
public class DcaeConfigurations extends HashMap<String, Object>{
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java
index e3f6e58..ba52262 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java
@@ -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");
}
}
}
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java
index dd940c4..822d74c 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/AlarmsCorrelationTest.java
@@ -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));
- }
-}
+}
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java
index 1a25a35..c4b605a 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/entity/CorrelationRuleTest.java
@@ -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));
+ }
}
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParserTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParserTest.java
index 827220c..c441942 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParserTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/dcae/utils/DcaeConfigurationParserTest.java
@@ -27,12 +27,19 @@ import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
import org.onap.holmes.common.dcae.entity.SecurityInfo;
+import org.onap.holmes.common.exception.CorrelationException;
public class DcaeConfigurationParserTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
@Test
public void parse() throws Exception {
DcaeConfigurations obj = DcaeConfigurationParser.parse(readConfigurationsFromFile("dcae.config.json"));
@@ -43,6 +50,19 @@ public class DcaeConfigurationParserTest {
assertThat(((SecurityInfo) obj.getPubSecInfo("sec_measurement")).getDmaapInfo().getLocation(), equalTo("mtl5"));
}
+ @Test
+ public void parse_with_empty_contents_excption() throws CorrelationException {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Can not resolve configurations from DCAE. The configuration string is empty.");
+ DcaeConfigurationParser.parse("");
+ }
+
+ @Test
+ public void parse_with_illegal_dcae_response_excption() throws CorrelationException {
+ thrown.expect(CorrelationException.class);
+ DcaeConfigurationParser.parse("This is an ordinary string.");
+ }
+
private String readConfigurationsFromFile(String fileName) throws URISyntaxException, FileNotFoundException {
URL url = DcaeConfigurationParserTest.class.getClassLoader().getResource(fileName);
File configFile = new File(new URI(url.toString()).getPath());
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java
index b47a16f..6494cd8 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java
@@ -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
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java
index 76aad81..ab75e06 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/utils/MSBRegisterUtilTest.java
@@ -35,6 +35,7 @@ public class MSBRegisterUtilTest {
@Rule
public PowerMockRule powerMockRule = new PowerMockRule();
+
private MSBRegisterUtil msbRegisterUtil = new MSBRegisterUtil();
@Test