summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2019-02-13 15:44:48 +0000
committermark.j.leonard <mark.j.leonard@gmail.com>2019-02-13 15:47:23 +0000
commitcc5176bed8bb87fbe28f49eb7fe99f8a1fac01c0 (patch)
tree2c806540ac1acd87e73fdf5bdadbe54a48640df0 /src/main
parent563772ec9a100e9eb46fff1b5087985dbe07d04a (diff)
Add a JUnit test for the Data Dictionary
Create sample configuration for debugging the DataDictionary.java code. Fix an issue in the Rule Driven Validator: re-enable invocation of the default rules when no indexed rules are found for an event. Change-Id: I85fb6c0797e1240c14997b6e8ba1f6c0304152db Issue-ID: AAI-2057 Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/aai/validation/ruledriven/RuleDrivenValidator.java42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/main/java/org/onap/aai/validation/ruledriven/RuleDrivenValidator.java b/src/main/java/org/onap/aai/validation/ruledriven/RuleDrivenValidator.java
index cee29f7..57ace7d 100644
--- a/src/main/java/org/onap/aai/validation/ruledriven/RuleDrivenValidator.java
+++ b/src/main/java/org/onap/aai/validation/ruledriven/RuleDrivenValidator.java
@@ -1,20 +1,24 @@
-/*
- * ============LICENSE_START===================================================
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved.
* Copyright (c) 2018-2019 European Software Marketing Ltd.
- * ============================================================================
+ * ================================================================================
* 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
+ * 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=====================================================
+ * ============LICENSE_END=========================================================
*/
+
package org.onap.aai.validation.ruledriven;
import java.io.File;
@@ -55,7 +59,7 @@ import org.onap.aai.validation.ruledriven.rule.Rule;
import org.onap.aai.validation.ruledriven.rule.RuleResult;
/**
- * Validator using explicit rules
+ * Validator using explicit rules.
*
*/
public class RuleDrivenValidator implements Validator {
@@ -71,16 +75,16 @@ public class RuleDrivenValidator implements Validator {
// Map of event type name against RuleManager for that event type
private Map<String, RuleManager> ruleManagers;
-
/**
- * Construct a Validator that is configured using rule files
+ * Construct a Validator that is configured using rule files.
*
* @param configurationPath
- * path to the Groovy rules files
+ * path to the Groovy rules files
* @param oxmReader
- * required for validating entity types
+ * required for validating entity types
* @param eventReader
- * a reader for extracting entities from each event to be validated
+ * a reader for extracting entities from each event to be validated
+ * @param ruleIndexingConfig
*/
public RuleDrivenValidator(final Path configurationPath, final OxmReader oxmReader, final EventReader eventReader,
final RuleIndexingConfig ruleIndexingConfig) {
@@ -146,6 +150,7 @@ public class RuleDrivenValidator implements Validator {
/*
* (non-Javadoc)
+ *
* @see org.onap.aai.validation.Validator#validate(java.lang.String)
*/
@Override
@@ -224,8 +229,8 @@ public class RuleDrivenValidator implements Validator {
if (!rulesDefined && ruleIndexingConfig.isPresent()) {
final String defaultIndexKey = ruleIndexingConfig.get().getDefaultIndexKey();
- if (StringUtils.isEmpty(defaultIndexKey)) {
- return ruleManager.getRulesForEntity(RuleManager.generateKey(new String[] { defaultIndexKey }));
+ if (!StringUtils.isEmpty(defaultIndexKey)) {
+ return ruleManager.getRulesForEntity(RuleManager.generateKey(new String[] {defaultIndexKey}));
} else {
applicationLogger.debug("Default index value not configured, unable to get rules");
applicationLogger.error(ApplicationMsgs.CANNOT_VALIDATE_ERROR, eventType);
@@ -244,11 +249,10 @@ public class RuleDrivenValidator implements Validator {
return "";
}
try {
- AttributeValues attributeValues = entity.getAttributeValues(ruleIndexingConfig.get().getIndexAttributes());
- applicationLogger
- .debug("Generating index using attributes: " + attributeValues.generateReport().toString());
- Collection<Object> values = attributeValues.generateReport().values();
- return RuleManager.generateKey(values.stream().toArray(String[]::new));
+ Map<String, Object> valuesMap =
+ entity.getAttributeValues(ruleIndexingConfig.get().getIndexAttributes()).generateReport();
+ applicationLogger.debug("Generating index using attributes: " + valuesMap);
+ return RuleManager.generateKey(valuesMap.values().stream().toArray(String[]::new));
} catch (ValidationServiceException e) {
applicationLogger.debug("Failed to retrieve index key attributes from event: " + e.getMessage());
applicationLogger.error(ApplicationMsgs.CANNOT_VALIDATE_ERROR, e, eventType);
@@ -271,7 +275,7 @@ public class RuleDrivenValidator implements Validator {
* Read the text content of the specified Path and append this to the specified String
*
* @param sb
- * StringBuilder for the rule configuration text
+ * StringBuilder for the rule configuration text
* @return a Consumer function that appends file content
*/
private Consumer<? super Path> appendFileContent(StringBuilder sb) {