summaryrefslogtreecommitdiffstats
path: root/feature-mdc-filters/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-07-24 17:03:32 -0400
committerJim Hahn <jrh3@att.com>2019-07-24 17:07:12 -0400
commit3f0f00395ebcfa9fd37765efddb82573588d1263 (patch)
tree56c2bb6b53f49165f2c693fe89259e7020a4313b /feature-mdc-filters/src/main
parentb08aaddaef7e3ca4248132365859a9a0da712148 (diff)
Add junit coverage to feature-mdc-filters
Change-Id: Idb1946c60d550deece25d2cc74131242ccc4c376 Issue-ID: POLICY-1772 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'feature-mdc-filters/src/main')
-rwxr-xr-xfeature-mdc-filters/src/main/java/org/onap/policy/drools/mdc/filters/MdcTopicFilter.java45
1 files changed, 22 insertions, 23 deletions
diff --git a/feature-mdc-filters/src/main/java/org/onap/policy/drools/mdc/filters/MdcTopicFilter.java b/feature-mdc-filters/src/main/java/org/onap/policy/drools/mdc/filters/MdcTopicFilter.java
index d0813a93..7aa0a920 100755
--- a/feature-mdc-filters/src/main/java/org/onap/policy/drools/mdc/filters/MdcTopicFilter.java
+++ b/feature-mdc-filters/src/main/java/org/onap/policy/drools/mdc/filters/MdcTopicFilter.java
@@ -20,11 +20,13 @@
package org.onap.policy.drools.mdc.filters;
+import com.att.aft.dme2.internal.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import lombok.Getter;
import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +40,7 @@ public class MdcTopicFilter {
private Map<String, FilterRule> rules = new HashMap<>();
+ @Getter
public static class FilterRule {
private String mdcKey;
private List<String> paths;
@@ -58,37 +61,29 @@ public class MdcTopicFilter {
this.paths = paths;
}
- public String getMdcKey() {
- return mdcKey;
- }
-
- public List<String> getPaths() {
- return paths;
- }
-
protected void setMdcKey(String mdcKey) {
- if (mdcKey == null || mdcKey.isEmpty()) {
+ if (StringUtils.isBlank(mdcKey)) {
throw new IllegalArgumentException(MDC_KEY_ERROR);
}
this.mdcKey = mdcKey;
}
protected void setPaths(List<String> paths) {
- if (paths == null || paths.isEmpty()) {
+ if (nullOrEmpty(paths)) {
throw new IllegalArgumentException(JSON_PATH_ERROR);
}
this.paths = paths;
}
protected void addPaths(List<String> paths) {
- if (paths == null || paths.isEmpty()) {
+ if (nullOrEmpty(paths)) {
throw new IllegalArgumentException(JSON_PATH_ERROR);
}
this.paths.addAll(paths);
}
protected void addPath(String path) {
- if (path == null || path.isEmpty()) {
+ if (StringUtils.isBlank(path)) {
throw new IllegalArgumentException(JSON_PATH_ERROR);
}
this.paths.add(path);
@@ -130,7 +125,7 @@ public class MdcTopicFilter {
* @return the filter rule associated with the key
*/
protected FilterRule getFilterRule(String mdcKey) {
- if (mdcKey == null || mdcKey.isEmpty()) {
+ if (StringUtils.isBlank(mdcKey)) {
throw new IllegalArgumentException(MDC_KEY_ERROR);
}
return rules.get(mdcKey);
@@ -144,7 +139,7 @@ public class MdcTopicFilter {
* @return the filter rule that was added for the topic
*/
protected FilterRule addFilterRule(String mdcKey, String path) {
- if (path == null || path.isEmpty()) {
+ if (StringUtils.isBlank(path)) {
throw new IllegalArgumentException(JSON_PATH_ERROR);
}
return addFilterRule(mdcKey, Arrays.asList(path));
@@ -158,11 +153,11 @@ public class MdcTopicFilter {
* @return the filter rule that was added for the topic
*/
protected FilterRule addFilterRule(String mdcKey, List<String> paths) {
- if (mdcKey == null || mdcKey.isEmpty()) {
+ if (StringUtils.isBlank(mdcKey)) {
throw new IllegalArgumentException(MDC_KEY_ERROR);
}
- if (paths == null || paths.isEmpty()) {
+ if (nullOrEmpty(paths)) {
throw new IllegalArgumentException(JSON_PATH_ERROR);
}
@@ -175,6 +170,10 @@ public class MdcTopicFilter {
return rule;
}
+ private static boolean nullOrEmpty(List<String> paths) {
+ return paths == null || paths.isEmpty();
+ }
+
/**
* Modifies an existing filter rule by adding the specified path.
*
@@ -183,7 +182,7 @@ public class MdcTopicFilter {
* @return the filter rule that was modified
*/
protected FilterRule modifyFilterRule(String mdcKey, String path) {
- if (path == null || path.isEmpty()) {
+ if (StringUtils.isBlank(path)) {
throw new IllegalArgumentException(JSON_PATH_ERROR);
}
return modifyFilterRule(mdcKey, Arrays.asList(path));
@@ -197,11 +196,11 @@ public class MdcTopicFilter {
* @return the filter rule that was modified
*/
protected FilterRule modifyFilterRule(String mdcKey, List<String> paths) {
- if (mdcKey == null || mdcKey.isEmpty()) {
+ if (StringUtils.isBlank(mdcKey)) {
throw new IllegalArgumentException(MDC_KEY_ERROR);
}
- if (paths == null || paths.isEmpty()) {
+ if (nullOrEmpty(paths)) {
throw new IllegalArgumentException(JSON_PATH_ERROR);
}
@@ -224,18 +223,18 @@ public class MdcTopicFilter {
* @return the filter rule that was modified
*/
protected FilterRule modifyFilterRule(String oldMdcKey, String newMdcKey, List<String> paths) {
- if (oldMdcKey == null || oldMdcKey.isEmpty()) {
+ if (StringUtils.isBlank(oldMdcKey)) {
throw new IllegalArgumentException("current mdcKey must be provided");
}
- if (newMdcKey == null || newMdcKey.isEmpty()) {
+ if (StringUtils.isBlank(newMdcKey)) {
throw new IllegalArgumentException("new mdcKey must be provided");
}
if (oldMdcKey.equals(newMdcKey)) {
throw new IllegalArgumentException("the old and new mdcKey are equivalent");
}
- if (paths == null || paths.isEmpty()) {
+ if (nullOrEmpty(paths)) {
throw new IllegalArgumentException(JSON_PATH_ERROR);
}
@@ -268,7 +267,7 @@ public class MdcTopicFilter {
* @return the filter rule that was deleted
*/
protected FilterRule deleteFilterRule(String mdcKey) {
- if (mdcKey == null || mdcKey.isEmpty()) {
+ if (StringUtils.isBlank(mdcKey)) {
throw new IllegalArgumentException(MDC_KEY_ERROR);
}
return rules.remove(mdcKey);