summaryrefslogtreecommitdiffstats
path: root/models-sim/policy-models-simulators/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-04-26 18:16:36 -0400
committerJim Hahn <jrh3@att.com>2021-04-29 11:35:02 -0400
commit4fdecb037bd2609a6b977adba6d2f263c977d9e1 (patch)
treecac0861d73c073e33e2b677fc6c9356e3dcf3574 /models-sim/policy-models-simulators/src
parent6e589fc31f69482d2cf5bf57c733094394439b0f (diff)
Remove GroupValidationResult
Removed GroupValidationResult, replacing it with BeanValidationResult. Modified the ParameterGroup subclasses to use BeanValidator, adding annotations where needed to trigger the validations that had been automatically performed by GroupValidationResult. Issue-ID: POLICY-2059 Change-Id: I245e4a647fcbb718faa63a7543f9f81c85da958c Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-sim/policy-models-simulators/src')
-rw-r--r--models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/CdsServerParameters.java11
-rw-r--r--models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/ClassRestServerParameters.java25
-rw-r--r--models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java27
-rw-r--r--models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/ClassRestServerParametersTest.java6
4 files changed, 19 insertions, 50 deletions
diff --git a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/CdsServerParameters.java b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/CdsServerParameters.java
index 97dc35449..5f4c18ffc 100644
--- a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/CdsServerParameters.java
+++ b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/CdsServerParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Bell Canada.
+ * 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.
@@ -23,8 +24,7 @@ import java.util.Base64;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
import org.onap.policy.common.parameters.ParameterRuntimeException;
import org.onap.policy.common.parameters.annotations.Max;
import org.onap.policy.common.parameters.annotations.Min;
@@ -33,7 +33,7 @@ import org.onap.policy.common.parameters.annotations.NotNull;
@Getter
@Setter
@ToString
-public class CdsServerParameters implements ParameterGroup {
+public class CdsServerParameters extends ParameterGroupImpl {
// Port range constants
private static final int MIN_USER_PORT = 1024;
@@ -78,11 +78,6 @@ public class CdsServerParameters implements ParameterGroup {
throw new ParameterRuntimeException("The name of this ParameterGroup implementation is always " + getName());
}
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
- }
-
/**
* Generate base64-encoded Authorization header from username and password.
*
diff --git a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/ClassRestServerParameters.java b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/ClassRestServerParameters.java
index 030d77449..65f94abe9 100644
--- a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/ClassRestServerParameters.java
+++ b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/ClassRestServerParameters.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-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.
@@ -21,28 +21,11 @@
package org.onap.policy.models.simulators;
import lombok.Getter;
-import org.apache.commons.lang3.StringUtils;
import org.onap.policy.common.endpoints.parameters.RestServerParameters;
-import org.onap.policy.common.parameters.ObjectValidationResult;
-import org.onap.policy.common.parameters.ValidationResult;
-import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.parameters.annotations.ClassName;
+import org.onap.policy.common.parameters.annotations.NotNull;
@Getter
public class ClassRestServerParameters extends RestServerParameters {
- private String providerClass;
-
- /**
- * Validates the parameters.
- *
- * @param containerName name of the parameter container
- * @return the validation result
- */
- public ValidationResult validate(String containerName) {
- // not using a BeanValidator because username and password are not required
- if (StringUtils.isBlank(providerClass)) {
- return new ObjectValidationResult("providerClass", providerClass, ValidationStatus.INVALID, "is empty");
- }
-
- return new ObjectValidationResult("providerClass", providerClass);
- }
+ private @NotNull @ClassName String providerClass;
}
diff --git a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java
index 4b60d5e45..491585e9c 100644
--- a/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java
+++ b/models-sim/policy-models-simulators/src/main/java/org/onap/policy/models/simulators/SimulatorParameters.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,8 +27,8 @@ import lombok.Getter;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.BeanValidator;
-import org.onap.policy.common.parameters.ObjectValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
/**
@@ -45,27 +45,27 @@ public class SimulatorParameters {
*/
private DmaapSimParameterGroup dmaapProvider;
- private CdsServerParameters grpcServer;
+ private @Valid CdsServerParameters grpcServer;
/**
* Parameters for the REST server simulators that are to be started.
*/
- private List<ClassRestServerParameters> restServers = new LinkedList<>();
+ private List<@Valid ClassRestServerParameters> restServers = new LinkedList<>();
/**
* Topic sinks that are used by {@link #topicServers}.
*/
- private List<TopicParameters> topicSinks = new LinkedList<>();
+ private List<@Valid TopicParameters> topicSinks = new LinkedList<>();
/**
* Topic sources that are used by {@link #topicServers}.
*/
- private List<TopicParameters> topicSources = new LinkedList<>();
+ private List<@Valid TopicParameters> topicSources = new LinkedList<>();
/**
* Parameters for the TOPIC server simulators that are to be started.
*/
- private List<TopicServerParameters> topicServers = new LinkedList<>();
+ private List<@Valid TopicServerParameters> topicServers = new LinkedList<>();
/**
@@ -83,21 +83,12 @@ public class SimulatorParameters {
BeanValidationResult subResult = new BeanValidationResult("dmaapProvider", dmaapProvider);
subResult.validateNotNull("name", dmaapProvider.getName());
if (dmaapProvider.getTopicSweepSec() < 1) {
- ObjectValidationResult fieldResult =
- new ObjectValidationResult("topicSweepSec", dmaapProvider.getTopicSweepSec(),
- ValidationStatus.INVALID, "is below the minimum value: 1");
- subResult.addResult(fieldResult);
+ subResult.addResult("topicSweepSec", dmaapProvider.getTopicSweepSec(),
+ ValidationStatus.INVALID, "is below the minimum value: 1");
}
result.addResult(subResult);
}
- if (grpcServer != null) {
- result.addResult(grpcServer.validate());
- }
-
- result.validateList("restServers", restServers, params -> params.validate("restServers"));
- result.validateList("topicServers", topicServers, params -> params.validate("topicServers"));
-
return result;
}
}
diff --git a/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/ClassRestServerParametersTest.java b/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/ClassRestServerParametersTest.java
index 76637610c..0560e851c 100644
--- a/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/ClassRestServerParametersTest.java
+++ b/models-sim/policy-models-simulators/src/test/java/org/onap/policy/models/simulators/ClassRestServerParametersTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-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.
@@ -35,7 +35,7 @@ public class ClassRestServerParametersTest {
@Test
public void testValidateString() throws CoderException {
// some fields missing
- ValidationResult result = new ClassRestServerParameters().validate("InvalidParams");
+ ValidationResult result = new ClassRestServerParameters().validate();
assertFalse(result.isValid());
assertNotNull(result.getResult());
@@ -43,6 +43,6 @@ public class ClassRestServerParametersTest {
SimulatorParameters simParams = new StandardCoder()
.decode(new File("src/test/resources/simParameters.json"), SimulatorParameters.class);
ClassRestServerParameters params = simParams.getRestServers().get(0);
- assertNull(params.validate("ValidParams").getResult());
+ assertNull(params.validate().getResult());
}
}