From 24400f789d2a20da08793fa8d5ac046caf46c267 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 10 Apr 2019 11:34:06 +0000 Subject: Finish unit test on policy-models Unit test coverage well over 90% in policy-models-base policy-models-dao policy-models-pdp policy-models-tosca policy-models-provider Issue-ID: POLICY-1095 Change-Id: I7703e2ae8a93575ca478c3d809ff8c1fb9f0f334 Signed-off-by: liamfallon --- models-pdp/pom.xml | 4 --- .../pdp/persistence/concepts/JpaPdpGroup.java | 34 +++++++++++++++------- .../policy/models/pdp/concepts/ModelsTest.java | 3 +- 3 files changed, 26 insertions(+), 15 deletions(-) (limited to 'models-pdp') diff --git a/models-pdp/pom.xml b/models-pdp/pom.xml index 029c76b8f..8eb7231f0 100644 --- a/models-pdp/pom.xml +++ b/models-pdp/pom.xml @@ -44,10 +44,6 @@ policy-models-tosca ${project.version} - - org.mariadb.jdbc - mariadb-java-client - com.h2database h2 diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java index d0fc216c2..1e77c099d 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java @@ -238,16 +238,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { } if (properties != null) { - for (Entry propertyEntry : properties.entrySet()) { - if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "a property key may not be null or blank")); - } - if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getValue())) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "a property value may not be null or blank")); - } - } + result = validateProperties(result); } if (pdpSubGroups == null) { @@ -262,6 +253,29 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { return result; } + /** + * Validate the properties. + * + * @param resultIn the incoming validation results so far + * @return the revalidation results including the property validation results + */ + private PfValidationResult validateProperties(PfValidationResult resultIn) { + PfValidationResult result = resultIn; + + for (Entry propertyEntry : properties.entrySet()) { + if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) { + result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "a property key may not be null or blank")); + } + if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getValue())) { + result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "a property value may not be null or blank")); + } + } + + return result; + } + @Override public int compareTo(final PfConcept otherConcept) { if (otherConcept == null) { diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ModelsTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ModelsTest.java index d22642d98..541e00b02 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ModelsTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ModelsTest.java @@ -36,11 +36,12 @@ import org.onap.policy.common.utils.validation.ToStringTester; * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ public class ModelsTest { + private static final String POJO_PACKAGE = "org.onap.policy.models.pdp.concepts"; @Test public void testPdpModels() { final Validator validator = ValidatorBuilder.create().with(new ToStringTester()).with(new SetterTester()) .with(new GetterTester()).build(); - validator.validate(ModelsTest.class.getPackage().getName(), new FilterPackageInfo()); + validator.validate(POJO_PACKAGE, new FilterPackageInfo()); } } -- cgit 1.2.3-korg