summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/aai/validation/controller/ValidationController.java9
-rw-r--r--src/main/java/org/onap/aai/validation/modeldriven/validator/ModelDrivenValidator.java11
-rw-r--r--src/main/java/org/onap/aai/validation/result/ValidationResult.java220
-rw-r--r--src/main/java/org/onap/aai/validation/result/ValidationResultBuilder.java55
-rw-r--r--src/main/java/org/onap/aai/validation/result/ValidationResultImpl.java255
-rw-r--r--src/main/java/org/onap/aai/validation/ruledriven/RuleDrivenValidator.java38
-rw-r--r--src/main/java/org/onap/aai/validation/ruledriven/RuleManager.java13
-rw-r--r--src/test/java/org/onap/aai/validation/controller/TestValidationController.java87
-rw-r--r--src/test/java/org/onap/aai/validation/publisher/MockEventPublisher.java13
-rw-r--r--src/test/java/org/onap/aai/validation/result/TestValidationResult.java105
-rw-r--r--src/test/java/org/onap/aai/validation/ruledriven/rule/TestConfigurationLoader.java3
-rw-r--r--src/test/java/org/onap/aai/validation/test/util/TestEntity.java13
-rw-r--r--src/test/java/org/onap/aai/validation/test/util/ValidationResultIsEqual.java10
13 files changed, 493 insertions, 339 deletions
diff --git a/src/main/java/org/onap/aai/validation/controller/ValidationController.java b/src/main/java/org/onap/aai/validation/controller/ValidationController.java
index 15e35b1..bd7c850 100644
--- a/src/main/java/org/onap/aai/validation/controller/ValidationController.java
+++ b/src/main/java/org/onap/aai/validation/controller/ValidationController.java
@@ -1,12 +1,12 @@
-/*
+/**
* ============LICENSE_START===================================================
- * Copyright (c) 2018 Amdocs
+ * 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,
@@ -42,6 +42,7 @@ import org.onap.aai.validation.publisher.MessagePublisher;
import org.onap.aai.validation.reader.EventReader;
import org.onap.aai.validation.reader.data.Entity;
import org.onap.aai.validation.result.ValidationResult;
+import org.onap.aai.validation.result.ValidationResultBuilder;
import org.onap.aai.validation.result.Violation;
import org.onap.aai.validation.util.JsonUtil;
@@ -105,7 +106,7 @@ public class ValidationController {
Entity entity = eventReader.getEntity(event);
if (!entity.getIds().isEmpty() && eventReader.getEntityType(event).isPresent()
&& entity.getResourceVersion().isPresent()) {
- ValidationResult validationResult = new ValidationResult(entity);
+ ValidationResult validationResult = new ValidationResultBuilder(eventReader, event).build();
// @formatter:off
validationResult.addViolation(new Violation.Builder(entity)
.category(VALIDATION_ERROR_CATEGORY)
diff --git a/src/main/java/org/onap/aai/validation/modeldriven/validator/ModelDrivenValidator.java b/src/main/java/org/onap/aai/validation/modeldriven/validator/ModelDrivenValidator.java
index 1b8ab00..ef27f40 100644
--- a/src/main/java/org/onap/aai/validation/modeldriven/validator/ModelDrivenValidator.java
+++ b/src/main/java/org/onap/aai/validation/modeldriven/validator/ModelDrivenValidator.java
@@ -1,12 +1,12 @@
-/*
+/**
* ============LICENSE_START===================================================
- * Copyright (c) 2018 Amdocs
+ * 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,
@@ -36,14 +36,15 @@ import org.onap.aai.validation.exception.ValidationServiceException;
import org.onap.aai.validation.modeldriven.ModelCacheManager;
import org.onap.aai.validation.modeldriven.ModelId;
import org.onap.aai.validation.modeldriven.configuration.mapping.ModelInstanceMapper;
-import org.onap.aai.validation.modeldriven.configuration.mapping.ModelInstanceMappingReader;
import org.onap.aai.validation.modeldriven.configuration.mapping.ModelInstanceMapper.MappingType;
+import org.onap.aai.validation.modeldriven.configuration.mapping.ModelInstanceMappingReader;
import org.onap.aai.validation.reader.EntityReader;
import org.onap.aai.validation.reader.EventReader;
import org.onap.aai.validation.reader.InstanceEntityReader;
import org.onap.aai.validation.reader.data.Entity;
import org.onap.aai.validation.reader.data.EntityId;
import org.onap.aai.validation.result.ValidationResult;
+import org.onap.aai.validation.result.ValidationResultBuilder;
import org.onap.aai.validation.result.Violation;
import org.onap.aai.validation.result.Violation.Builder;
import org.onap.aai.validation.result.Violation.ViolationType;
@@ -148,7 +149,7 @@ public class ModelDrivenValidator implements Validator {
}
}
- ValidationResult validationResult = new ValidationResult(instanceEntity);
+ ValidationResult validationResult = new ValidationResultBuilder(instanceEntity).build();
// This is a shortcut to passing the parent model name all the way down.
populateViolationModelNames(violations, instanceEntity);
diff --git a/src/main/java/org/onap/aai/validation/result/ValidationResult.java b/src/main/java/org/onap/aai/validation/result/ValidationResult.java
index b632a0f..9526c03 100644
--- a/src/main/java/org/onap/aai/validation/result/ValidationResult.java
+++ b/src/main/java/org/onap/aai/validation/result/ValidationResult.java
@@ -1,12 +1,12 @@
-/*
+/**
* ============LICENSE_START===================================================
- * Copyright (c) 2018 Amdocs
+ * 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,
@@ -18,227 +18,47 @@
package org.onap.aai.validation.result;
import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.gson.annotations.Expose;
-import java.time.Instant;
-import java.time.ZoneOffset;
-import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
import java.util.List;
-import java.util.Objects;
-import java.util.UUID;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.onap.aai.validation.exception.ValidationServiceException;
-import org.onap.aai.validation.reader.data.Entity;
-import org.onap.aai.validation.reader.data.EntityId;
-import org.onap.aai.validation.util.JsonUtil;
-
-/**
- * The result of an instance validation. This can include zero or more {@link Violation} objects.
- */
-public class ValidationResult {
-
- @Expose
- private String validationId;
- @Expose
- private String validationTimestamp;
+public interface ValidationResult {
- @Expose
- private JsonElement entityId;
+ List<Violation> getViolations();
- @Expose
- private String entityType;
+ JsonElement getEntityId();
- @Expose
- private String entityLink;
+ String getEntityLink();
- @Expose
- private String resourceVersion;
-
- @Expose
- private JsonElement entity;
+ String getEntityType();
-
- @Expose
- private List<Violation> violations = new ArrayList<>();
-
- /**
- * Create the validation payload initialised with an event identifier and a timestamp.
- *
- * @param entity
- * @throws ValidationServiceException
- */
- public ValidationResult(Entity entity) throws ValidationServiceException {
- this.validationId = UUID.randomUUID().toString();
- this.validationTimestamp =
- DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX").withZone(ZoneOffset.UTC).format(Instant.now());
- this.entityId = new JsonObject();
- for (EntityId id : entity.getIds()) {
- this.entityId.getAsJsonObject().addProperty(id.getPrimaryKey(), id.getValue());
- }
- this.entityType = entity.getType();
- this.entityLink = entity.getEntityLink();
- this.resourceVersion = entity.getResourceVersion().orElse(null);
- this.entity = entity.getJson()!=null ?new JsonParser().parse(entity.getJson()): new JsonObject();
- }
-
+ String getResourceVersion();
/**
- * Add a validation violation.
+ * Add a single validation violation.
*
* @param violation a single {@link Violation} to add to the validation result
*/
- public void addViolation(Violation violation) {
- this.violations.add(violation);
- }
+ void addViolation(Violation violation);
/**
* Add a list of validation violations.
*
* @param violations a List of {@link Violation} objects to add to the validation result
*/
- public void addViolations(List<Violation> violations) {
- this.violations.addAll(violations);
- }
-
- public String getValidationId() {
- return validationId;
- }
-
- public void setValidationId(String eventId) {
- this.validationId = eventId;
- }
-
- public String getValidationTimestamp() {
- return validationTimestamp;
- }
-
- public void setValidationTimestamp(String timestamp) {
- this.validationTimestamp = timestamp;
- }
-
- public JsonElement getEntityId() {
- return entityId;
- }
-
- public void setEntityId(JsonElement entityId) {
- this.entityId = entityId;
- }
-
- public String getEntityType() {
- return entityType;
- }
-
- public void setEntityType(String entityType) {
- this.entityType = entityType;
- }
-
- public String getEntityLink() {
- return entityLink;
- }
-
- public void setEntityLink(String uri) {
- this.entityLink = uri;
- }
-
- public String getResourceVersion() {
- return resourceVersion;
- }
-
- public void setResourceVersion(String resourceVersion) {
- this.resourceVersion = resourceVersion;
- }
-
- public JsonElement getEntity() {
- return entity;
- }
-
- public void setEntity(JsonElement entity) {
- this.entity = entity;
- }
-
- public List<Violation> getViolations() {
- return violations;
- }
-
- public void setViolations(List<Violation> violations) {
- this.violations = violations;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(this.entityId, this.entityLink, this.entityType, this.resourceVersion, this.validationId,
- this.validationTimestamp, this.violations, this.entity);
- }
-
- /*
- * validationId is checked first, as this is meant to be unique
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof ValidationResult)) {
- return false;
- } else if (obj == this) {
- return true;
- }
- ValidationResult rhs = (ValidationResult) obj;
- // @formatter:off
- return new EqualsBuilder()
- .append(entityId, rhs.entityId)
- .append(entityLink, rhs.entityLink)
- .append(entityType, rhs.entityType)
- .append(resourceVersion, rhs.resourceVersion)
- .append(validationId, rhs.validationId)
- .append(validationTimestamp, rhs.validationTimestamp)
- .append(violations, rhs.violations)
- .append(entity, rhs.entity)
- .isEquals();
- // @formatter:on
- }
-
- @Override
- public String toString() {
- return JsonUtil.toJson(this);
- }
+ void addViolations(List<Violation> violations);
/**
* Create a JSON representation of the object, with each violation's validationRule omitted when it has a null value
*
* @return this object formatted as a JSON string ready for publishing
*/
- public String toJson() {
- return toString();
- }
+ String toJson();
- /**
- * Create a new object from the JSON representation
- *
- * @param json representation of the Validation Result
- * @return a ValidationResult object
- */
- public static ValidationResult fromJson(String json) {
- ValidationResult validationResult = JsonUtil.toAnnotatedClassfromJson(json, ValidationResult.class);
- if (validationResult != null) {
- validationResult.initialiseValues();
- }
- return validationResult;
- }
+ String getValidationId();
+
+ String getValidationTimestamp();
+
+ void setEntityId(JsonElement entityId);
+
+ void setEntityType(String entityType);
- /**
- * Ensure that any unset fields are properly initialised. This is particularly useful when the object has been
- * deserialised from a JSON string, as any missing/undefined values will not be read by the deserialiser and thus
- * the corresponding fields will not be set.
- */
- private void initialiseValues() {
- List<Violation> violationList = getViolations();
- if (violationList != null) {
- for (Violation violation : violationList) {
- violation.initialiseValues();
- }
- }
- }
}
diff --git a/src/main/java/org/onap/aai/validation/result/ValidationResultBuilder.java b/src/main/java/org/onap/aai/validation/result/ValidationResultBuilder.java
new file mode 100644
index 0000000..743e08d
--- /dev/null
+++ b/src/main/java/org/onap/aai/validation/result/ValidationResultBuilder.java
@@ -0,0 +1,55 @@
+/**
+ * ============LICENSE_START===================================================
+ * 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
+ *
+ * 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=====================================================
+ */
+package org.onap.aai.validation.result;
+
+import org.onap.aai.validation.exception.ValidationServiceException;
+import org.onap.aai.validation.reader.EventReader;
+import org.onap.aai.validation.reader.data.Entity;
+
+public class ValidationResultBuilder {
+
+ private final EventReader eventReader;
+ private final String event;
+ private Entity entity;
+
+ public ValidationResultBuilder(EventReader eventReader, String event) {
+ this.eventReader = eventReader;
+ this.event = event;
+ }
+
+ public ValidationResultBuilder(Entity entity) {
+ this.eventReader = null;
+ this.event = null;
+ this.entity = entity;
+ }
+
+ public static ValidationResult fromJson(String json) {
+ return ValidationResultImpl.fromJson(json);
+ }
+
+ public ValidationResult build() throws ValidationServiceException {
+ return new ValidationResultImpl(getEntity());
+ }
+
+ private Entity getEntity() throws ValidationServiceException {
+ if (entity == null) {
+ entity = eventReader.getEntity(event);
+ }
+ return entity;
+ }
+}
diff --git a/src/main/java/org/onap/aai/validation/result/ValidationResultImpl.java b/src/main/java/org/onap/aai/validation/result/ValidationResultImpl.java
new file mode 100644
index 0000000..376a41c
--- /dev/null
+++ b/src/main/java/org/onap/aai/validation/result/ValidationResultImpl.java
@@ -0,0 +1,255 @@
+/**
+ * ============LICENSE_START===================================================
+ * 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
+ *
+ * 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=====================================================
+ */
+package org.onap.aai.validation.result;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.annotations.Expose;
+import java.time.Instant;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.UUID;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+import org.onap.aai.validation.exception.ValidationServiceException;
+import org.onap.aai.validation.reader.data.Entity;
+import org.onap.aai.validation.reader.data.EntityId;
+import org.onap.aai.validation.util.JsonUtil;
+
+/**
+ * The result of an instance validation. This can include zero or more {@link Violation} objects.
+ */
+public class ValidationResultImpl implements ValidationResult {
+
+ @Expose
+ private String validationId;
+
+ @Expose
+ private String validationTimestamp;
+
+ @Expose
+ private JsonElement entityId;
+
+ @Expose
+ private String entityType;
+
+ @Expose
+ private String entityLink;
+
+ @Expose
+ private String resourceVersion;
+
+ @Expose
+ private JsonElement entity;
+
+
+ @Expose
+ private List<Violation> violations = new ArrayList<>();
+
+ /**
+ * Create the validation payload initialised with an event identifier and a timestamp.
+ *
+ * @param entity
+ * @throws ValidationServiceException
+ */
+ public ValidationResultImpl(Entity entity) throws ValidationServiceException {
+ this.validationId = UUID.randomUUID().toString();
+ this.validationTimestamp =
+ DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX").withZone(ZoneOffset.UTC).format(Instant.now());
+ this.entityId = new JsonObject();
+ for (EntityId id : entity.getIds()) {
+ this.entityId.getAsJsonObject().addProperty(id.getPrimaryKey(), id.getValue());
+ }
+ this.entityType = entity.getType();
+ this.entityLink = entity.getEntityLink();
+ this.resourceVersion = entity.getResourceVersion().orElse(null);
+ this.entity = entity.getJson() != null ? new JsonParser().parse(entity.getJson()) : new JsonObject();
+ }
+
+ /**
+ * Add a validation violation.
+ *
+ * @param violation a single {@link Violation} to add to the validation result
+ */
+ @Override
+ public void addViolation(Violation violation) {
+ this.violations.add(violation);
+ }
+
+ /**
+ * Add a list of validation violations.
+ *
+ * @param violations a List of {@link Violation} objects to add to the validation result
+ */
+ @Override
+ public void addViolations(List<Violation> violations) {
+ this.violations.addAll(violations);
+ }
+
+ @Override
+ public String getValidationId() {
+ return validationId;
+ }
+
+ public void setValidationId(String eventId) {
+ this.validationId = eventId;
+ }
+
+ @Override
+ public String getValidationTimestamp() {
+ return validationTimestamp;
+ }
+
+ public void setValidationTimestamp(String timestamp) {
+ this.validationTimestamp = timestamp;
+ }
+
+ @Override
+ public JsonElement getEntityId() {
+ return entityId;
+ }
+
+ @Override
+ public void setEntityId(JsonElement entityId) {
+ this.entityId = entityId;
+ }
+
+ @Override
+ public String getEntityType() {
+ return entityType;
+ }
+
+ @Override
+ public void setEntityType(String entityType) {
+ this.entityType = entityType;
+ }
+
+ @Override
+ public String getEntityLink() {
+ return entityLink;
+ }
+
+ public void setEntityLink(String uri) {
+ this.entityLink = uri;
+ }
+
+ @Override
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+ public JsonElement getEntity() {
+ return entity;
+ }
+
+ public void setEntity(JsonElement entity) {
+ this.entity = entity;
+ }
+
+ @Override
+ public List<Violation> getViolations() {
+ return violations;
+ }
+
+ public void setViolations(List<Violation> violations) {
+ this.violations = violations;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.entityId, this.entityLink, this.entityType, this.resourceVersion, this.validationId,
+ this.validationTimestamp, this.violations, this.entity);
+ }
+
+ /*
+ * validationId is checked first, as this is meant to be unique
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof ValidationResultImpl)) {
+ return false;
+ } else if (obj == this) {
+ return true;
+ }
+ ValidationResultImpl rhs = (ValidationResultImpl) obj;
+ // @formatter:off
+ return new EqualsBuilder()
+ .append(entityId, rhs.entityId)
+ .append(entityLink, rhs.entityLink)
+ .append(entityType, rhs.entityType)
+ .append(resourceVersion, rhs.resourceVersion)
+ .append(validationId, rhs.validationId)
+ .append(validationTimestamp, rhs.validationTimestamp)
+ .append(violations, rhs.violations)
+ .append(entity, rhs.entity)
+ .isEquals();
+ // @formatter:on
+ }
+
+ @Override
+ public String toString() {
+ return JsonUtil.toJson(this);
+ }
+
+ /**
+ * Create a JSON representation of the object, with each violation's validationRule omitted when it has a null value
+ *
+ * @return this object formatted as a JSON string ready for publishing
+ */
+ @Override
+ public String toJson() {
+ return toString();
+ }
+
+ /**
+ * Create a new object from the JSON representation
+ *
+ * @param json representation of the Validation Result
+ * @return a ValidationResult object
+ */
+ public static ValidationResultImpl fromJson(String json) {
+ ValidationResultImpl validationResult = JsonUtil.toAnnotatedClassfromJson(json, ValidationResultImpl.class);
+ if (validationResult != null) {
+ validationResult.initialiseValues();
+ }
+ return validationResult;
+ }
+
+ /**
+ * Ensure that any unset fields are properly initialised. This is particularly useful when the object has been
+ * deserialised from a JSON string, as any missing/undefined values will not be read by the deserialiser and thus
+ * the corresponding fields will not be set.
+ */
+ private void initialiseValues() {
+ List<Violation> violationList = getViolations();
+ if (violationList != null) {
+ for (Violation violation : violationList) {
+ violation.initialiseValues();
+ }
+ }
+ }
+}
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 49b251e..cee29f7 100644
--- a/src/main/java/org/onap/aai/validation/ruledriven/RuleDrivenValidator.java
+++ b/src/main/java/org/onap/aai/validation/ruledriven/RuleDrivenValidator.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START===================================================
- * Copyright (c) 2018 Amdocs
+ * 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.
@@ -33,6 +33,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Stream;
+import org.apache.commons.lang.StringUtils;
import org.onap.aai.validation.Validator;
import org.onap.aai.validation.config.RuleIndexingConfig;
import org.onap.aai.validation.exception.ValidationServiceError;
@@ -44,6 +45,7 @@ import org.onap.aai.validation.reader.OxmReader;
import org.onap.aai.validation.reader.data.AttributeValues;
import org.onap.aai.validation.reader.data.Entity;
import org.onap.aai.validation.result.ValidationResult;
+import org.onap.aai.validation.result.ValidationResultBuilder;
import org.onap.aai.validation.result.Violation;
import org.onap.aai.validation.result.Violation.ViolationType;
import org.onap.aai.validation.ruledriven.configuration.EntitySection;
@@ -136,9 +138,9 @@ public class RuleDrivenValidator implements Validator {
*
* @param entityType
* @param eventType
- * @return the rules defined for this entityType
+ * @return the Optional rules defined for this entityType
*/
- public List<Rule> getRulesForEntity(String entityType, String eventType) {
+ public Optional<List<Rule>> getRulesForEntity(String entityType, String eventType) {
return ruleManagers.get(eventType.toLowerCase(Locale.getDefault())).getRulesForEntity(entityType);
}
@@ -152,11 +154,10 @@ public class RuleDrivenValidator implements Validator {
Entity entity = getEventReader().getEntity(event);
Optional<String> eventType = eventReader.getEventType(event);
- List<Rule> rules = getRulesToApply(entity, eventType).orElse(null);
- if (rules == null) {
- throw new ValidationServiceException(ValidationServiceError.RULES_NOT_DEFINED, eventType.orElse(null));
- }
- ValidationResult validationResult = new ValidationResult(entity);
+ List<Rule> rules = getRulesToApply(entity, eventType).orElseThrow(
+ () -> new ValidationServiceException(ValidationServiceError.RULES_NOT_DEFINED, eventType.orElse(null)));
+
+ ValidationResult validationResult = new ValidationResultBuilder(eventReader, event).build();
Violation.Builder builder = new Violation.Builder(entity);
for (Rule rule : rules) {
@@ -207,7 +208,7 @@ public class RuleDrivenValidator implements Validator {
&& ruleIndexingConfig.get().getIndexedEvents().contains(eventType.get())) {
rules = getRulesByIndex(entity, eventType.get(), ruleManager.get());
} else {
- rules = Optional.of(ruleManager.get().getRulesForEntity(entity.getType()));
+ rules = ruleManager.get().getRulesForEntity(entity.getType());
}
}
}
@@ -217,18 +218,21 @@ public class RuleDrivenValidator implements Validator {
private Optional<List<Rule>> getRulesByIndex(Entity entity, String eventType, RuleManager ruleManager) {
String rulesKey = generateKey(entity, eventType);
applicationLogger.debug(String.format("Retrieving indexed rules for key '%s'", rulesKey));
- Optional<List<Rule>> rules = Optional.of(ruleManager.getRulesForEntity(rulesKey));
- if (rules.get().isEmpty() && ruleIndexingConfig.isPresent()) {
- if (ruleIndexingConfig.get().getDefaultIndexKey() == null
- || ruleIndexingConfig.get().getDefaultIndexKey().isEmpty()) {
+
+ final Optional<List<Rule>> entityRules = ruleManager.getRulesForEntity(rulesKey);
+ final boolean rulesDefined = entityRules.filter(l -> !l.isEmpty()).isPresent();
+
+ if (!rulesDefined && ruleIndexingConfig.isPresent()) {
+ final String defaultIndexKey = ruleIndexingConfig.get().getDefaultIndexKey();
+ 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);
- return rules;
}
- String defaultKey = RuleManager.generateKey(new String[] { ruleIndexingConfig.get().getDefaultIndexKey() });
- rules = Optional.of(ruleManager.getRulesForEntity(defaultKey));
}
- return rules;
+
+ return entityRules;
}
private String generateKey(Entity entity, String eventType) {
diff --git a/src/main/java/org/onap/aai/validation/ruledriven/RuleManager.java b/src/main/java/org/onap/aai/validation/ruledriven/RuleManager.java
index c21ce24..380c99a 100644
--- a/src/main/java/org/onap/aai/validation/ruledriven/RuleManager.java
+++ b/src/main/java/org/onap/aai/validation/ruledriven/RuleManager.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START===================================================
- * Copyright (c) 2018 Amdocs
+ * 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.
@@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.SortedSet;
import java.util.TreeSet;
import org.onap.aai.validation.ruledriven.configuration.EntitySection;
@@ -45,7 +46,8 @@ public class RuleManager {
/**
* Create the rules for each type of entity based on the supplied configuration
*
- * @param entities configuration (all entities)
+ * @param entities
+ * configuration (all entities)
* @throws InstantiationException
* @throws IllegalAccessException
* @throws GroovyConfigurationException
@@ -69,11 +71,10 @@ public class RuleManager {
/**
* @param entityType
- * @return the rules configured for this entity type
+ * @return the Optional rules configured for this entity type
*/
- public List<Rule> getRulesForEntity(String entityType) {
- List<Rule> rules = rulesMap.get(entityType);
- return rules == null ? Collections.emptyList() : rules;
+ public Optional<List<Rule>> getRulesForEntity(String entityType) {
+ return Optional.ofNullable(rulesMap.get(entityType));
}
public static String generateKey(String[] indices) {
diff --git a/src/test/java/org/onap/aai/validation/controller/TestValidationController.java b/src/test/java/org/onap/aai/validation/controller/TestValidationController.java
index ff67181..b35ed17 100644
--- a/src/test/java/org/onap/aai/validation/controller/TestValidationController.java
+++ b/src/test/java/org/onap/aai/validation/controller/TestValidationController.java
@@ -1,12 +1,12 @@
-/*
+/**
* ============LICENSE_START===================================================
- * Copyright (c) 2018 Amdocs
+ * 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,
@@ -22,7 +22,6 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.util.ArrayList;
@@ -39,9 +38,7 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.aai.validation.Validator;
-import org.onap.aai.validation.config.EventReaderConfig;
import org.onap.aai.validation.config.ValidationControllerConfig;
-import org.onap.aai.validation.controller.ValidationController;
import org.onap.aai.validation.exception.ValidationServiceError;
import org.onap.aai.validation.exception.ValidationServiceException;
import org.onap.aai.validation.publisher.MessagePublisher;
@@ -49,6 +46,7 @@ import org.onap.aai.validation.reader.EventReader;
import org.onap.aai.validation.reader.data.Entity;
import org.onap.aai.validation.reader.data.EntityId;
import org.onap.aai.validation.result.ValidationResult;
+import org.onap.aai.validation.result.ValidationResultBuilder;
import org.onap.aai.validation.result.Violation;
@RunWith(MockitoJUnitRunner.class)
@@ -172,12 +170,11 @@ public class TestValidationController {
when(eventReader.getEntity(TESTDATA_EXCEPTION_EVENT)).thenReturn(entity);
when(eventReader.getEntityType(TESTDATA_HANDLE_EXCEPTION_EXCEPTION_EVENT)).thenThrow(
new RuntimeException("Error during handling the exception for an event that couldn't be validated"));
- //@formatter:off
- Mockito.doThrow(new ValidationServiceException(ValidationServiceError.EVENT_CLIENT_PUBLISHER_INIT_ERROR))
- .when(messagePublisher)
- .publishMessage(
- Mockito.contains("\"entityId\":\"[vserver-id=instanceid1]\",\"entityType\":\"entitytype1\",\"resourceVersion\":\"resourceVersion1\""));
- //@formatter:on
+
+ Mockito.doThrow(new ValidationServiceException(ValidationServiceError.EVENT_CLIENT_PUBLISHER_INIT_ERROR))
+ .when(messagePublisher).publishMessage(
+ Mockito.contains("\"entityId\":\"[vserver-id=instanceid1]\",\"entityType\":\"entitytype1\","
+ + "\"resourceVersion\":\"resourceVersion1\""));
}
private Map<String, List<String>> setupEventTypeData() {
@@ -196,66 +193,72 @@ public class TestValidationController {
}
private Map<String, List<ValidationResult>> setupTestData() throws ValidationServiceException {
+ final Map<String, List<ValidationResult>> validationResultsMap = new HashMap<>();
- Map<String, List<ValidationResult>> validationResultsMap = new HashMap<>();
-
- List<ValidationResult> aaiEventValidationResults = new ArrayList<>();
-
+ when(eventReader.getEntity(VSERVER)).thenReturn(entity);
setUpEntityMock("20160525162737-61c49d41-5338-4755-af54-06cee9fe4aca", VSERVER, "1464193654");
- aaiEventValidationResults.add(new ValidationResult(entity));
- aaiEventValidationResults.add(new ValidationResult(entity));
+ ValidationResultBuilder builder = new ValidationResultBuilder(eventReader, VSERVER);
+ List<ValidationResult> aaiEventValidationResults = new ArrayList<>();
+ aaiEventValidationResults.add(builder.build());
+ aaiEventValidationResults.add(builder.build());
validationResultsMap.put(TESTDATA_EVENTTYPE_AAI, aaiEventValidationResults);
List<ValidationResult> apiEventValidationResults = new ArrayList<>();
setUpEntityMock("20160525162737-61c49d41-5338-4755-af54-06cee9fe4acb", VSERVER, "1464193655");
- apiEventValidationResults.add(new ValidationResult(entity));
+ apiEventValidationResults.add(builder.build());
validationResultsMap.put(TESTDATA_EVENTTYPE_API, apiEventValidationResults);
List<ValidationResult> namedQueryEventValidationResults = new ArrayList<>();
setUpEntityMock("20160525162737-61c49d41-5338-4755-af54-06cee9fe4acc", VSERVER, "1464193656");
- namedQueryEventValidationResults.add(new ValidationResult(entity));
+ namedQueryEventValidationResults.add(builder.build());
validationResultsMap.put(TESTDATA_EVENTTYPE_NAMEDQUERY, namedQueryEventValidationResults);
List<ValidationResult> messagePublishExceptionValidationResults = new ArrayList<>();
setUpEntityMock("instanceid1", "entitytype1", "resourceVersion1");
- messagePublishExceptionValidationResults.add(new ValidationResult(entity));
+ messagePublishExceptionValidationResults.add(builder.build());
validationResultsMap.put(TESTDATA_VALIDATION_RESULT_PUBLISH_ERROR, messagePublishExceptionValidationResults);
return validationResultsMap;
}
@Test
- public void testExecuteForAAIEvent() throws Exception {
+ public void testExecuteForAaiEvent() throws Exception {
// Test for AAI-EVENT
validationController.execute(TESTDATA_EVENTTYPE_AAI, TEST);
verify(ruleDrivenValidator, times(1)).validate(TESTDATA_EVENTTYPE_AAI);
- verify(messagePublisher, times(2)).publishMessage(Mockito.contains(
- "\"entityId\":{\"vserver-id\":\"20160525162737-61c49d41-5338-4755-af54-06cee9fe4aca\"},\"entityType\":\"vserver\",\"entityLink\":\"entityLink\",\"resourceVersion\":\"1464193654\",\"entity\":{},\"violations\":[]}"));
+ verify(messagePublisher, times(2)).publishMessage(Mockito
+ .contains("\"entityId\":{\"vserver-id\":\"20160525162737-61c49d41-5338-4755-af54-06cee9fe4aca\"},"
+ + "\"entityType\":\"vserver\",\"entityLink\":\"entityLink\","
+ + "\"resourceVersion\":\"1464193654\",\"entity\":{},\"violations\":[]}"));
}
@Test
- public void testExecuteForAPIEvent() throws Exception {
+ public void testExecuteForApiEvent() throws Exception {
// Test for AAI-DATA-EXPORT-API
validationController.execute(TESTDATA_EVENTTYPE_API, TEST);
verify(ruleDrivenValidator, times(1)).validate(TESTDATA_EVENTTYPE_API);
- verify(messagePublisher, times(1)).publishMessage(Mockito.contains(
- "\"entityId\":{\"vserver-id\":\"20160525162737-61c49d41-5338-4755-af54-06cee9fe4acb\"},\"entityType\":\"vserver\",\"entityLink\":\"entityLink\",\"resourceVersion\":\"1464193655\",\"entity\":{},\"violations\":[]}"));
+ verify(messagePublisher, times(1)).publishMessage(Mockito
+ .contains("\"entityId\":{\"vserver-id\":\"20160525162737-61c49d41-5338-4755-af54-06cee9fe4acb\"},"
+ + "\"entityType\":\"vserver\",\"entityLink\":\"entityLink\","
+ + "\"resourceVersion\":\"1464193655\",\"entity\":{},\"violations\":[]}"));
}
@Test
- public void testExecuteForNQEvent() throws Exception {
+ public void testExecuteForNqEvent() throws Exception {
// Test for AAI-DATA-EXPORT-NQ
validationController.execute(TESTDATA_EVENTTYPE_NAMEDQUERY, TEST);
verify(modelDrivenValidator, times(1)).validate(TESTDATA_EVENTTYPE_NAMEDQUERY);
- verify(messagePublisher, times(1)).publishMessage(Mockito.contains(
- "\"entityId\":{\"vserver-id\":\"20160525162737-61c49d41-5338-4755-af54-06cee9fe4acc\"},\"entityType\":\"vserver\",\"entityLink\":\"entityLink\",\"resourceVersion\":\"1464193656\",\"entity\":{},\"violations\":[]}"));
+ verify(messagePublisher, times(1)).publishMessage(Mockito
+ .contains("\"entityId\":{\"vserver-id\":\"20160525162737-61c49d41-5338-4755-af54-06cee9fe4acc\"},"
+ + "\"entityType\":\"vserver\",\"entityLink\":\"entityLink\","
+ + "\"resourceVersion\":\"1464193656\",\"entity\":{},\"violations\":[]}"));
}
@Test
@@ -332,26 +335,25 @@ public class TestValidationController {
verify(ruleDrivenValidator, times(1)).validate(TESTDATA_EXCEPTION_EVENT);
// @formatter:off
- Violation violation = new Violation.Builder(entity)
- .category("CANNOT_VALIDATE")
- .severity("CRITICAL")
- .violationType("NONE")
- .errorMessage("Failed to validate")
- .build();
- // @formatter:on
+ Violation violation = new Violation.Builder(entity)
+ .category("CANNOT_VALIDATE")
+ .severity("CRITICAL")
+ .violationType("NONE")
+ .errorMessage("Failed to validate")
+ .build();
+ // @formatter:on
JsonObject violationObject = new JsonParser().parse(violation.toString()).getAsJsonObject();
violationObject.remove("validationRule"); // Not set
JsonObject validationResult = new JsonObject();
JsonObject entityIdObject = new JsonObject();
- JsonElement entity = new JsonObject();
entityIdObject.addProperty(primaryKey, value);
validationResult.add(Violation.ENTITY_ID_PROPERTY, entityIdObject);
validationResult.addProperty(Violation.ENTITY_TYPE_PROPERTY, "entitytype1");
validationResult.addProperty(ENTITY_LINK, ENTITY_LINK);
validationResult.addProperty("resourceVersion", resourceVersion);
- validationResult.add("entity", entity);
+ validationResult.add("entity", new JsonObject());
JsonArray violations = new JsonArray();
violations.add(violationObject);
validationResult.add("violations", violations);
@@ -376,12 +378,13 @@ public class TestValidationController {
// This test is here for code coverage.
validationController.execute(TESTDATA_VALIDATION_RESULT_PUBLISH_ERROR, TEST);
verify(ruleDrivenValidator, times(1)).validate(TESTDATA_VALIDATION_RESULT_PUBLISH_ERROR);
- verify(messagePublisher, times(1)).publishMessage(Mockito.contains(
- "\"entityId\":{\"vserver-id\":\"instanceid1\"},\"entityType\":\"entitytype1\",\"entityLink\":\"entityLink\",\"resourceVersion\":\"resourceVersion1\",\"entity\":{},\"violations\":[]}"));
+ verify(messagePublisher, times(1)).publishMessage(
+ Mockito.contains("\"entityId\":{\"vserver-id\":\"instanceid1\"},\"entityType\":\"entitytype1\","
+ + "\"entityLink\":\"entityLink\",\"resourceVersion\":\"resourceVersion1\","
+ + "\"entity\":{},\"violations\":[]}"));
}
private void setUpEntityMock(String id, String type, String resourceVersion) throws ValidationServiceException {
- when(eventReader.getEventReaderConfig()).thenReturn(new EventReaderConfig());
when(entity.getType()).thenReturn(type);
EntityId entityId = new EntityId("vserver-id", id);
when(entity.getIds()).thenReturn(Collections.singletonList(entityId));
diff --git a/src/test/java/org/onap/aai/validation/publisher/MockEventPublisher.java b/src/test/java/org/onap/aai/validation/publisher/MockEventPublisher.java
index d1cfae0..f09f6d5 100644
--- a/src/test/java/org/onap/aai/validation/publisher/MockEventPublisher.java
+++ b/src/test/java/org/onap/aai/validation/publisher/MockEventPublisher.java
@@ -1,12 +1,12 @@
-/*
+/**
* ============LICENSE_START===================================================
- * Copyright (c) 2018 Amdocs
+ * 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,
@@ -17,15 +17,14 @@
*/
package org.onap.aai.validation.publisher;
-import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collection;
import org.onap.aai.validation.exception.ValidationServiceException;
-import org.onap.aai.validation.publisher.MessagePublisher;
import org.onap.aai.validation.result.ValidationResult;
+import org.onap.aai.validation.result.ValidationResultBuilder;
import org.onap.aai.validation.test.util.TestEntity;
import org.onap.aai.validation.test.util.ValidationResultIsEqual;
@@ -54,8 +53,8 @@ public class MockEventPublisher implements MessagePublisher {
@Override
public void publishMessage(String message) throws ValidationServiceException {
- ValidationResult validationResult = ValidationResult.fromJson(message);
- assertThat(testDescription, validationResult, is(ValidationResultIsEqual.equalTo(expectedValidationResult)));
+ assertThat(testDescription, ValidationResultBuilder.fromJson(message),
+ ValidationResultIsEqual.equalTo(expectedValidationResult));
publishedMessage = true;
}
diff --git a/src/test/java/org/onap/aai/validation/result/TestValidationResult.java b/src/test/java/org/onap/aai/validation/result/TestValidationResult.java
index 32f85fe..e262ef1 100644
--- a/src/test/java/org/onap/aai/validation/result/TestValidationResult.java
+++ b/src/test/java/org/onap/aai/validation/result/TestValidationResult.java
@@ -1,6 +1,6 @@
-/*
+/**
* ============LICENSE_START===================================================
- * Copyright (c) 2018-2019 Amdocs
+ * 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.
@@ -59,12 +59,16 @@ public class TestValidationResult {
System.setProperty("APP_HOME", ".");
}
+ private static final DateTimeFormatter formatter =
+ DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX").withZone(ZoneOffset.UTC);
+
@Inject
private EventReader eventReader;
private static String vserverEvent;
private static Entity entity;
+
@BeforeClass
public static void setUpBeforeClass() throws Exception {
vserverEvent = TestUtil.getFileAsString(TestData.VSERVER.getFilename());
@@ -76,13 +80,19 @@ public class TestValidationResult {
}
enum TestData {
- // @formatter:off
- VSERVER ("validation-result/vserver-create-event.json");
+ VSERVER(
+ "validation-result/vserver-create-event.json"
+ );
private String filename;
- TestData(String filename) {this.filename = filename;}
- public String getFilename() {return this.filename;}
- // @formatter:on
+
+ TestData(String filename) {
+ this.filename = filename;
+ }
+
+ public String getFilename() {
+ return this.filename;
+ }
}
@Test
@@ -96,8 +106,8 @@ public class TestValidationResult {
ValidationResult transformedVr = toAndFromJson(validationResult);
assertThatValidationResultIsValid(transformedVr);
- Violation v = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0));
- assertThat(v.getViolationDetails(), is(violationDetails));
+ Violation violation = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0));
+ assertThat(violation.getViolationDetails(), is(violationDetails));
}
@Test
@@ -112,8 +122,8 @@ public class TestValidationResult {
// Check
assertThatValidationResultIsValid(transformedVr);
- Violation v = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0));
- assertThat(v.getViolationDetails(), is(violationDetails));
+ Violation violation = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0));
+ assertThat(violation.getViolationDetails(), is(violationDetails));
}
@Test
@@ -128,8 +138,8 @@ public class TestValidationResult {
// Check
assertThatValidationResultIsValid(transformedVr);
- Violation v = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0));
- assertThat(v.getViolationDetails(), is(violationDetails));
+ Violation violation = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0));
+ assertThat(violation.getViolationDetails(), is(violationDetails));
}
@Test
@@ -140,13 +150,13 @@ public class TestValidationResult {
violationDetails.put("attr2", 2);
ValidationResult validationResult = getValidationResult(violationDetails);
- ValidationResult vr = toAndFromJson(validationResult);
+ ValidationResult transformedVr = toAndFromJson(validationResult);
// Check
- assertThatValidationResultIsValid(vr);
- Violation v = assertThatViolationIsValid(vr, validationResult.getViolations().get(0));
- assertThat(v.getViolationDetails().get("attr1"), is(1.0));
- assertThat(v.getViolationDetails().get("attr2"), is(2.0));
+ assertThatValidationResultIsValid(transformedVr);
+ Violation violation = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0));
+ assertThat(violation.getViolationDetails().get("attr1"), is(1.0));
+ assertThat(violation.getViolationDetails().get("attr2"), is(2.0));
}
@Test
@@ -165,8 +175,8 @@ public class TestValidationResult {
// Check
assertThatValidationResultIsValid(transformedVr);
- Violation v = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0));
- String jsonDetails = v.getViolationDetails().get("attr1").toString();
+ Violation violation = assertThatViolationIsValid(transformedVr, validationResult.getViolations().get(0));
+ String jsonDetails = violation.getViolationDetails().get("attr1").toString();
JsonParser jsonParser = new JsonParser();
JsonElement jsonElement = jsonParser.parse(jsonDetails);
assertThat(jsonObject, is(jsonElement));
@@ -174,13 +184,14 @@ public class TestValidationResult {
@Test
public void testCompareObjects() throws Exception {
- ValidationResult validationResult = new ValidationResult(entity);
+ ValidationResultBuilder builder = new ValidationResultBuilder(eventReader, vserverEvent);
+ ValidationResult validationResult = builder.build();
assertThat(validationResult, is(not(equalTo(null))));
validationResult.setEntityId(new JsonObject());
assertThat(validationResult, is(not(equalTo(null))));
- ValidationResult other = new ValidationResult(entity);
+ ValidationResult other = builder.build();
assertThat(validationResult, is(not(equalTo(other))));
validationResult.setEntityType("type");
@@ -254,9 +265,12 @@ public class TestValidationResult {
* Generate various violations using the supplied builders and assert the expected equality of the generated
* Violation IDs whenever the values supplied to the builders are the same.
*
- * @param b1 a builder
- * @param b2 another builder
- * @param expectedResult whether or not the two builders should produce identical violations
+ * @param b1
+ * a builder
+ * @param b2
+ * another builder
+ * @param expectedResult
+ * whether or not the two builders should produce identical violations
* @throws ValidationServiceException
*/
private void testViolationIdsForEquality(Builder b1, Builder b2, Boolean expectedResult)
@@ -370,7 +384,7 @@ public class TestValidationResult {
private ValidationResult getValidationResult(Map<String, Object> violationDetails)
throws ValidationServiceException {
- ValidationResult validationResult = new ValidationResult(entity);
+ ValidationResult validationResult = new ValidationResultBuilder(eventReader, vserverEvent).build();
//@formatter:off
Violation violation = new Violation.Builder(entity)
@@ -388,29 +402,29 @@ public class TestValidationResult {
}
private ValidationResult toAndFromJson(ValidationResult validationResult) {
- return JsonUtil.toAnnotatedClassfromJson(validationResult.toJson(), ValidationResult.class);
+ return JsonUtil.toAnnotatedClassfromJson(validationResult.toJson(), ValidationResultImpl.class);
}
- private void assertThatValidationResultIsValid(ValidationResult vr) {
- assertTrue("Expected valid UUID", isValidEventId(vr.getValidationId()));
- assertIsValidTimestamp(vr.getValidationTimestamp());
+ private void assertThatValidationResultIsValid(ValidationResult validationResult) {
+ assertTrue("Expected valid UUID", isValidEventId(validationResult.getValidationId()));
+ assertIsValidTimestamp(validationResult.getValidationTimestamp());
JsonObject expectedEntityId = new JsonObject();
expectedEntityId.addProperty("vserver-id", "example-vserver-id-val-34666");
- assertThat(vr.getEntityId(), is(expectedEntityId));
- assertThat(vr.getEntityType(), is("vserver"));
- assertThat(vr.getResourceVersion(), is("1464193654"));
- assertThat(vr.getEntityLink(), is(
- "cloud-infrastructure/cloud-regions/cloud-region/region1/AAIregion1/tenants/tenant/example-tenant-id-val-88551/vservers/vserver/example-vserver-id-val-34666"));
+ assertThat(validationResult.getEntityId(), is(expectedEntityId));
+ assertThat(validationResult.getEntityType(), is("vserver"));
+ assertThat(validationResult.getResourceVersion(), is("1464193654"));
+ assertThat(validationResult.getEntityLink(), is("cloud-infrastructure/cloud-regions/cloud-region/region1/"
+ + "AAIregion1/tenants/tenant/example-tenant-id-val-88551/vservers/vserver/example-vserver-id-val-34666"));
}
- private Violation assertThatViolationIsValid(ValidationResult vr, Violation expectedViolation) {
- Violation v = vr.getViolations().get(0);
- assertThat(v.getViolationId(), is(expectedViolation.getViolationId()));
- assertThat(v.getCategory(), is("category"));
- assertThat(v.getSeverity(), is("severity"));
- assertThat(v.getViolationType(), is("violationType"));
- assertThat(v.getErrorMessage(), is("errorMessage"));
- return v;
+ private Violation assertThatViolationIsValid(ValidationResult validationResult, Violation expectedViolation) {
+ Violation violation = validationResult.getViolations().get(0);
+ assertThat(violation.getViolationId(), is(expectedViolation.getViolationId()));
+ assertThat(violation.getCategory(), is("category"));
+ assertThat(violation.getSeverity(), is("severity"));
+ assertThat(violation.getViolationType(), is("violationType"));
+ assertThat(violation.getErrorMessage(), is("errorMessage"));
+ return violation;
}
private void assertThatViolationsAreEqual(Violation v1, Violation v2, Boolean expectedResult) {
@@ -429,14 +443,13 @@ public class TestValidationResult {
private boolean isValidEventId(String eventId) {
try {
UUID.fromString(eventId);
+ return true;
} catch (IllegalArgumentException exception) {
return false;
}
- return true;
}
private void assertIsValidTimestamp(String date) {
- DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX").withZone(ZoneOffset.UTC);
- Instant.from(f.parse(date));
+ Instant.from(formatter.parse(date));
}
}
diff --git a/src/test/java/org/onap/aai/validation/ruledriven/rule/TestConfigurationLoader.java b/src/test/java/org/onap/aai/validation/ruledriven/rule/TestConfigurationLoader.java
index f226252..a70d908 100644
--- a/src/test/java/org/onap/aai/validation/ruledriven/rule/TestConfigurationLoader.java
+++ b/src/test/java/org/onap/aai/validation/ruledriven/rule/TestConfigurationLoader.java
@@ -29,7 +29,6 @@ import org.junit.Test;
import org.onap.aai.validation.reader.OxmReader;
import org.onap.aai.validation.reader.data.AttributeValues;
import org.onap.aai.validation.ruledriven.RuleDrivenValidator;
-import org.onap.aai.validation.ruledriven.rule.Rule;
public class TestConfigurationLoader {
@@ -77,7 +76,7 @@ public class TestConfigurationLoader {
// Find the trinity rule
Rule trinityRule = null;
- for (Rule rule : validator.getRulesForEntity("vserver", "aai-event")) {
+ for (Rule rule : validator.getRulesForEntity("vserver", "aai-event").get()) {
if (rule.getName().contains("TRINITY") && rule.getName().contains("generic-vnf")) {
trinityRule = rule;
}
diff --git a/src/test/java/org/onap/aai/validation/test/util/TestEntity.java b/src/test/java/org/onap/aai/validation/test/util/TestEntity.java
index e42873a..b94a875 100644
--- a/src/test/java/org/onap/aai/validation/test/util/TestEntity.java
+++ b/src/test/java/org/onap/aai/validation/test/util/TestEntity.java
@@ -1,4 +1,4 @@
-/*
+/**
* ============LICENSE_START===================================================
* Copyright (c) 2018 Amdocs
* ============================================================================
@@ -6,7 +6,7 @@
* 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,
@@ -25,6 +25,7 @@ import java.net.URISyntaxException;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import org.onap.aai.validation.result.ValidationResult;
+import org.onap.aai.validation.result.ValidationResultBuilder;
public class TestEntity {
@@ -44,6 +45,8 @@ public class TestEntity {
}
/**
+ * Fetch the expected JSON output from the test resources.
+ *
* @return the contents of the file that stores the expected JSON, or an empty string if there is no expected JSON
* @throws URISyntaxException
* @throws IOException
@@ -57,7 +60,7 @@ public class TestEntity {
}
public ValidationResult getExpectedValidationResult() throws JsonSyntaxException, URISyntaxException, IOException {
- return ValidationResult.fromJson(getExpectedJson());
+ return ValidationResultBuilder.fromJson(getExpectedJson());
}
@Override
@@ -79,10 +82,10 @@ public class TestEntity {
}
private String getErrorFileContents() throws URISyntaxException, IOException {
- return TestUtil.getFileAsString(new URI(getErrorFileURI()).getPath());
+ return TestUtil.getFileAsString(new URI(getErrorFileUri()).getPath());
}
- private String getErrorFileURI() {
+ private String getErrorFileUri() {
return expectedResultsFile.replaceAll("\\.exp\\.json$", ".error");
}
}
diff --git a/src/test/java/org/onap/aai/validation/test/util/ValidationResultIsEqual.java b/src/test/java/org/onap/aai/validation/test/util/ValidationResultIsEqual.java
index aa6471f..2ef1e1e 100644
--- a/src/test/java/org/onap/aai/validation/test/util/ValidationResultIsEqual.java
+++ b/src/test/java/org/onap/aai/validation/test/util/ValidationResultIsEqual.java
@@ -1,4 +1,4 @@
-/*
+/**
* ============LICENSE_START===================================================
* Copyright (c) 2018 Amdocs
* ============================================================================
@@ -6,7 +6,7 @@
* 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,
@@ -23,7 +23,7 @@ import org.hamcrest.Matcher;
import org.onap.aai.validation.result.ValidationResult;
/**
- * Matcher for comparing actual and expected ValidationResults
+ * Matcher for comparing actual and expected ValidationResults.
*
*/
public class ValidationResultIsEqual extends BaseMatcher<ValidationResult> {
@@ -38,11 +38,11 @@ public class ValidationResultIsEqual extends BaseMatcher<ValidationResult> {
}
@Override
- public boolean matches(Object o) {
+ public boolean matches(Object obj) {
if (expected == null) {
return false;
}
- ValidationResult actual = (ValidationResult) o;
+ ValidationResult actual = (ValidationResult) obj;
return actual.getEntityId().equals(expected.getEntityId()) && //
actual.getEntityType().equals(expected.getEntityType()) && //
(actual.getEntityLink() == null ? "" : actual.getEntityLink()).equals(expected.getEntityLink()) && //