summaryrefslogtreecommitdiffstats
path: root/models-provider/src
diff options
context:
space:
mode:
Diffstat (limited to 'models-provider/src')
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderParameters.java38
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderParametersTest.java5
2 files changed, 14 insertions, 29 deletions
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderParameters.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderParameters.java
index 19345553b..bcd14c82b 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderParameters.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderParameters.java
@@ -23,10 +23,11 @@
package org.onap.policy.models.provider;
import lombok.Data;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.BeanValidator;
import org.onap.policy.common.parameters.ParameterGroup;
-import org.onap.policy.common.parameters.ValidationStatus;
-import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl;
// @formatter:off
@@ -55,42 +56,25 @@ public class PolicyModelsProviderParameters implements ParameterGroup {
private static final String DEFAULT_IMPLEMENTATION = DatabasePolicyModelsProviderImpl.class.getName();
private String name;
+ @NotNull @NotBlank
private String implementation = DEFAULT_IMPLEMENTATION;
private String databaseType;
+ @NotNull @NotBlank
private String databaseDriver;
+ @NotNull @NotBlank
private String databaseUrl;
private String databaseUser;
private String databasePassword;
+ @NotNull @NotBlank
private String persistenceUnit;
/**
* Validate the model provider parameters.
*
*/
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult validationResult = new GroupValidationResult(this);
-
- if (!ParameterValidationUtils.validateStringParameter(implementation)) {
- validationResult.setResult("implementation", ValidationStatus.INVALID,
- "a PolicyModelsProvider implementation must be specified");
- }
-
- if (!ParameterValidationUtils.validateStringParameter(databaseDriver)) {
- validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
- "a driver must be specified for the JDBC connection to the database");
- }
- if (!ParameterValidationUtils.validateStringParameter(databaseUrl)) {
- validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
- "a URL must be specified for the JDBC connection to the database");
- }
-
- if (!ParameterValidationUtils.validateStringParameter(persistenceUnit)) {
- validationResult.setResult("persistenceUnit", ValidationStatus.INVALID,
- "a persistence unit must be specified for connecting to the database");
- }
-
- return validationResult;
+ @Override
+ public BeanValidationResult validate() {
+ return new BeanValidator().validateTop(getClass().getSimpleName(), this);
}
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderParametersTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderParametersTest.java
index 51771ff9a..b1ae2a876 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderParametersTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderParametersTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +25,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
/**
* Test of {@link PolicyModelsProviderParameters} class.
@@ -40,7 +41,7 @@ public class PolicyModelsProviderParametersTest {
pars.setDatabaseUrl("jdbc://www.acmecorp/roadrunner");
pars.setPersistenceUnit("WileECoyote");
- GroupValidationResult result = pars.validate();
+ ValidationResult result = pars.validate();
assertTrue(result.isValid());
pars.setImplementation(null);