summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-04-28 15:45:22 -0400
committerJim Hahn <jrh3@att.com>2021-05-03 15:44:08 -0400
commite168ce2fad71650ad730519c772a9b093c0a8f43 (patch)
tree8d97f8823eb4f97916b2c19909c6b13e6a008e4a
parentcb09008c4d252dbc9a62f3a1d0b463a74380aa77 (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: I2c0c01fac355e6cde4d8d6998dc42f8a2e2ebb65 Signed-off-by: Jim Hahn <jrh3@att.com>
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperJsonAdapterParameters.java19
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParameters.java20
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/parameters/ContextParameters.java52
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/parameters/DistributorParameters.java34
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/parameters/LockManagerParameters.java36
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/parameters/PersistorParameters.java36
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaHelperParameters.java32
-rw-r--r--context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaParameters.java39
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameters.java43
-rw-r--r--core/core-engine/src/main/java/org/onap/policy/apex/core/engine/ExecutorParameters.java31
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.java4
-rw-r--r--core/core-engine/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java15
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java9
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParameters.java66
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java5
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParameters.java79
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParameters.java13
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java16
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java6
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParameters.java21
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java9
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParameters.java22
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParametersTest.java5
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParameters.java16
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParameters.java170
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java4
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImpl.java5
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java5
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java239
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParameters.java39
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/RestPluginCarrierTechnologyParameters.java91
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java82
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventhandler/EventHandlerParameters.java58
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java32
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextCharDelimitedParameters.java10
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java21
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java7
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java3
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java10
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java80
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java58
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java236
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperDooperCarrierTechnologyParameters.java116
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterGroup.java8
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterHandler.java5
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java34
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java4
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java18
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java6
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java11
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/executionproperties/DummyCarrierTechnologyParameters.java30
-rw-r--r--testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParameters.java126
-rw-r--r--testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersHandlerTest.java37
53 files changed, 713 insertions, 1460 deletions
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperJsonAdapterParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperJsonAdapterParameters.java
index 0c68c42a1..75099f6ad 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperJsonAdapterParameters.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperJsonAdapterParameters.java
@@ -24,7 +24,9 @@ package org.onap.policy.apex.context.impl.schema.java;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonSerializer;
import com.google.gson.TypeAdapter;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.apache.commons.lang3.StringUtils;
+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.slf4j.ext.XLogger;
@@ -145,8 +147,8 @@ public class JavaSchemaHelperJsonAdapterParameters implements ParameterGroup {
* {@inheritDoc}.
*/
@Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = new GroupValidationResult(this);
+ public BeanValidationResult validate() {
+ final BeanValidationResult result = new BeanValidator().validateTop(getClass().getSimpleName(), this);
getClass(ADAPTED_CLASS, adaptedClass, result);
@@ -172,7 +174,7 @@ public class JavaSchemaHelperJsonAdapterParameters implements ParameterGroup {
}
if (errorMessage != null) {
- result.setResult(ADAPTOR_CLASS, ValidationStatus.INVALID, errorMessage);
+ result.addResult(ADAPTOR_CLASS, adaptorClazz, ValidationStatus.INVALID, errorMessage);
}
}
@@ -186,9 +188,9 @@ public class JavaSchemaHelperJsonAdapterParameters implements ParameterGroup {
* @param classToCheck the class to check for existence
* @param result the result of the check
*/
- private Class<?> getClass(String parameterName, String classToCheck, final GroupValidationResult result) {
- if (classToCheck == null || classToCheck.trim().length() == 0) {
- result.setResult(parameterName, ValidationStatus.INVALID, "parameter is null or blank");
+ private Class<?> getClass(String parameterName, String classToCheck, final BeanValidationResult result) {
+ if (StringUtils.isBlank(classToCheck)) {
+ result.addResult(parameterName, classToCheck, ValidationStatus.INVALID, "parameter is null or blank");
return null;
}
@@ -196,7 +198,8 @@ public class JavaSchemaHelperJsonAdapterParameters implements ParameterGroup {
try {
return Class.forName(classToCheck);
} catch (final ClassNotFoundException e) {
- result.setResult(parameterName, ValidationStatus.INVALID, "class not found: " + e.getMessage());
+ result.addResult(parameterName, classToCheck, ValidationStatus.INVALID,
+ "class not found: " + e.getMessage());
LOGGER.warn("class not found: ", e);
return null;
}
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParameters.java
index 2c57d4ea9..417a2e8ce 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParameters.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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.
@@ -22,9 +23,9 @@ package org.onap.policy.apex.context.impl.schema.java;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Map.Entry;
import org.onap.policy.apex.context.parameters.SchemaHelperParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
/**
* The Schema helper parameter class for the Java schema helper is an empty parameter class that acts as a placeholder.
@@ -33,7 +34,7 @@ import org.onap.policy.common.parameters.GroupValidationResult;
*/
public class JavaSchemaHelperParameters extends SchemaHelperParameters {
// Map of specific type adapters for this event
- private Map<String, JavaSchemaHelperJsonAdapterParameters> jsonAdapters = new LinkedHashMap<>();
+ private Map<String, @NotNull @Valid JavaSchemaHelperJsonAdapterParameters> jsonAdapters = new LinkedHashMap<>();
/**
* Constructor for Java schema helper parameters.
@@ -61,17 +62,4 @@ public class JavaSchemaHelperParameters extends SchemaHelperParameters {
this.jsonAdapters = jsonAdapters;
}
- /**
- * {@inheritDoc}.
- */
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = new GroupValidationResult(this);
-
- for (Entry<String, JavaSchemaHelperJsonAdapterParameters> typeAdapterEntry : jsonAdapters.entrySet()) {
- result.setResult("jsonAdapters", typeAdapterEntry.getKey(), typeAdapterEntry.getValue().validate());
- }
- return result;
- }
-
}
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/ContextParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/ContextParameters.java
index 21b3a5eaf..56b6c8ec4 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/ContextParameters.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/ContextParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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.
@@ -20,8 +21,9 @@
package org.onap.policy.apex.context.parameters;
-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.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
// @formatter:off
/**
@@ -42,25 +44,19 @@ import org.onap.policy.common.parameters.ParameterGroup;
* being used for context album persistence
* </ol>
*/
-// @formatter:on
-public class ContextParameters implements ParameterGroup {
- // @formatter:off
- // Plugin Parameters
- private String name;
- private DistributorParameters distributorParameters = new DistributorParameters();
- private SchemaParameters schemaParameters = new SchemaParameters();
- private LockManagerParameters lockManagerParameters = new LockManagerParameters();
- private PersistorParameters persistorParameters = new PersistorParameters();
+@NotNull
+public class ContextParameters extends ParameterGroupImpl {
+ private @Valid DistributorParameters distributorParameters = new DistributorParameters();
+ private @Valid SchemaParameters schemaParameters = new SchemaParameters();
+ private @Valid LockManagerParameters lockManagerParameters = new LockManagerParameters();
+ private @Valid PersistorParameters persistorParameters = new PersistorParameters();
// @formatter:on
/**
* Constructor to create a context parameters instance and register the instance with the parameter service.
*/
public ContextParameters() {
- super();
-
- // Set the name for the parameters
- this.name = ContextParameterConstants.MAIN_GROUP_NAME;
+ super(ContextParameterConstants.MAIN_GROUP_NAME);
}
/**
@@ -137,32 +133,8 @@ public class ContextParameters implements ParameterGroup {
@Override
public String toString() {
- return "ContextParameters [name=" + name + ", distributorParameters=" + distributorParameters
+ return "ContextParameters [name=" + getName() + ", distributorParameters=" + distributorParameters
+ ", schemaParameters=" + schemaParameters + ", lockManagerParameters=" + lockManagerParameters
+ ", persistorParameters=" + persistorParameters + "]";
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- GroupValidationResult result = new GroupValidationResult(this);
-
- // @formatter:off
- result.setResult("distributorParameters", distributorParameters.validate());
- result.setResult("schemaParameters", schemaParameters.validate());
- result.setResult("lockManagerParameters", lockManagerParameters.validate());
- result.setResult("persistorParameters", persistorParameters.validate());
- // @formatter:on
-
- return result;
- }
}
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/DistributorParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/DistributorParameters.java
index 8cb6c5916..e1432e6c5 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/DistributorParameters.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/DistributorParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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.
@@ -21,8 +22,9 @@
package org.onap.policy.apex.context.parameters;
import org.onap.policy.apex.context.impl.distribution.jvmlocal.JvmLocalDistributor;
-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.annotations.ClassName;
+import org.onap.policy.common.parameters.annotations.NotNull;
/**
* An empty distributor parameter class that may be specialized by context distributor plugins that
@@ -31,22 +33,19 @@ import org.onap.policy.common.parameters.ParameterGroup;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class DistributorParameters implements ParameterGroup {
+@NotNull
+public class DistributorParameters extends ParameterGroupImpl {
/** The default distributor makes context albums available to all threads in a single JVM. */
public static final String DEFAULT_DISTRIBUTOR_PLUGIN_CLASS = JvmLocalDistributor.class.getName();
- private String name;
- private String pluginClass = DEFAULT_DISTRIBUTOR_PLUGIN_CLASS;
+ private @ClassName String pluginClass = DEFAULT_DISTRIBUTOR_PLUGIN_CLASS;
/**
* Constructor to create a distributor parameters instance and register the instance with the
* parameter service.
*/
public DistributorParameters() {
- super();
-
- // Set the name for the parameters
- this.name = ContextParameterConstants.DISTRIBUTOR_GROUP_NAME;
+ super(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
}
/**
@@ -69,21 +68,6 @@ public class DistributorParameters implements ParameterGroup {
@Override
public String toString() {
- return "DistributorParameters [name=" + name + ", pluginClass=" + pluginClass + "]";
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
+ return "DistributorParameters [name=" + getName() + ", pluginClass=" + pluginClass + "]";
}
}
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/LockManagerParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/LockManagerParameters.java
index 2f8aa0d2a..d49adf464 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/LockManagerParameters.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/LockManagerParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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.
@@ -21,8 +22,9 @@
package org.onap.policy.apex.context.parameters;
import org.onap.policy.apex.context.impl.locking.jvmlocal.JvmLocalLockManager;
-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.annotations.ClassName;
+import org.onap.policy.common.parameters.annotations.NotNull;
/**
* An empty lock manager parameter class that may be specialized by context lock manager plugins
@@ -31,24 +33,21 @@ import org.onap.policy.common.parameters.ParameterGroup;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class LockManagerParameters implements ParameterGroup {
+@NotNull
+public class LockManagerParameters extends ParameterGroupImpl {
/**
* The default lock manager can lock context album instance across all threads in a single JVM.
*/
public static final String DEFAULT_LOCK_MANAGER_PLUGIN_CLASS = JvmLocalLockManager.class.getName();
- private String name;
- private String pluginClass = DEFAULT_LOCK_MANAGER_PLUGIN_CLASS;
+ private @ClassName String pluginClass = DEFAULT_LOCK_MANAGER_PLUGIN_CLASS;
/**
* Constructor to create a lock manager parameters instance and register the instance with the
* parameter service.
*/
public LockManagerParameters() {
- super();
-
- // Set the name for the parameters
- this.name = ContextParameterConstants.LOCKING_GROUP_NAME;
+ super(ContextParameterConstants.LOCKING_GROUP_NAME);
}
/**
@@ -68,24 +67,9 @@ public class LockManagerParameters implements ParameterGroup {
public void setPluginClass(final String pluginClass) {
this.pluginClass = pluginClass;
}
-
- @Override
- public String toString() {
- return "LockManagerParameters [name=" + name + ", pluginClass=" + pluginClass + "]";
- }
@Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
+ public String toString() {
+ return "LockManagerParameters [name=" + getName() + ", pluginClass=" + pluginClass + "]";
}
}
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/PersistorParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/PersistorParameters.java
index 3616b526e..98865cd88 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/PersistorParameters.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/PersistorParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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.
@@ -20,8 +21,9 @@
package org.onap.policy.apex.context.parameters;
-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.annotations.ClassName;
+import org.onap.policy.common.parameters.annotations.NotNull;
/**
* A persistor parameter class that may be specialized by context persistor plugins that require
@@ -36,7 +38,8 @@ import org.onap.policy.common.parameters.ParameterGroup;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class PersistorParameters implements ParameterGroup {
+@NotNull
+public class PersistorParameters extends ParameterGroupImpl {
/** The default persistor is a dummy persistor that stubs the Persistor interface. */
public static final String DEFAULT_PERSISTOR_PLUGIN_CLASS =
"org.onap.policy.apex.context.impl.persistence.ephemeral.EphemeralPersistor";
@@ -44,8 +47,7 @@ public class PersistorParameters implements ParameterGroup {
/** Default periodic flushing interval, 5 minutes in milliseconds. */
public static final long DEFAULT_FLUSH_PERIOD = 300000;
- private String name;
- private String pluginClass = DEFAULT_PERSISTOR_PLUGIN_CLASS;
+ private @ClassName String pluginClass = DEFAULT_PERSISTOR_PLUGIN_CLASS;
// Parameters for flushing
private long flushPeriod = DEFAULT_FLUSH_PERIOD;
@@ -55,10 +57,7 @@ public class PersistorParameters implements ParameterGroup {
* parameter service.
*/
public PersistorParameters() {
- super();
-
- // Set the name for the parameters
- this.name = ContextParameterConstants.PERSISTENCE_GROUP_NAME;
+ super(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
}
/**
@@ -103,22 +102,7 @@ public class PersistorParameters implements ParameterGroup {
@Override
public String toString() {
- return "PersistorParameters [name=" + name + ", pluginClass=" + pluginClass + ", flushPeriod=" + flushPeriod
- + "]";
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
+ return "PersistorParameters [name=" + getName() + ", pluginClass=" + pluginClass + ", flushPeriod="
+ + flushPeriod + "]";
}
}
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaHelperParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaHelperParameters.java
index e2bb4d6b9..0c6d3592b 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaHelperParameters.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaHelperParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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.
@@ -20,8 +21,9 @@
package org.onap.policy.apex.context.parameters;
-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.annotations.ClassName;
+import org.onap.policy.common.parameters.annotations.NotNull;
/**
* An empty schema helper parameter class that may be specialized by context schema helper plugins that require plugin
@@ -29,9 +31,9 @@ import org.onap.policy.common.parameters.ParameterGroup;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class SchemaHelperParameters implements ParameterGroup {
- private String name;
- private String schemaHelperPluginClass;
+@NotNull
+public class SchemaHelperParameters extends ParameterGroupImpl {
+ private @ClassName String schemaHelperPluginClass;
/**
* Constructor to create a schema helper parameters instance and register the instance with the parameter service.
@@ -57,24 +59,10 @@ public class SchemaHelperParameters implements ParameterGroup {
public void setSchemaHelperPluginClass(final String pluginClass) {
schemaHelperPluginClass = pluginClass;
}
-
- @Override
- public String toString() {
- return "SchemaHelperParameters [name=" + name + ", schemaHelperPluginClass=" + schemaHelperPluginClass + "]";
- }
-
- @Override
- public String getName() {
- return name;
- }
@Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
+ public String toString() {
+ return "SchemaHelperParameters [name=" + getName() + ", schemaHelperPluginClass=" + schemaHelperPluginClass
+ + "]";
}
}
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaParameters.java b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaParameters.java
index 3f5c26e34..a1dedc5c0 100644
--- a/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaParameters.java
+++ b/context/context-management/src/main/java/org/onap/policy/apex/context/parameters/SchemaParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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.
@@ -21,11 +22,11 @@
package org.onap.policy.apex.context.parameters;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.TreeMap;
import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters;
-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.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
/**
* Bean class holding schema parameters for schemas and their helpers. As more than one schema can be used in Apex
@@ -37,23 +38,20 @@ import org.onap.policy.common.parameters.ParameterGroup;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class SchemaParameters implements ParameterGroup {
+@NotNull
+public class SchemaParameters extends ParameterGroupImpl {
/** The Java schema flavour is always available for use. */
public static final String DEFAULT_SCHEMA_FLAVOUR = "Java";
- private String name;
// A map of parameters for executors of various logic types
- private Map<String, SchemaHelperParameters> schemaHelperParameterMap;
+ private Map<String, @NotNull @Valid SchemaHelperParameters> schemaHelperParameterMap;
/**
* Constructor to create a distributor parameters instance and register the instance with the parameter service.
*/
public SchemaParameters() {
- super();
-
- // Set the name for the parameters
- this.name = ContextParameterConstants.SCHEMA_GROUP_NAME;
+ super(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaHelperParameterMap = new TreeMap<>();
@@ -88,25 +86,4 @@ public class SchemaParameters implements ParameterGroup {
public SchemaHelperParameters getSchemaHelperParameters(final String schemaFlavour) {
return schemaHelperParameterMap.get(schemaFlavour);
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = new GroupValidationResult(this);
-
- for (Entry<String, SchemaHelperParameters> schemaHelperEntry : schemaHelperParameterMap.entrySet()) {
- result.setResult("schemaHelperParameterMap", schemaHelperEntry.getKey(),
- schemaHelperEntry.getValue().validate());
- }
- return result;
- }
}
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameters.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameters.java
index 3ca74153e..3cf43c581 100644
--- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameters.java
+++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/EngineParameters.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 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,14 +25,13 @@ package org.onap.policy.apex.core.engine;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.TreeMap;
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.apex.context.parameters.ContextParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
-import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
/**
* This class holds the parameters for a single Apex engine. This parameter class holds parameters for context schemas
@@ -51,44 +51,21 @@ import org.onap.policy.common.parameters.ValidationResult;
*/
@Getter
@Setter
-public class EngineParameters implements ParameterGroup {
- private ContextParameters contextParameters = new ContextParameters();
+@NotNull
+public class EngineParameters extends ParameterGroupImpl {
+ private @Valid ContextParameters contextParameters = new ContextParameters();
- // Parameter group name
- private String name;
// A map of parameters for executors of various logic types
- private Map<String, ExecutorParameters> executorParameterMap = new TreeMap<>();
+ private Map<String, @NotNull @Valid ExecutorParameters> executorParameterMap = new TreeMap<>();
// A list of parameters to be passed to the task, so that they can be used in the logic
- private List<TaskParameters> taskParameters = new ArrayList<>();
+ private List<@NotNull @Valid TaskParameters> taskParameters = new ArrayList<>();
/**
* Constructor to create an engine parameters instance and register the instance with the parameter service.
*/
public EngineParameters() {
- super();
-
- // Set the name for the parameters
- this.name = EngineParameterConstants.MAIN_GROUP_NAME;
+ super(EngineParameterConstants.MAIN_GROUP_NAME);
}
-
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = new GroupValidationResult(this);
-
- result.setResult("contextParameters", contextParameters.validate());
-
- for (Entry<String, ExecutorParameters> executorParEntry : executorParameterMap.entrySet()) {
- result.setResult("executorParameterMap", executorParEntry.getKey(), executorParEntry.getValue().validate());
- }
- for (TaskParameters taskParam : taskParameters) {
- ValidationResult taskParamValidationResult = taskParam.validate("taskParameters");
- result.setResult(taskParamValidationResult.getName(), taskParamValidationResult.getStatus(),
- taskParamValidationResult.getResult());
- }
- return result;
- }
-
-
}
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/ExecutorParameters.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/ExecutorParameters.java
index 7de121d66..7bff07d9a 100644
--- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/ExecutorParameters.java
+++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/ExecutorParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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.
@@ -20,8 +21,7 @@
package org.onap.policy.apex.core.engine;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
/**
* This class provides the executors for a logic flavour. Plugin classes for execution of task
@@ -32,10 +32,7 @@ import org.onap.policy.common.parameters.ParameterGroup;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class ExecutorParameters implements ParameterGroup {
- // Parameter group name
- private String name;
-
+public class ExecutorParameters extends ParameterGroupImpl {
// Executor Plugin classes for executors
private String taskExecutorPluginClass;
private String taskSelectionExecutorPluginClass;
@@ -46,10 +43,7 @@ public class ExecutorParameters implements ParameterGroup {
* parameter service.
*/
public ExecutorParameters() {
- super();
-
- // Set the name for the parameters
- this.name = EngineParameterConstants.EXECUTOR_GROUP_NAME;
+ super(EngineParameterConstants.EXECUTOR_GROUP_NAME);
}
/**
@@ -110,23 +104,8 @@ public class ExecutorParameters implements ParameterGroup {
@Override
public String toString() {
- return "ExecutorParameters [name=" + name + ", taskExecutorPluginClass=" + taskExecutorPluginClass
+ return "ExecutorParameters [name=" + getName() + ", taskExecutorPluginClass=" + taskExecutorPluginClass
+ ", taskSelectionExecutorPluginClass=" + taskSelectionExecutorPluginClass
+ ", stateFinalizerExecutorPluginClass=" + stateFinalizerExecutorPluginClass + "]";
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- @Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
- }
}
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.java
index ba936f24a..5427c3515 100644
--- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.java
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 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.
@@ -21,6 +22,7 @@
package org.onap.policy.apex.core.engine;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -59,6 +61,8 @@ public class EngineParametersTest {
taskParameters.add(new TaskParameters("param1key", "param1value", "param1taskId"));
taskParameters.add(new TaskParameters("param1key", "param1value", null));
pars.setTaskParameters(taskParameters);
+
+ assertThat(pars.validate().getResult()).isNull();
assertTrue(pars.validate().isValid());
ParameterService.register(pars);
diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java
index 88c8c852d..784580422 100644
--- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java
+++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java
@@ -1,25 +1,27 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * 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.
* 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.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.core.engine;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -47,10 +49,11 @@ public class ExecutorParametersTest {
assertEquals("ExecutorParameters [name=Name, taskExecutorPluginClass=some.task.executor.plugin.class, "
+ "taskSelectionExecutorPluginClass=some.task.selection.executor.plugin.class, "
+ "stateFinalizerExecutorPluginClass=some.state.finalizer.plugin.class]", pars.toString());
-
+
+ assertThat(pars.validate().getResult()).isNull();
assertTrue(pars.validate().isValid());
-
-
+
+
ParameterService.register(pars);
ParameterService.deregister(pars);
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java
index 480d8423b..7c79e95b6 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 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.
@@ -28,7 +29,7 @@ import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.apex.service.engine.event.ApexEventException;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
public class GrpcCarrierTechnologyParametersTest {
@@ -45,7 +46,7 @@ public class GrpcCarrierTechnologyParametersTest {
@Test
public void testGrpcCarrierTechnologyParameters_invalid_producer_params() throws ApexEventException {
- GroupValidationResult result = params.validate();
+ ValidationResult result = params.validate();
assertTrue(result.isValid());
assertThatThrownBy(() -> params.validateGrpcParameters(true))
.hasMessage("Issues in specifying gRPC Producer parameters:\ntimeout should have a positive value.\n"
@@ -64,7 +65,7 @@ public class GrpcCarrierTechnologyParametersTest {
params.setPort(2233);
params.setTimeout(1000);
params.setUsername(USERNAME);
- GroupValidationResult result = params.validate();
+ ValidationResult result = params.validate();
assertTrue(result.isValid());
Assertions.assertThatCode(() -> params.validateGrpcParameters(true)).doesNotThrowAnyException();
}
@@ -77,7 +78,7 @@ public class GrpcCarrierTechnologyParametersTest {
params.setUsername(USERNAME);
params.setPort(23); // invalid value
- GroupValidationResult result = params.validate();
+ ValidationResult result = params.validate();
assertTrue(result.isValid());
assertThatThrownBy(() -> params.validateGrpcParameters(true))
.hasMessageContaining("port range should be between 1024 and 65535");
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParameters.java
index d93a1b981..d4647b584 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParameters.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParameters.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019,2021 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.
@@ -23,10 +24,10 @@ package org.onap.policy.apex.plugins.event.carrier.jms;
import java.util.Properties;
import javax.naming.Context;
-import org.apache.commons.lang3.StringUtils;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
/**
* Apex parameters for JMS as an event carrier technology.
@@ -100,12 +101,19 @@ public class JmsCarrierTechnologyParameters extends CarrierTechnologyParameters
// JMS carrier parameters
private String connectionFactory = DEFAULT_CONNECTION_FACTORY;
+ @NotNull @NotBlank
private String initialContextFactory = DEFAULT_INITIAL_CTXT_FACTORY;
+ @NotNull @NotBlank
private String providerUrl = DEFAULT_PROVIDER_URL;
+ @NotNull @NotBlank
private String securityPrincipal = DEFAULT_SECURITY_PRINCIPAL;
+ @NotNull @NotBlank
private String securityCredentials = DEFAULT_SECURITY_CREDENTIALS;
+ @NotNull @NotBlank
private String producerTopic = DEFAULT_PRODUCER_TOPIC;
+ @NotNull @NotBlank
private String consumerTopic = DEFAULT_CONSUMER_TOPIC;
+ @Min(0)
private int consumerWaitTime = DEFAULT_CONSUMER_WAIT_TIME;
private boolean objectMessageSending = DEFAULT_TO_OBJECT_MSG_SENDING;
// @formatter:on
@@ -327,56 +335,4 @@ public class JmsCarrierTechnologyParameters extends CarrierTechnologyParameters
public void setObjectMessageSending(final boolean objectMessageSending) {
this.objectMessageSending = objectMessageSending;
}
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = super.validate();
-
- if (StringUtils.isBlank(initialContextFactory)) {
- result.setResult("initialContextFactory", ValidationStatus.INVALID,
- "initialContextFactory must be specified as a string that is a class that implements the "
- + "interface org.jboss.naming.remote.client.InitialContextFactory");
- }
-
- if (StringUtils.isBlank(providerUrl)) {
- result.setResult("providerUrl", ValidationStatus.INVALID,
- "providerUrl must be specified as a URL string that specifies the location of "
- + "configuration information for the service provider to use "
- + "such as remote://localhost:4447");
- }
-
- if (StringUtils.isBlank(securityPrincipal)) {
- result.setResult("securityPrincipal", ValidationStatus.INVALID,
- "securityPrincipal must be specified the identity of the principal for authenticating "
- + "the caller to the service");
- }
-
- if (StringUtils.isBlank(securityCredentials)) {
- result.setResult("securityCredentials", ValidationStatus.INVALID,
- " securityCredentials must be specified as the credentials of the "
- + "principal for authenticating the caller to the service");
- }
-
- if (StringUtils.isBlank(producerTopic)) {
- result.setResult("producerTopic", ValidationStatus.INVALID,
- " producerTopic must be a string that identifies the JMS topic "
- + "on which Apex will send events");
- }
-
- if (StringUtils.isBlank(consumerTopic)) {
- result.setResult("consumerTopic", ValidationStatus.INVALID,
- " consumerTopic must be a string that identifies the JMS topic "
- + "on which Apex will recieve events");
- }
-
- if (consumerWaitTime < 0) {
- result.setResult("consumerWaitTime", ValidationStatus.INVALID,
- "[" + consumerWaitTime + "] invalid, must be specified as consumerWaitTime >= 0");
- }
-
- return result;
- }
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java
index 5f1b99500..36f2e31ce 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
* Modifications Copyright (C) 2019,2021 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.
@@ -32,15 +33,15 @@ import java.util.Properties;
import javax.naming.Context;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ParameterRuntimeException;
+import org.onap.policy.common.parameters.ValidationResult;
public class JmsCarrierTechnologyParametersTest {
JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null;
Properties jmsProducerProperties = null;
Properties jmsConsumerProperties = null;
- GroupValidationResult result = null;
+ ValidationResult result = null;
public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS";
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParameters.java
index eb1f15c93..475017283 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParameters.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/main/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParameters.java
@@ -3,6 +3,7 @@
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
+ * 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.
@@ -25,16 +26,20 @@ package org.onap.policy.apex.plugins.event.carrier.kafka;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
import java.util.Properties;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.producer.internals.DefaultPartitioner;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.BeanValidationResult;
+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.Min;
import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.models.base.Validated;
/**
* Apex parameters for Kafka as an event carrier technology.
@@ -226,68 +231,76 @@ public class KafkaCarrierTechnologyParameters extends CarrierTechnologyParameter
* {@inheritDoc}.
*/
@Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = super.validate();
+ public BeanValidationResult validate() {
+ final BeanValidationResult result = super.validate();
- validateConsumerTopicList(result);
+ result.addResult(validateConsumerTopicList());
- validateKafkaProperties(result);
+ result.addResult(validateKafkaProperties());
return result;
}
/**
* Validate the consumer topic list.
- *
- * @param result the result of the validation.
*/
- private void validateConsumerTopicList(final GroupValidationResult result) {
+ private ValidationResult validateConsumerTopicList() {
if (consumerTopicList == null || consumerTopicList.length == 0) {
- result.setResult("consumerTopicList", ValidationStatus.INVALID,
+ return new ObjectValidationResult("consumerTopicList", consumerTopicList, ValidationStatus.INVALID,
"not specified, must be specified as a list of strings");
- return;
}
- StringBuilder consumerTopicStringBuilder = new StringBuilder();
+ BeanValidationResult result = new BeanValidationResult("consumerTopicList", consumerTopicList);
+ int item = 0;
for (final String consumerTopic : consumerTopicList) {
if (StringUtils.isBlank(consumerTopic)) {
- consumerTopicStringBuilder.append(consumerTopic + "/");
+ result.addResult(ENTRY + item, consumerTopic, ValidationStatus.INVALID, Validated.IS_BLANK);
}
+
+ ++item;
}
- if (consumerTopicStringBuilder.length() > 0) {
- result.setResult("consumerTopicList", ValidationStatus.INVALID,
- "invalid consumer topic list entries found: /" + consumerTopicStringBuilder.toString());
- }
+
+ return result;
}
/**
* Validate the kafka properties.
- *
- * @param result the result of the validation.
*/
- private void validateKafkaProperties(final GroupValidationResult result) {
+ private ValidationResult validateKafkaProperties() {
// Kafka properties are optional
if (kafkaProperties == null || kafkaProperties.length == 0) {
- return;
+ return null;
}
- for (int i = 0; i < kafkaProperties.length; i++) {
- if (kafkaProperties[i].length != 2) {
- result.setResult(KAFKA_PROPERTIES, ValidationStatus.INVALID,
- ENTRY + i + " invalid, kafka properties must be name-value pairs");
- }
+ BeanValidationResult result = new BeanValidationResult(KAFKA_PROPERTIES, kafkaProperties);
- if (StringUtils.isBlank(kafkaProperties[i][0])) {
- result.setResult(KAFKA_PROPERTIES, ValidationStatus.INVALID,
- ENTRY + i + " invalid, key is null or blank");
+ for (int i = 0; i < kafkaProperties.length; i++) {
+ final String label = ENTRY + i;
+ final String[] kafkaProperty = kafkaProperties[i];
+ final List<String> value = (kafkaProperty == null ? null : Arrays.asList(kafkaProperty));
+ final BeanValidationResult result2 = new BeanValidationResult(label, value);
+
+ if (kafkaProperty == null) {
+ // note: add to result, not result2
+ result.addResult(label, value, ValidationStatus.INVALID, Validated.IS_NULL);
+
+ } else if (kafkaProperty.length != 2) {
+ // note: add to result, not result2
+ result.addResult(label, Arrays.asList(kafkaProperty), ValidationStatus.INVALID,
+ "kafka properties must be name-value pairs");
+
+ } else if (StringUtils.isBlank(kafkaProperty[0])) {
+ result2.addResult("key", kafkaProperty[0], ValidationStatus.INVALID, Validated.IS_BLANK);
+
+ } else if (null == kafkaProperty[1]) {
+ // the value of a property has to be specified as empty in some cases, but should never be null.
+ result2.addResult("value", kafkaProperty[1], ValidationStatus.INVALID, Validated.IS_NULL);
}
- // the value of a property has to be specified as empty in some cases, but should never be null.
- if (null == kafkaProperties[i][1]) {
- result.setResult(KAFKA_PROPERTIES, ValidationStatus.INVALID,
- ENTRY + i + " invalid, value is null");
- }
+ result.addResult(result2);
}
+
+ return result;
}
/**
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParameters.java
index d5bca3f5a..23936439a 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParameters.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParameters.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 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,8 @@ package org.onap.policy.apex.plugins.event.carrier.restclient;
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ObjectValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
// @formatter:off
@@ -66,14 +68,13 @@ public class RestClientCarrierTechnologyParameters extends RestPluginCarrierTech
* {@inheritDoc}
*/
@Override
- public GroupValidationResult validateUrl(final GroupValidationResult result) {
+ public ValidationResult validateUrl() {
// Check if the URL has been set for event output
- final String urlNullMessage = "no URL has been set for event sending on " + getLabel();
if (getUrl() == null) {
- result.setResult("url", ValidationStatus.INVALID, urlNullMessage);
- return result;
+ final String urlNullMessage = "no URL has been set for event sending on " + getLabel();
+ return new ObjectValidationResult("url", null, ValidationStatus.INVALID, urlNullMessage);
}
- return super.validateUrl(result);
+ return super.validateUrl();
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java
index 9d4da1cd0..58d265a97 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java
@@ -3,6 +3,7 @@
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * 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.
@@ -47,7 +48,10 @@ public class RestClientCarrierTechnologyParametersTest {
arguments.setRelativeFileRoot(".");
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessageContaining("HTTP header array entry is null\n parameter");
+ .hasMessageContaining("httpHeaders")
+ .hasMessageContaining("item \"entry 0\" value \"null\" INVALID, is null")
+ .hasMessageContaining("item \"entry 1\" value \"null\" INVALID, is null")
+ .hasMessageContaining("item \"entry 2\" value \"null\" INVALID, is null");
}
@Test
@@ -57,8 +61,9 @@ public class RestClientCarrierTechnologyParametersTest {
arguments.setRelativeFileRoot(".");
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessageContaining("HTTP header array entries must have one key and one value: [aaa, bbb, ccc]")
- .hasMessageEndingWith("HTTP header array entries must have one key and one value: [aaa]\n");
+ .hasMessageContaining("httpHeaders")
+ .hasMessageContaining("\"entry 0\" value \"[aaa, bbb, ccc]\" INVALID, must have one key and one value")
+ .hasMessageContaining("\"entry 0\" value \"[aaa]\" INVALID, must have one key and one value");
}
@Test
@@ -68,8 +73,9 @@ public class RestClientCarrierTechnologyParametersTest {
arguments.setRelativeFileRoot(".");
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessageContaining("HTTP header key is null or blank: [null, bbb]")
- .hasMessageEndingWith("HTTP header value is null or blank: [ccc, null]\n");
+ .hasMessageContaining("httpHeaders", "entry 0", "entry 1")
+ .hasMessageContaining("item \"key\" value \"null\" INVALID, is blank")
+ .hasMessageContaining("item \"value\" value \"null\" INVALID, is blank");
}
@Test
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java
index d5268b14c..f17721bdc 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java
@@ -43,19 +43,19 @@ public class RestRequestorCarrierTechnologyParametersTest {
@Test
public void testRestRequestorCarrierTechnologyParametersBadList() {
verifyException("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderBadList.json",
- "HTTP header array entry is null\n parameter");
+ "item \"entry 2\" value \"null\" INVALID, is null");
}
@Test
public void testRestRequestorCarrierTechnologyParametersNotKvPairs() {
verifyException("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNotKvPairs.json",
- "HTTP header array entries must have one key and one value: [aaa, bbb, ccc]");
+ "item \"entry 0\" value \"[aaa, bbb, ccc]\" INVALID, must have one key");
}
@Test
public void testRestRequestorCarrierTechnologyParametersNulls() {
verifyException("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNulls.json",
- "HTTP header key is null or blank: [null, bbb]");
+ "\"key\"");
}
private void verifyException(String fileName, String expectedMsg) {
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParameters.java
index afc07da95..bf24d2260 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParameters.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParameters.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications 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,9 +25,11 @@ package org.onap.policy.apex.plugins.event.carrier.restserver;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.models.base.Validated;
/**
* Apex parameters for REST as an event carrier technology with Apex as a REST client.
@@ -89,27 +92,25 @@ public class RestServerCarrierTechnologyParameters extends CarrierTechnologyPara
* {@inheritDoc}.
*/
@Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = super.validate();
+ public BeanValidationResult validate() {
+ final BeanValidationResult result = super.validate();
// Check if host is defined, it is only defined on REST server consumers
if (standalone) {
- if (host != null && host.trim().length() == 0) {
- result.setResult("host", ValidationStatus.INVALID,
- "host not specified, host must be specified as a string");
+ if (StringUtils.isBlank(host)) {
+ result.addResult("host", host, ValidationStatus.INVALID, Validated.IS_BLANK);
}
// Check if port is defined, it is only defined on REST server consumers
if (port != -1 && port < MIN_USER_PORT || port > MAX_USER_PORT) {
- result.setResult("port", ValidationStatus.INVALID,
- "[" + port + "] invalid, must be specified as 1024 <= port <= 65535");
+ result.addResult("port", port, ValidationStatus.INVALID, "must be between 1024 and 65535");
}
} else {
if (host != null) {
- result.setResult("host", ValidationStatus.INVALID, "host is specified only in standalone mode");
+ result.addResult("host", host, ValidationStatus.INVALID, "should be specified only in standalone mode");
}
if (port != -1) {
- result.setResult("port", ValidationStatus.INVALID, "port is specified only in standalone mode");
+ result.addResult("port", port, ValidationStatus.INVALID, "should be specified only in standalone mode");
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java
index 2c8a764e8..ef78d3211 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
* Modifications 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.
@@ -21,6 +22,7 @@
package org.onap.policy.apex.plugins.event.carrier.restserver;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -28,12 +30,12 @@ import static org.junit.Assert.assertTrue;
import java.lang.reflect.Field;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
public class RestServerCarrierTechnologyParametersTest {
RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null;
- GroupValidationResult result = null;
+ ValidationResult result = null;
/**
* Set up testing.
@@ -144,7 +146,6 @@ public class RestServerCarrierTechnologyParametersTest {
result = restServerCarrierTechnologyParameters.validate();
assertNotNull(result);
assertFalse(result.isValid());
- assertTrue(result.getResult().contains("host is specified only in standalone mode"));
- assertTrue(result.getResult().contains("port is specified only in standalone mode"));
+ assertThat(result.getResult()).contains("host", "port", "should be specified only in standalone mode");
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParameters.java
index c77aac9a9..f867020ec 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParameters.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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.
@@ -20,9 +21,13 @@
package org.onap.policy.apex.plugins.event.carrier.websocket;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.parameters.annotations.Max;
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.models.base.Validated;
/**
* Apex parameters for Kafka as an event carrier technology.
@@ -50,6 +55,8 @@ public class WebSocketCarrierTechnologyParameters extends CarrierTechnologyParam
// Web socket parameters
private boolean wsClient = true;
private String host = DEFAULT_HOST;
+ @Min(MIN_USER_PORT)
+ @Max(MAX_USER_PORT)
private int port = DEFAULT_PORT;
// @formatter:on
@@ -97,16 +104,11 @@ public class WebSocketCarrierTechnologyParameters extends CarrierTechnologyParam
* {@inheritDoc}.
*/
@Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = super.validate();
+ public BeanValidationResult validate() {
+ final BeanValidationResult result = super.validate();
- if (wsClient && (host == null || host.trim().length() == 0)) {
- result.setResult("host", ValidationStatus.INVALID, "host not specified, must be host as a string");
- }
-
- if (port < MIN_USER_PORT || port > MAX_USER_PORT) {
- result.setResult("port", ValidationStatus.INVALID,
- "[" + port + "] invalid, must be specified as 1024 <= port <= 65535");
+ if (wsClient && StringUtils.isBlank(host)) {
+ result.addResult("host", host, ValidationStatus.INVALID, Validated.IS_BLANK);
}
return result;
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParametersTest.java
index 1ab732141..f318c000a 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/WebSocketCarrierTechnologyParametersTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
* Modifications 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.
@@ -26,12 +27,12 @@ import static org.junit.Assert.assertNotNull;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
public class WebSocketCarrierTechnologyParametersTest {
WebSocketCarrierTechnologyParameters webSocketCarrierTechnologyParameters = null;
- GroupValidationResult result = null;
+ ValidationResult result = null;
/**
* Set up testing.
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParameters.java
index 6f352599c..635597548 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParameters.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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.
* 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.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -21,7 +22,6 @@
package org.onap.policy.apex.service.engine.event.impl.eventrequestor;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
/**
* This class holds the parameters that allows an output event to to be sent back into APEX as one
@@ -60,14 +60,6 @@ public class EventRequestorCarrierTechnologyParameters extends CarrierTechnology
* {@inheritDoc}.
*/
@Override
- public GroupValidationResult validate() {
- return new GroupValidationResult(this);
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
public String getName() {
return this.getLabel();
}
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParameters.java
index 5071824ce..eceb0b4f9 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParameters.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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.
* 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.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -21,12 +22,18 @@
package org.onap.policy.apex.service.engine.event.impl.filecarrierplugin;
import java.io.File;
+import lombok.Getter;
+import lombok.Setter;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.ApexFileEventConsumer;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.producer.ApexFileEventProducer;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.BeanValidationResult;
+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.Min;
import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.models.base.Validated;
/**
* This class holds the parameters that allows transport of events into and out of Apex using files and standard input
@@ -42,6 +49,8 @@ import org.onap.policy.common.utils.validation.ParameterValidationUtils;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
+@Getter
+@Setter
public class FileCarrierTechnologyParameters extends CarrierTechnologyParameters {
// @formatter:off
/** The label of this carrier technology. */
@@ -60,7 +69,7 @@ public class FileCarrierTechnologyParameters extends CarrierTechnologyParameters
private boolean standardIo = false;
private boolean standardError = false;
private boolean streamingMode = false;
- private long startDelay = 0;
+ private @Min(0) long startDelay = 0;
// @formatter:on
/**
@@ -77,96 +86,6 @@ public class FileCarrierTechnologyParameters extends CarrierTechnologyParameters
}
/**
- * Gets the file name from which to read or to which to write events.
- *
- * @return the file name from which to read or to which to write events
- */
- public String getFileName() {
- return fileName;
- }
-
- /**
- * Checks if is standard IO should be used for input or output.
- *
- * @return true, if standard IO should be used for input or output
- */
- public boolean isStandardIo() {
- return standardIo;
- }
-
- /**
- * Checks if is standard error should be used for output.
- *
- * @return true, if standard error should be used for output
- */
- public boolean isStandardError() {
- return standardError;
- }
-
- /**
- * Checks if is streaming mode is on.
- *
- * @return true, if streaming mode is on
- */
- public boolean isStreamingMode() {
- return streamingMode;
- }
-
- /**
- * Sets the file name from which to read or to which to write events.
- *
- * @param fileName the file name from which to read or to which to write events
- */
- public void setFileName(final String fileName) {
- this.fileName = fileName;
- }
-
- /**
- * Sets if standard IO should be used for event input or output.
- *
- * @param standardIo if standard IO should be used for event input or output
- */
- public void setStandardIo(final boolean standardIo) {
- this.standardIo = standardIo;
- }
-
- /**
- * Sets if standard error should be used for event output.
- *
- * @param standardError if standard error should be used for event output
- */
- public void setStandardError(final boolean standardError) {
- this.standardError = standardError;
- }
-
- /**
- * Sets streaming mode.
- *
- * @param streamingMode the streaming mode value
- */
- public void setStreamingMode(final boolean streamingMode) {
- this.streamingMode = streamingMode;
- }
-
- /**
- * Gets the delay in milliseconds before the plugin starts processing.
- *
- * @return the delay
- */
- public long getStartDelay() {
- return startDelay;
- }
-
- /**
- * Sets the delay in milliseconds before the plugin starts processing.
- *
- * @param startDelay the delay
- */
- public void setStartDelay(final long startDelay) {
- this.startDelay = startDelay;
- }
-
- /**
* {@inheritDoc}.
*/
@Override
@@ -188,36 +107,29 @@ public class FileCarrierTechnologyParameters extends CarrierTechnologyParameters
* {@inheritDoc}.
*/
@Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = super.validate();
+ public BeanValidationResult validate() {
+ final BeanValidationResult result = super.validate();
if (!standardIo && !standardError) {
- validateFileName(result);
+ result.addResult(validateFileName());
}
if (standardIo || standardError) {
streamingMode = true;
}
- if (startDelay < 0) {
- result.setResult("startDelay", ValidationStatus.INVALID,
- "startDelay must be zero or a positive number of milliseconds");
- }
-
return result;
}
-
+
/**
* Validate the file name parameter.
- *
- * @param result the variable in which to store the result of the validation
+ *
+ * @return the result of the validation
*/
- private void validateFileName(final GroupValidationResult result) {
+ private ValidationResult validateFileName() {
if (!ParameterValidationUtils.validateStringParameter(fileName)) {
- result.setResult(FILE_NAME_TOKEN, ValidationStatus.INVALID,
- "\"" + fileName + "\" invalid, must be specified as a non-empty string");
- return;
+ return new ObjectValidationResult(FILE_NAME_TOKEN, fileName, ValidationStatus.INVALID, Validated.IS_BLANK);
}
String absoluteFileName = null;
@@ -233,53 +145,65 @@ public class FileCarrierTechnologyParameters extends CarrierTechnologyParameters
// Check if the file exists, the file should be a regular file and should be readable
if (theFile.exists()) {
- validateExistingFile(result, absoluteFileName, theFile);
+ return validateExistingFile(absoluteFileName, theFile);
} else {
// The path to the file should exist and should be writable
- validateNewFileParent(result, absoluteFileName, theFile);
+ return validateNewFileParent(absoluteFileName, theFile);
}
}
/**
* Validate an existing file is OK.
- *
- * @param result the result of the validation
+ *
* @param absoluteFileName the absolute file name of the file
* @param theFile the file that exists
+ * @return the result of the validation
*/
- private void validateExistingFile(final GroupValidationResult result, String absoluteFileName, File theFile) {
+ private ValidationResult validateExistingFile(String absoluteFileName, File theFile) {
// Check that the file is a regular file
if (!theFile.isFile()) {
- result.setResult(FILE_NAME_TOKEN, ValidationStatus.INVALID, "is not a plain file");
+ return new ObjectValidationResult(FILE_NAME_TOKEN, absoluteFileName, ValidationStatus.INVALID,
+ "is not a plain file");
+
} else {
fileName = absoluteFileName;
if (!theFile.canRead()) {
- result.setResult(FILE_NAME_TOKEN, ValidationStatus.INVALID, "is not readable");
+ return new ObjectValidationResult(FILE_NAME_TOKEN, absoluteFileName, ValidationStatus.INVALID,
+ "is not readable");
}
+
+ return null;
}
}
/**
* Validate the parent of a new file is OK.
- *
- * @param result the result of the validation
+ *
* @param absoluteFileName the absolute file name of the file
* @param theFile the file that exists
+ * @return the result of the validation
*/
- private void validateNewFileParent(final GroupValidationResult result, String absoluteFileName, File theFile) {
+ private ValidationResult validateNewFileParent(String absoluteFileName, File theFile) {
// Check that the parent of the file is a directory
if (!theFile.getParentFile().exists()) {
- result.setResult(FILE_NAME_TOKEN, ValidationStatus.INVALID, "parent of file does not exist");
+ return new ObjectValidationResult(FILE_NAME_TOKEN, absoluteFileName, ValidationStatus.INVALID,
+ "parent of file does not exist");
+
} else if (!theFile.getParentFile().isDirectory()) {
// Check that the parent of the file is a directory
- result.setResult(FILE_NAME_TOKEN, ValidationStatus.INVALID, "parent of file is not directory");
+ return new ObjectValidationResult(FILE_NAME_TOKEN, absoluteFileName, ValidationStatus.INVALID,
+ "parent of file is not directory");
+
} else {
fileName = absoluteFileName;
if (!theFile.getParentFile().canRead()) {
- result.setResult(FILE_NAME_TOKEN, ValidationStatus.INVALID, "is not readable");
+ return new ObjectValidationResult(FILE_NAME_TOKEN, absoluteFileName, ValidationStatus.INVALID,
+ "is not readable");
}
+
+ return null;
}
}
}
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java
index 9757c57e8..80974af31 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java
@@ -3,6 +3,7 @@
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
+ * 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.
@@ -106,14 +107,12 @@ public class ApexMain {
// The arguments return a string if there is a message to print and we should exit
final String argumentMessage = arguments.parse(args);
if (argumentMessage != null) {
- LOGGER.info(argumentMessage);
throw new ApexException(argumentMessage);
}
// Validate that the arguments are sane
arguments.validateInputFiles();
} catch (final ApexException | CommandLineException e) {
- LOGGER.error("Arguments validation failed.", e);
throw new ApexException("Arguments validation failed.", e);
}
@@ -122,7 +121,6 @@ public class ApexMain {
try {
axParameters = apexParameterHandler.getParameters(arguments);
} catch (final Exception e) {
- LOGGER.error("Cannot create APEX Parameters from the arguments provided.", e);
throw new ApexException("Cannot create APEX Parameters from the arguments provided.", e);
}
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImpl.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImpl.java
index a558b9946..3deb234c6 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImpl.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImpl.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 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.
@@ -48,7 +49,7 @@ import org.onap.policy.apex.service.engine.runtime.ApexEventListener;
import org.onap.policy.apex.service.engine.runtime.EngineService;
import org.onap.policy.apex.service.engine.runtime.EngineServiceEventInterface;
import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -138,7 +139,7 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
throw new ApexException("engine service configuration parameters are null");
}
- final GroupValidationResult validation = config.validate();
+ final ValidationResult validation = config.validate();
if (!validation.isValid()) {
LOGGER.warn("Invalid engine service configuration parameters: {}" + validation.getResult());
throw new ApexException("Invalid engine service configuration parameters: " + validation);
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java
index 673d9cab5..0a317d600 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameterHandler.java
@@ -3,6 +3,7 @@
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
+ * 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.
@@ -38,9 +39,9 @@ import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnolo
import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParametersJsonAdapter;
import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters;
import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParametersJsonAdapter;
-import org.onap.policy.common.parameters.GroupValidationResult;
import org.onap.policy.common.parameters.ParameterException;
import org.onap.policy.common.parameters.ParameterService;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.ext.XLogger;
@@ -107,7 +108,7 @@ public class ApexParameterHandler {
}
// Validate the parameters
- final GroupValidationResult validationResult = parameters.validate();
+ final ValidationResult validationResult = parameters.validate();
if (!validationResult.isValid()) {
String returnMessage = "validation error(s) on parameters from \"" + toscaPolicyFilePath + "\"\n";
returnMessage += validationResult.getResult();
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java
index 692d5aee3..1302661b9 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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.
* 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.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -24,20 +25,30 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import lombok.Getter;
+import lombok.Setter;
import org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
-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.ValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Size;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.models.base.Validated;
/**
* The main container parameter class for an Apex service.
- *
+ *
* <p>The following parameters are defined: <ol> <li>engineServiceParameters: The parameters for the Apex engine service
* itself, such as the number of engine threads to run and the deployment port number to use. <li>eventOutputParameters:
* A map of parameters for event outputs that Apex will use to emit events. Apex emits events on all outputs
@@ -48,6 +59,8 @@ import org.onap.policy.common.utils.validation.ParameterValidationUtils;
*/
public class ApexParameters implements ParameterGroup {
// Parameter group name
+ @Getter
+ @Setter
private String name;
// Constants for recurring strings
@@ -58,16 +71,27 @@ public class ApexParameters implements ParameterGroup {
private static final String FOR_PEERED_MODE_STRING = " for peered mode ";
// Properties for the Java JVM
+ @Getter
private String[][] javaProperties = null;
// Parameters for the engine service and the engine threads in the engine service
- private EngineServiceParameters engineServiceParameters;
+ @Getter
+ @Setter
+ private @NotNull @Valid EngineServiceParameters engineServiceParameters;
// Parameters for the event outputs that Apex will use to send events on its outputs
- private Map<String, EventHandlerParameters> eventOutputParameters = new LinkedHashMap<>();
+ @Getter
+ @Setter
+ @Size(min = 1)
+ private Map<@NotNull @NotBlank String, @NotNull @Valid EventHandlerParameters> eventOutputParameters =
+ new LinkedHashMap<>();
// Parameters for the event inputs that Apex will use to receive events on its inputs
- private Map<String, EventHandlerParameters> eventInputParameters = new LinkedHashMap<>();
+ @Getter
+ @Setter
+ @Size(min = 1)
+ private Map<@NotNull @NotBlank String, @NotNull @Valid EventHandlerParameters> eventInputParameters =
+ new LinkedHashMap<>();
/**
* Constructor to create an apex parameters instance and register the instance with the parameter service.
@@ -80,70 +104,6 @@ public class ApexParameters implements ParameterGroup {
}
/**
- * Gets the parameters for the Apex engine service.
- *
- * @return the engine service parameters
- */
- public EngineServiceParameters getEngineServiceParameters() {
- return engineServiceParameters;
- }
-
- /**
- * Sets the engine service parameters.
- *
- * @param engineServiceParameters the engine service parameters
- */
- public void setEngineServiceParameters(final EngineServiceParameters engineServiceParameters) {
- this.engineServiceParameters = engineServiceParameters;
- }
-
- /**
- * Gets the event output parameter map.
- *
- * @return the parameters for all event outputs
- */
- public Map<String, EventHandlerParameters> getEventOutputParameters() {
- return eventOutputParameters;
- }
-
- /**
- * Sets the event output parameters.
- *
- * @param eventOutputParameters the event outputs parameters
- */
- public void setEventOutputParameters(final Map<String, EventHandlerParameters> eventOutputParameters) {
- this.eventOutputParameters = eventOutputParameters;
- }
-
- /**
- * Gets the event input parameter map.
- *
- * @return the parameters for all event inputs
- */
- public Map<String, EventHandlerParameters> getEventInputParameters() {
- return eventInputParameters;
- }
-
- /**
- * Sets the event input parameters.
- *
- * @param eventInputParameters the event input parameters
- */
- public void setEventInputParameters(final Map<String, EventHandlerParameters> eventInputParameters) {
- this.eventInputParameters = eventInputParameters;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(final String name) {
- this.name = name;
- }
-
- /**
* Check if Java properties have been specified.
*
* @return true if Java properties have been specified
@@ -152,38 +112,11 @@ public class ApexParameters implements ParameterGroup {
return javaProperties != null && javaProperties.length > 0;
}
- /**
- * Gets the Java properties that have been specified.
- *
- * @return the Java properties that have been specified
- */
- public String[][] getJavaProperties() {
- return javaProperties;
- }
-
@Override
- public GroupValidationResult validate() {
- GroupValidationResult result = new GroupValidationResult(this);
+ public BeanValidationResult validate() {
+ BeanValidationResult result = new BeanValidator().validateTop(getClass().getSimpleName(), this);
- validateJavaProperties(result);
-
- if (engineServiceParameters == null) {
- result.setResult("engineServiceParameters", ValidationStatus.INVALID,
- "engine service parameters are not specified");
- } else {
- result.setResult("engineServiceParameters", engineServiceParameters.validate());
- }
-
- // Sanity check, we must have an entry in both output and input maps
- if (eventInputParameters.isEmpty()) {
- result.setResult(EVENT_INPUT_PARAMETERS_STRING, ValidationStatus.INVALID,
- "at least one event input must be specified");
- }
-
- if (eventOutputParameters.isEmpty()) {
- result.setResult(EVENT_OUTPUT_PARAMETERS_STRING, ValidationStatus.INVALID,
- "at least one event output must be specified");
- }
+ result.addResult(validateJavaProperties());
// Validate that the values of all parameters are ok
validateEventHandlerMap(EVENT_INPUT_PARAMETERS_STRING, result, eventInputParameters);
@@ -201,56 +134,50 @@ public class ApexParameters implements ParameterGroup {
/**
* This method validates the java properties variable if it is present.
- *
- * @param result the result of the validation
*/
- private void validateJavaProperties(GroupValidationResult result) {
+ private ValidationResult validateJavaProperties() {
if (javaProperties == null) {
- return;
+ return null;
}
- StringBuilder errorMessageBuilder = new StringBuilder();
+ BeanValidationResult result = new BeanValidationResult(JAVA_PROPERTIES, javaProperties);
+ int item = 0;
for (String[] javaProperty : javaProperties) {
+ final String label = "entry " + (item++);
+ final List<String> value = (javaProperty == null ? null : Arrays.asList(javaProperty));
+ BeanValidationResult result2 = new BeanValidationResult(label, value);
+
if (javaProperty == null) {
- errorMessageBuilder.append("java properties array entry is null\n");
+ // note: add to result, not result2
+ result.addResult(label, null, ValidationStatus.INVALID, Validated.IS_NULL);
+
} else if (javaProperty.length != 2) {
- errorMessageBuilder.append("java properties array entries must have one key and one value: "
- + Arrays.deepToString(javaProperty) + "\n");
+ // note: add to result, not result2
+ result.addResult(label, value, ValidationStatus.INVALID, "must have one key and one value");
+
} else if (!ParameterValidationUtils.validateStringParameter(javaProperty[0])) {
- errorMessageBuilder
- .append("java properties key is null or blank: " + Arrays.deepToString(javaProperty) + "\n");
+ result2.addResult("key", javaProperty[0], ValidationStatus.INVALID, Validated.IS_BLANK);
+
} else if (!ParameterValidationUtils.validateStringParameter(javaProperty[1])) {
- errorMessageBuilder
- .append("java properties value is null or blank: " + Arrays.deepToString(javaProperty) + "\n");
+ result2.addResult("value", javaProperty[1], ValidationStatus.INVALID, Validated.IS_BLANK);
}
- }
- if (errorMessageBuilder.length() > 0) {
- result.setResult(JAVA_PROPERTIES, ValidationStatus.INVALID, errorMessageBuilder.toString());
+ result.addResult(result2);
}
+
+ return result;
}
/**
* This method validates the parameters in an event handler map.
- *
+ *
* @param eventHandlerType the type of the event handler to use on error messages
* @param result the result object to use to return validation messages
* @param parsForValidation The event handler parameters to validate (input or output)
*/
- private void validateEventHandlerMap(final String eventHandlerType, final GroupValidationResult result,
+ private void validateEventHandlerMap(final String eventHandlerType, final BeanValidationResult result,
final Map<String, EventHandlerParameters> parsForValidation) {
for (final Entry<String, EventHandlerParameters> parameterEntry : parsForValidation.entrySet()) {
- if (parameterEntry.getKey() == null || parameterEntry.getKey().trim().isEmpty()) {
- result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID,
- "invalid " + eventHandlerType + " name \"" + parameterEntry.getKey() + "\"");
- } else if (parameterEntry.getValue() == null) {
- result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID,
- "invalid/Null event input prameters specified for " + eventHandlerType + " name \""
- + parameterEntry.getKey() + "\" ");
- } else {
- result.setResult(eventHandlerType, parameterEntry.getKey(), parameterEntry.getValue().validate());
- }
-
parameterEntry.getValue().setName(parameterEntry.getKey());
// Validate parameters for peered mode settings
@@ -262,46 +189,46 @@ public class ApexParameters implements ParameterGroup {
/**
* Validate parameter values for event handlers in a peered mode.
- *
+ *
* @param eventHandlerType The event handler type we are checking
* @param result The result object to which to append any error messages
* @param parameterEntry The entry to check the peered mode on
* @param peeredMode The mode to check
*/
- private void validatePeeredModeParameters(final String eventHandlerType, final GroupValidationResult result,
+ private void validatePeeredModeParameters(final String eventHandlerType, final BeanValidationResult result,
final Entry<String, EventHandlerParameters> parameterEntry, final EventHandlerPeeredMode peeredMode) {
final String messagePreamble = "specified peered mode \"" + peeredMode + "\"";
final String peer = parameterEntry.getValue().getPeer(peeredMode);
if (parameterEntry.getValue().isPeeredMode(peeredMode)) {
if (peer == null || peer.trim().isEmpty()) {
- result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID,
+ result.addResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID,
messagePreamble + " mandatory parameter not specified or is null");
}
if (parameterEntry.getValue().getPeerTimeout(peeredMode) < 0) {
- result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID,
+ result.addResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID,
messagePreamble + " timeout value \"" + parameterEntry.getValue().getPeerTimeout(peeredMode)
+ "\" is illegal, specify a non-negative timeout value in milliseconds");
}
} else {
if (peer != null) {
- result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID, messagePreamble
- + " peer is illegal on " + eventHandlerType + " \"" + parameterEntry.getKey() + "\" ");
+ result.addResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID, messagePreamble
+ + " peer is illegal");
}
if (parameterEntry.getValue().getPeerTimeout(peeredMode) != 0) {
- result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID, messagePreamble
- + " timeout is illegal on " + eventHandlerType + " \"" + parameterEntry.getKey() + "\"");
+ result.addResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID, messagePreamble
+ + " timeout is illegal");
}
}
}
/**
* This method validates that the settings are valid for the given peered mode.
- *
+ *
* @param result The result object to which to append any error messages
* @param peeredMode The peered mode to check
*/
- private void validatePeeredMode(final GroupValidationResult result, final EventHandlerPeeredMode peeredMode) {
+ private void validatePeeredMode(final BeanValidationResult result, final EventHandlerPeeredMode peeredMode) {
// Find the input and output event handlers that use this peered mode
final Map<String, EventHandlerParameters> inputParametersUsingMode = new HashMap<>();
final Map<String, EventHandlerParameters> outputParametersUsingMode = new HashMap<>();
@@ -327,13 +254,13 @@ public class ApexParameters implements ParameterGroup {
/**
* This method validates that the settings are valid for the event handlers on one.
- *
+ *
* @param handlerMapVariableName the variable name of the map on which the paired parameters are being checked
* @param result The result object to which to append any error messages
* @param leftModeParameters The mode parameters being checked
* @param rightModeParameters The mode parameters being referenced by the checked parameters
*/
- private void validatePeeredModePeers(final String handlerMapVariableName, final GroupValidationResult result,
+ private void validatePeeredModePeers(final String handlerMapVariableName, final BeanValidationResult result,
final EventHandlerPeeredMode peeredMode, final Map<String, EventHandlerParameters> leftModeParameterMap,
final Map<String, EventHandlerParameters> rightModeParameterMap) {
@@ -351,7 +278,7 @@ public class ApexParameters implements ParameterGroup {
// Check that the peer reference is OK
if (rightModeParameters == null) {
- result.setResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID,
+ result.addResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID,
PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING + peeredMode
+ " does not exist or is not defined with the same peered mode");
continue;
@@ -360,20 +287,20 @@ public class ApexParameters implements ParameterGroup {
// Now check that the right side peer is the left side event handler
final String rightSidePeer = rightModeParameters.getPeer(peeredMode);
if (!rightSidePeer.equals(leftModeParameterEntry.getKey())) {
- result.setResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID,
- PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING + peeredMode
- + ", value \"" + rightSidePeer + "\" on peer \"" + leftSidePeer
- + "\" does not equal event handler \"" + leftModeParameterEntry.getKey() + "\"");
+ result.addResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID,
+ PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + '"'
+ + FOR_PEERED_MODE_STRING + peeredMode + ", value \"" + rightSidePeer
+ + "\" on peer does not equal event handler");
} else {
// Check for duplicates
if (!leftCheckDuplicateSet.add(leftSidePeer)) {
- result.setResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID,
+ result.addResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID,
PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING + peeredMode
+ ", peer value \"" + leftSidePeer + "\" on event handler \""
+ leftModeParameterEntry.getKey() + "\" is used more than once");
}
if (!rightCheckDuplicateSet.add(rightSidePeer)) {
- result.setResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID,
+ result.addResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID,
PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING + peeredMode
+ ", peer value \"" + rightSidePeer + "\" on peer \"" + leftSidePeer
+ "\" on event handler \"" + leftModeParameterEntry.getKey() + "\" is used more than once");
@@ -381,12 +308,12 @@ public class ApexParameters implements ParameterGroup {
}
if (!crossCheckPeeredTimeoutValues(leftModeParameters, rightModeParameters, peeredMode)) {
- result.setResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID,
- PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING + peeredMode
- + " timeout " + leftModeParameters.getPeerTimeout(peeredMode) + " on event handler \""
- + leftModeParameters.getName() + "\" does not equal timeout "
- + rightModeParameters.getPeerTimeout(peeredMode) + " on event handler \""
- + rightModeParameters.getName() + "\"");
+ result.addResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID,
+ PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + '"'
+ + FOR_PEERED_MODE_STRING + peeredMode + " timeout "
+ + leftModeParameters.getPeerTimeout(peeredMode)
+ + " does not equal peer timeout "
+ + rightModeParameters.getPeerTimeout(peeredMode));
}
}
@@ -394,7 +321,7 @@ public class ApexParameters implements ParameterGroup {
/**
* Validate the timeout values on two peers.
- *
+ *
* @param leftModeParameters The parameters of the left hand peer
* @param peeredMode The peered mode being checked
* @return true if the timeout values are cross checked as being OK
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParameters.java
index e688aad17..503d4c5d7 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/CarrierTechnologyParameters.java
@@ -21,10 +21,11 @@
package org.onap.policy.apex.service.parameters.carriertechnology;
-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.ValidationStatus;
+import org.onap.policy.common.parameters.annotations.ClassName;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
/**
* The default carrier technology parameter class that may be specialized by carrier technology plugins that require
@@ -37,15 +38,17 @@ import org.onap.policy.common.parameters.ValidationStatus;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public abstract class CarrierTechnologyParameters implements ParameterGroup {
+@NotNull
+@NotBlank
+public abstract class CarrierTechnologyParameters extends ParameterGroupImpl {
// The carrier technology label
private String label = null;
// Producer and Consumer plugin classes for the event producer and consumer for this carrier
// technology
- private String eventProducerPluginClass = null;
- private String eventConsumerPluginClass = null;
+ private @ClassName String eventProducerPluginClass = null;
+ private @ClassName String eventConsumerPluginClass = null;
/**
* Constructor to create a carrier technology parameters instance with the name of a sub class of this class and
@@ -130,30 +133,6 @@ public abstract class CarrierTechnologyParameters implements ParameterGroup {
+ ", eventConsumerPluginClass=" + eventConsumerPluginClass + "]";
}
- /**
- * {@inheritDoc}.
- */
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = new GroupValidationResult(this);
-
- if (label == null || label.length() == 0) {
- result.setResult("label", ValidationStatus.INVALID, "carrier technology label not specified or is blank");
- }
-
- if (eventProducerPluginClass == null || eventProducerPluginClass.length() == 0) {
- result.setResult("eventProducerPluginClass", ValidationStatus.INVALID,
- "carrier technology eventProducerPluginClass not specified or is blank");
- }
-
- if (eventConsumerPluginClass == null || eventConsumerPluginClass.length() == 0) {
- result.setResult("eventConsumerPluginClass", ValidationStatus.INVALID,
- "carrier technology eventConsumerPluginClass not specified or is blank");
- }
-
- return result;
- }
-
@Override
public String getName() {
return this.getLabel();
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/RestPluginCarrierTechnologyParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/RestPluginCarrierTechnologyParameters.java
index eab936edc..4e086e809 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/RestPluginCarrierTechnologyParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/carriertechnology/RestPluginCarrierTechnologyParameters.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 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.
@@ -23,6 +24,7 @@ package org.onap.policy.apex.service.parameters.carriertechnology;
import java.util.Arrays;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -32,9 +34,12 @@ import javax.ws.rs.core.MultivaluedMap;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.BeanValidationResult;
+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.utils.validation.ParameterValidationUtils;
+import org.onap.policy.models.base.Validated;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -155,42 +160,42 @@ public class RestPluginCarrierTechnologyParameters extends CarrierTechnologyPara
* {@inheritDoc}.
*/
@Override
- public GroupValidationResult validate() {
- GroupValidationResult result = super.validate();
+ public BeanValidationResult validate() {
+ BeanValidationResult result = super.validate();
- validateUrl(result);
- validateHttpHeaders(result);
+ result.addResult(validateUrl());
+ result.addResult(validateHttpHeaders());
+ result.addResult(validateHttpCodeFilter());
- return validateHttpCodeFilter(result);
+ return result;
}
// @formatter:off
/**
* Validate the URL.
*
- * <p>Checks:
- * http://www.blah.com/{par1/somethingelse (Missing end tag) use {[^\\{}]*$
- * http://www.blah.com/{par1/{some}thingelse (Nested tag) use {[^}]*{
- * http://www.blah.com/{par1}/some}thingelse (Missing start tag1) use }[^{}]*.}
- * http://www.blah.com/par1}/somethingelse (Missing start tag2) use }[^{}]*}
- * http://www.blah.com/{}/somethingelse (Empty tag) use {[\s]*}
- * @param result the result of the validation
+ * <p/>Checks:
+ * <br/>http://www.blah.com/{par1/somethingelse (Missing end tag) use {[^\\{}]*$
+ * <br/>http://www.blah.com/{par1/{some}thingelse (Nested tag) use {[^}]*{
+ * <br/>http://www.blah.com/{par1}/some}thingelse (Missing start tag1) use }[^{}]*.}
+ * <br/>http://www.blah.com/par1}/somethingelse (Missing start tag2) use }[^{}]*}
+ * <br/>http://www.blah.com/{}/somethingelse (Empty tag) use {[\s]*}
*/
// @formatter:on
- public GroupValidationResult validateUrl(final GroupValidationResult result) {
+ public ValidationResult validateUrl() {
// The URL may be optional so existence must be checked in the plugin code
- if (getUrl() == null) {
- return result;
+ String url2 = getUrl();
+ if (url2 == null) {
+ return null;
}
- Matcher matcher = patternErrorKey.matcher(getUrl());
+ Matcher matcher = patternErrorKey.matcher(url2);
if (matcher.find()) {
- final String urlInvalidMessage = "invalid URL " + getUrl() + " has been set for event sending on "
- + getLabel();
- result.setResult("url", ValidationStatus.INVALID, urlInvalidMessage);
+ final String urlInvalidMessage = "invalid URL has been set for event sending on " + getLabel();
+ return new ObjectValidationResult("url", url2, ValidationStatus.INVALID, urlInvalidMessage);
}
- return result;
+ return null;
}
/**
@@ -198,24 +203,35 @@ public class RestPluginCarrierTechnologyParameters extends CarrierTechnologyPara
*
* @param result the result of the validation
*/
- private GroupValidationResult validateHttpHeaders(final GroupValidationResult result) {
+ private ValidationResult validateHttpHeaders() {
if (httpHeaders == null) {
- return result;
+ return null;
}
+ BeanValidationResult result = new BeanValidationResult(HTTP_HEADERS, httpHeaders);
+
+ int item = 0;
for (String[] httpHeader : httpHeaders) {
+ final String label = "entry " + (item++);
+ final List<String> value = (httpHeader == null ? null : Arrays.asList(httpHeader));
+ BeanValidationResult result2 = new BeanValidationResult(label, value);
+
if (httpHeader == null) {
- result.setResult(HTTP_HEADERS, ValidationStatus.INVALID, "HTTP header array entry is null");
+ // note: add to result, not result2
+ result.addResult(label, null, ValidationStatus.INVALID, Validated.IS_NULL);
+
} else if (httpHeader.length != 2) {
- result.setResult(HTTP_HEADERS, ValidationStatus.INVALID,
- "HTTP header array entries must have one key and one value: " + Arrays.deepToString(httpHeader));
+ // note: add to result, not result2
+ result.addResult(label, value, ValidationStatus.INVALID, "must have one key and one value");
+
} else if (!ParameterValidationUtils.validateStringParameter(httpHeader[0])) {
- result.setResult(HTTP_HEADERS, ValidationStatus.INVALID,
- "HTTP header key is null or blank: " + Arrays.deepToString(httpHeader));
+ result2.addResult("key", httpHeader[0], ValidationStatus.INVALID, Validated.IS_BLANK);
+
} else if (!ParameterValidationUtils.validateStringParameter(httpHeader[1])) {
- result.setResult(HTTP_HEADERS, ValidationStatus.INVALID,
- "HTTP header value is null or blank: " + Arrays.deepToString(httpHeader));
+ result2.addResult("value", httpHeader[1], ValidationStatus.INVALID, Validated.IS_BLANK);
}
+
+ result.addResult(result2);
}
return result;
@@ -223,28 +239,27 @@ public class RestPluginCarrierTechnologyParameters extends CarrierTechnologyPara
/**
* Validate the HTTP code filter.
- *
- * @param result the result of the validation
*/
- public GroupValidationResult validateHttpCodeFilter(final GroupValidationResult result) {
+ public ValidationResult validateHttpCodeFilter() {
if (httpCodeFilter == null) {
httpCodeFilter = DEFAULT_HTTP_CODE_FILTER;
} else if (StringUtils.isBlank(httpCodeFilter)) {
- result.setResult(HTTP_CODE_FILTER, ValidationStatus.INVALID,
- "HTTP code filter must be specified as a three digit regular expression");
+ return new ObjectValidationResult(HTTP_CODE_FILTER, httpCodeFilter, ValidationStatus.INVALID,
+ "must be a three digit regular expression");
} else {
try {
Pattern.compile(httpCodeFilter);
} catch (PatternSyntaxException pse) {
+ LOGGER.debug("Invalid HTTP code filter", pse);
String message = "Invalid HTTP code filter, the filter must be specified as a three digit "
+ "regular expression: " + pse.getMessage();
- result.setResult(HTTP_CODE_FILTER, ValidationStatus.INVALID, message);
- LOGGER.debug(message, pse);
+ return new ObjectValidationResult(HTTP_CODE_FILTER, httpCodeFilter, ValidationStatus.INVALID,
+ message);
}
}
- return result;
+ return null;
}
/**
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java
index afede627e..d33ae1697 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/engineservice/EngineServiceParameters.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * 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.
@@ -21,16 +22,21 @@
package org.onap.policy.apex.service.parameters.engineservice;
+import javax.validation.Valid;
import lombok.Getter;
import lombok.Setter;
-import org.apache.commons.lang3.StringUtils;
import org.onap.policy.apex.core.engine.EngineParameters;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
import org.onap.policy.apex.service.parameters.ApexParameterConstants;
-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.parameters.annotations.Max;
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Pattern;
// @formatter:off
/**
@@ -58,6 +64,7 @@ import org.onap.policy.common.parameters.ValidationStatus;
// @formatter:on
@Getter
@Setter
+@NotNull
public class EngineServiceParameters implements ParameterGroup {
private static final int MAX_PORT = 65535;
@@ -80,17 +87,25 @@ public class EngineServiceParameters implements ParameterGroup {
// Constants for repeated strings
// Apex engine service parameters
+ @Pattern(regexp = AxKey.NAME_REGEXP)
private String name = DEFAULT_NAME;
+ @Pattern(regexp = AxKey.VERSION_REGEXP)
private String version = DEFAULT_VERSION;
+ @Min(0)
private int id = DEFAULT_ID;
+ @Min(1)
private int instanceCount = DEFAULT_INSTANCE_COUNT;
+ @Min(1)
+ @Max(MAX_PORT)
private int deploymentPort = DEFAULT_DEPLOYMENT_PORT;
+ @NotBlank
private String policyModel = null;
+ @Min(0)
private long periodicEventPeriod = 0;
// @formatter:on
// Apex engine internal parameters
- private EngineParameters engineParameters = new EngineParameters();
+ private @Valid EngineParameters engineParameters = new EngineParameters();
/**
* Constructor to create an apex engine service parameters instance and register the instance with the parameter
@@ -126,63 +141,8 @@ public class EngineServiceParameters implements ParameterGroup {
* {@inheritDoc}.
*/
@Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = new GroupValidationResult(this);
-
- validateStringParameters(result);
-
- validateNumericParameters(result);
-
- if (StringUtils.isBlank(policyModel)) {
- result.setResult("policyModel", ValidationStatus.INVALID, "must be specified");
- }
- result.setResult("engineParameters", engineParameters.validate());
-
- return result;
- }
-
- /**
- * Validate string parameters.
- *
- * @param result the result of string parameter validation
- */
- private void validateStringParameters(final GroupValidationResult result) {
- if (name == null || !name.matches(AxKey.NAME_REGEXP)) {
- result.setResult("name", ValidationStatus.INVALID,
- "name is invalid, it must match regular expression" + AxKey.NAME_REGEXP);
- }
-
- if (version == null || !version.matches(AxKey.VERSION_REGEXP)) {
- result.setResult("version", ValidationStatus.INVALID,
- "version is invalid, it must match regular expression" + AxKey.VERSION_REGEXP);
- }
- }
-
- /**
- * Validate numeric parameters.
- *
- * @param result the result of numeric parameter validation
- */
- private void validateNumericParameters(final GroupValidationResult result) {
- if (id < 0) {
- result.setResult("id", ValidationStatus.INVALID,
- "id not specified or specified value [" + id + "] invalid, must be specified as id >= 0");
- }
-
- if (instanceCount < 1) {
- result.setResult("instanceCount", ValidationStatus.INVALID,
- "instanceCount [" + instanceCount + "] invalid, must be specified as instanceCount >= 1");
- }
-
- if (deploymentPort < 1 || deploymentPort > MAX_PORT) {
- result.setResult("deploymentPort", ValidationStatus.INVALID, "deploymentPort [" + deploymentPort
- + "] invalid, must be specified as 1024 <= port <= 65535");
- }
-
- if (periodicEventPeriod < 0) {
- result.setResult("periodicEventPeriod", ValidationStatus.INVALID, "periodicEventPeriod ["
- + periodicEventPeriod + "] invalid, must be specified in milliseconds as >=0");
- }
+ public BeanValidationResult validate() {
+ return new BeanValidator().validateTop(getClass().getSimpleName(), this);
}
}
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventhandler/EventHandlerParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventhandler/EventHandlerParameters.java
index 72eb58b0f..7fb4584fe 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventhandler/EventHandlerParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventhandler/EventHandlerParameters.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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.
* 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.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -25,18 +26,21 @@ import java.util.regex.PatternSyntaxException;
import org.onap.policy.apex.service.parameters.ApexParameterConstants;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters;
-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.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The parameters for a single event producer, event consumer or synchronous event handler.
- *
+ *
* <p>Event producers, consumers, and synchronous event handlers all use a carrier technology and an event protocol so
* the actual parameters for each one are the same. Therefore, we use the same class for the parameters of each one.
- *
+ *
* <p>The following parameters are defined: <ol> <li>carrierTechnologyParameters: The carrier technology is the type of
* messaging infrastructure used to carry events. Examples are File, Kafka or REST. <li>eventProtocolParameters: The
* format that the events are in when being carried. Examples are JSON, XML, or Java Beans. carrier technology
@@ -56,8 +60,8 @@ public class EventHandlerParameters implements ParameterGroup {
private static final Logger LOGGER = LoggerFactory.getLogger(EventHandlerParameters.class);
private String name = null;
- private CarrierTechnologyParameters carrierTechnologyParameters = null;
- private EventProtocolParameters eventProtocolParameters = null;
+ private @NotNull @Valid CarrierTechnologyParameters carrierTechnologyParameters = null;
+ private @NotNull @Valid EventProtocolParameters eventProtocolParameters = null;
private boolean synchronousMode = false;
private String synchronousPeer = null;
private long synchronousTimeout = 0;
@@ -97,7 +101,7 @@ public class EventHandlerParameters implements ParameterGroup {
/**
* Checks if the name of the event handler is set.
- *
+ *
* @return true if the name is set
*/
public boolean checkSetName() {
@@ -214,7 +218,7 @@ public class EventHandlerParameters implements ParameterGroup {
/**
* Get the timeout value for the event handler in peered mode.
- *
+ *
* @param peeredMode the peered mode to get the timeout for
* @return the timeout value
*/
@@ -231,7 +235,7 @@ public class EventHandlerParameters implements ParameterGroup {
/**
* Set the timeout value for the event handler in peered mode.
- *
+ *
* @param peeredMode the peered mode to set the timeout for
* @param timeout the timeout value
*/
@@ -306,22 +310,8 @@ public class EventHandlerParameters implements ParameterGroup {
* {@inheritDoc}.
*/
@Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = new GroupValidationResult(this);
-
- if (eventProtocolParameters == null) {
- result.setResult("eventProtocolParameters", ValidationStatus.INVALID,
- "event handler eventProtocolParameters not specified or blank");
- } else {
- result.setResult("eventProtocolParameters", eventProtocolParameters.validate());
- }
-
- if (carrierTechnologyParameters == null) {
- result.setResult("carrierTechnologyParameters", ValidationStatus.INVALID,
- "event handler carrierTechnologyParameters not specified or blank");
- } else {
- result.setResult("carrierTechnologyParameters", carrierTechnologyParameters.validate());
- }
+ public BeanValidationResult validate() {
+ final BeanValidationResult result = new BeanValidator().validateTop(getClass().getSimpleName(), this);
if (eventNameFilter != null) {
try {
@@ -329,7 +319,7 @@ public class EventHandlerParameters implements ParameterGroup {
} catch (final PatternSyntaxException pse) {
String message = "event handler eventNameFilter is not a valid regular expression: " + pse.getMessage();
LOGGER.trace(message, pse);
- result.setResult("eventNameFilter", ValidationStatus.INVALID, message);
+ result.addResult("eventNameFilter", eventNameFilter, ValidationStatus.INVALID, message);
}
}
@@ -338,7 +328,7 @@ public class EventHandlerParameters implements ParameterGroup {
/**
* Check if we're using synchronous mode.
- *
+ *
* @return true if if we're using synchronous mode
*/
public boolean isSynchronousMode() {
@@ -347,7 +337,7 @@ public class EventHandlerParameters implements ParameterGroup {
/**
* The synchronous peer for this event handler.
- *
+ *
* @return the synchronous peer for this event handler
*/
public String getSynchronousPeer() {
@@ -356,7 +346,7 @@ public class EventHandlerParameters implements ParameterGroup {
/**
* Get the timeout for synchronous operations.
- *
+ *
* @return the timeout for synchronous operations
*/
public long getSynchronousTimeout() {
@@ -365,7 +355,7 @@ public class EventHandlerParameters implements ParameterGroup {
/**
* Check if this event handler will use requestor mode.
- *
+ *
* @return true if this event handler will use requestor mode
*/
public boolean isRequestorMode() {
@@ -374,7 +364,7 @@ public class EventHandlerParameters implements ParameterGroup {
/**
* The requestor peer for this event handler.
- *
+ *
* @return the requestor peer for this event handler
*/
public String getRequestorPeer() {
@@ -383,7 +373,7 @@ public class EventHandlerParameters implements ParameterGroup {
/**
* Get the requestor timeout.
- *
+ *
* @return the requestorTimeout.
*/
public long getRequestorTimeout() {
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java
index 68d5f8a56..1fd8e7489 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java
@@ -21,10 +21,11 @@
package org.onap.policy.apex.service.parameters.eventprotocol;
-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.ValidationStatus;
+import org.onap.policy.common.parameters.annotations.ClassName;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
/**
* A default event protocol parameter class that may be specialized by event protocol plugins that require plugin
@@ -39,12 +40,14 @@ import org.onap.policy.common.parameters.ValidationStatus;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public abstract class EventProtocolParameters implements ParameterGroup {
+@NotNull
+@NotBlank
+public abstract class EventProtocolParameters extends ParameterGroupImpl {
// The event protocol label
private String label = null;
// Event protocol converter plugin class for this event protocol
- private String eventProtocolPluginClass;
+ private @ClassName String eventProtocolPluginClass;
/**
* Constructor to create an event protocol parameters instance with the name of a sub class of this class and
@@ -99,25 +102,6 @@ public abstract class EventProtocolParameters implements ParameterGroup {
+ "]";
}
- /**
- * {@inheritDoc}.
- */
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = new GroupValidationResult(this);
-
- if (label == null || label.length() == 0) {
- result.setResult("label", ValidationStatus.INVALID, "event protocol label not specified or is blank");
- }
-
- if (eventProtocolPluginClass == null || eventProtocolPluginClass.length() == 0) {
- result.setResult("eventProtocolPluginClass", ValidationStatus.INVALID,
- "event protocol eventProtocolPluginClass not specified or is blank");
- }
-
- return result;
- }
-
@Override
public String getName() {
return this.getLabel();
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextCharDelimitedParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextCharDelimitedParameters.java
index d15d7ed47..3875d4a14 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextCharDelimitedParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextCharDelimitedParameters.java
@@ -21,7 +21,7 @@
package org.onap.policy.apex.service.parameters.eventprotocol;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
/**
@@ -97,16 +97,16 @@ public abstract class EventProtocolTextCharDelimitedParameters extends EventProt
* {@inheritDoc}.
*/
@Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = super.validate();
+ public BeanValidationResult validate() {
+ final BeanValidationResult result = super.validate();
if (startChar == '\0') {
- result.setResult("startChar", ValidationStatus.INVALID,
+ result.addResult("startChar", null, ValidationStatus.INVALID,
"text character delimited start character has not been specified");
}
if (endChar == '\0') {
- result.setResult("endChar", ValidationStatus.INVALID,
+ result.addResult("endChar", null, ValidationStatus.INVALID,
"text character delimited end character has not been specified\n");
}
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java
index ff363aff6..32883301e 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolTextTokenDelimitedParameters.java
@@ -21,8 +21,8 @@
package org.onap.policy.apex.service.parameters.eventprotocol;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
/**
* An event protocol parameter class for token delimited textual event protocols that may be specialized by event
@@ -42,7 +42,7 @@ import org.onap.policy.common.parameters.ValidationStatus;
*/
public abstract class EventProtocolTextTokenDelimitedParameters extends EventProtocolParameters {
// The delimiter token for text blocks
- private String startDelimiterToken = null;
+ private @NotNull @NotBlank String startDelimiterToken = null;
private String endDelimiterToken = null;
private boolean delimiterAtStart = true;
@@ -115,19 +115,4 @@ public abstract class EventProtocolTextTokenDelimitedParameters extends EventPro
return "EventProtocolTextTokenDelimitedParameters [startDelimiterToken=" + startDelimiterToken
+ ", endDelimiterToken=" + endDelimiterToken + ", delimiterAtStart=" + delimiterAtStart + "]";
}
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = super.validate();
-
- if (startDelimiterToken == null || startDelimiterToken.length() == 0) {
- result.setResult("startDelimiterToken", ValidationStatus.INVALID,
- "text start delimiter token not specified or is blank\n");
- }
-
- return result;
- }
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java
index c0da81625..878756383 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 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.
@@ -23,7 +24,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
public class EventRequestorCarrierTechnologyParametersTest {
@@ -37,7 +38,7 @@ public class EventRequestorCarrierTechnologyParametersTest {
@Test
public void validate() {
final EventRequestorCarrierTechnologyParameters parameters = new EventRequestorCarrierTechnologyParameters();
- final GroupValidationResult actual = parameters.validate();
+ final ValidationResult actual = parameters.validate();
assertNotNull(actual);
}
-} \ No newline at end of file
+}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
index b7532aba2..29a3e0f00 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
@@ -3,6 +3,7 @@
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020-2021 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
+ * 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.
@@ -109,7 +110,7 @@ public class ApexMainTest {
apexMain1 = new ApexMain(args);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
- .contains("parameter group has status INVALID"));
+ .contains("item has status INVALID"));
assertNotNull(apexMain1);
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java
index 9557ca8f9..a0169d7e3 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java
@@ -3,6 +3,7 @@
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * 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.
@@ -70,10 +71,11 @@ public class ApexParametersTest {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessageContaining("java properties array entries must have one key and one value")
- .hasMessageContaining("java properties key is null or blank")
- .hasMessageContaining("java properties value is null or blank")
- .hasMessageContaining("java properties array entry is null");
+ .hasMessageContaining("\"javaProperties\"")
+ .hasMessageContaining("entry 0", "entry 1", "entry 2", "entry 3", "entry 4", "entry 5")
+ .hasMessageContaining("must have one key and one value")
+ .hasMessageContaining("\"key\" value \"null\" INVALID, is blank")
+ .hasMessageContaining("\"value\" value \"null\" INVALID, is blank");
}
@Test
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java
index da4ceaa12..e37da3540 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java
@@ -3,6 +3,7 @@
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * 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.
@@ -72,15 +73,11 @@ public class ParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/noParams.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
- + "engine service parameters are not specified\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "at least one event output must be specified\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "at least one event input must be specified\n");
+ .hasMessageContaining("src/test/resources/parameters/noParams.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("\"engineServiceParameters\" value \"null\" INVALID, is null")
+ .hasMessageContaining("\"eventOutputParameters\" value \"{}\" INVALID, minimum number of elements: 1")
+ .hasMessageContaining("\"eventInputParameters\" value \"{}\" INVALID, minimum number of elements: 1");
}
@Test
@@ -89,19 +86,13 @@ public class ParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/blankParams.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group \"ENGINE_SERVICE_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
- + "INVALID, parameter group has status INVALID\n"
- + " field \"id\" type \"int\" value \"-1\" INVALID, "
- + "id not specified or specified value [-1] invalid, must be specified as id >= 0\n"
- + " field \"policyModel\" type \"java.lang.String\" value \"null\" INVALID, must be specified\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "at least one event output must be specified\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "at least one event input must be specified\n");
+ .hasMessageContaining("src/test/resources/parameters/blankParams.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("EngineServiceParameters")
+ .hasMessageContaining("\"id\" value \"-1\" INVALID, is below the minimum")
+ .hasMessageContaining("\"policyModel\" value \"null\" INVALID, is null")
+ .hasMessageContaining("\"eventOutputParameters\" value \"{}\" INVALID, minimum number of elements")
+ .hasMessageContaining("\"eventInputParameters\" value \"{}\" INVALID, minimum number of elements");
}
@Test
@@ -110,38 +101,19 @@ public class ParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/badParams.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group \"hello there\" type "
- + "\"org.onap.policy.apex.service.parameters.engineservice.EngineServiceParameters\" "
- + "INVALID, parameter group has status INVALID\n"
- + " field \"name\" type \"java.lang.String\" value \"hello there\" INVALID, "
- + "name is invalid, it must match regular expression[A-Za-z0-9\\-_\\.]+\n"
- + " field \"id\" type \"int\" value \"-45\" INVALID, id not specified or "
- + "specified value [-45] invalid, must be specified as id >= 0\n"
- + " field \"instanceCount\" type \"int\" value \"-345\" INVALID, "
- + "instanceCount [-345] invalid, must be specified as instanceCount >= 1\n"
- + " field \"deploymentPort\" type \"int\" value \"65536\" INVALID, "
- + "deploymentPort [65536] invalid, must be specified as 1024 <= port <= 65535\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"FirstProducer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
- + "\"org.onap.policy.apex.service.engine.event.impl."
- + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
- + "\"null\" invalid, must be specified as a non-empty string\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"TheFileConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
- + "\"org.onap.policy.apex.service.engine.event.impl."
- + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
- + "\"null\" invalid, must be specified as a non-empty string\n");
+ .hasMessageContaining("src/test/resources/parameters/badParams.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("EngineServiceParameters")
+ .hasMessageContaining("\"name\" value \"hello there\" INVALID, does not match")
+ .hasMessageContaining("\"id\" value \"-45\" INVALID, is below the minimum")
+ .hasMessageContaining("\"instanceCount\" value \"-345\" INVALID, is below the minimum")
+ .hasMessageContaining("\"deploymentPort\" value \"65536\" INVALID, exceeds the maximum")
+ .hasMessageContaining("eventOutputParameters", "FirstProducer", "EventHandlerParameters",
+ "FileCarrierTechnologyParameters")
+ .hasMessageContaining("\"fileName\" value \"null\" INVALID, is blank")
+ .hasMessageContaining("eventInputParameters", "TheFileConsumer1", "EventHandlerParameters",
+ "FileCarrierTechnologyParameters")
+ .hasMessageContaining("\"fileName\" value \"null\" INVALID, is blank");
}
@Test
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java
index 0ef4fa252..0b05eac63 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java
@@ -3,6 +3,7 @@
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * 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.
@@ -75,14 +76,11 @@ public class ProducerConsumerTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/prodConsNoCT.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"aConsumer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
- + "event handler carrierTechnologyParameters not specified or blank\n");
+ .hasMessageContaining("src/test/resources/parameters/prodConsNoCT.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("eventInputParameters", "aConsumer", "EventHandlerParameters",
+ "carrierTechnologyParameters")
+ .hasMessageContaining("is null");
}
@Test
@@ -91,23 +89,14 @@ public class ProducerConsumerTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from \"src/test/resources/parameters/prodConsNoEP.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"aProducer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", parameter group has status INVALID\n" + " parameter group \"UNDEFINED\" INVALID, "
- + "event handler eventProtocolParameters not specified or blank\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"aConsumer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", parameter group has status INVALID\n" + " parameter group \"FILE\" type "
- + "\"org.onap.policy.apex.service.engine.event.impl."
- + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " field \"fileName\" type \"java.lang.String\" value \"null\" INVALID, "
- + "\"null\" invalid, must be specified as a non-empty string\n");
+ .hasMessageContaining("src/test/resources/parameters/prodConsNoEP.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("eventOutputParameters", "aProducer", "EventHandlerParameters",
+ "eventProtocolParameters")
+ .hasMessageContaining("eventInputParameters", "aConsumer", "EventHandlerParameters",
+ "FileCarrierTechnologyParameters", "fileName")
+ .hasMessageContaining("is null")
+ .hasMessageContaining("is blank");
}
@Test
@@ -170,19 +159,12 @@ public class ProducerConsumerTests {
final String[] args = {"-p", "src/test/resources/parameters/prodConsBadFileName.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments)).hasMessage(
- "validation error(s) on parameters from " + "\"src/test/resources/parameters/prodConsBadFileName.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"aProducer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, parameter group has status INVALID\n" + " parameter group \"FILE\" type "
- + "\"org.onap.policy.apex.service.engine.event.impl."
- + "filecarrierplugin.FileCarrierTechnologyParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " field \"fileName\" type "
- + "\"java.lang.String\" value \"null\" INVALID, "
- + "\"null\" invalid, must be specified as a non-empty string\n");
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageContaining("src/test/resources/parameters/prodConsBadFileName.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("eventOutputParameters", "aProducer", "EventHandlerParameters",
+ "FileCarrierTechnologyParameters", "fileName")
+ .hasMessageContaining("is blank");
}
@Test
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java
index 71ff28877..aaa98fd47 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java
@@ -51,16 +51,10 @@ public class SyncParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsNoSyncWithPeer.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", specified peered mode \"SYNCHRONOUS\" "
- + "peer is illegal on eventOutputParameters \"SyncProducer0\" \n");
+ .hasMessageContaining("src/test/resources/parameters/syncBadParamsNoSyncWithPeer.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("\"eventOutputParameters\" value \"SyncProducer0\" INVALID")
+ .hasMessageContaining("peer is illegal");
}
@Test
@@ -69,16 +63,10 @@ public class SyncParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsNotSyncWithPeer.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", specified peered mode \"SYNCHRONOUS\" peer is illegal "
- + "on eventOutputParameters \"SyncProducer0\" \n");
+ .hasMessageContaining("src/test/resources/parameters/syncBadParamsNotSyncWithPeer.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("\"eventOutputParameters\" value \"SyncProducer0\" INVALID")
+ .hasMessageContaining("peer is illegal");
}
@Test
@@ -87,27 +75,13 @@ public class SyncParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsBadPeers.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS does not exist "
- + "or is not defined with the same peered mode\n" + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS does not exist "
- + "or is not defined with the same peered mode\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS does not exist "
- + "or is not defined with the same peered mode\n" + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS does not exist "
- + "or is not defined with the same peered mode\n");
+ .hasMessageContaining("src/test/resources/parameters/syncBadParamsBadPeers.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("\"eventOutputParameters\" value \"SyncProducer0\" INVALID")
+ .hasMessageContaining("\"eventOutputParameters\" value \"SyncProducer1\" INVALID")
+ .hasMessageContaining("\"eventInputParameters\" value \"SyncConsumer0\" INVALID")
+ .hasMessageContaining("\"eventInputParameters\" value \"SyncConsumer1\" INVALID")
+ .hasMessageContaining("does not exist or is not defined");
}
@Test
@@ -116,29 +90,16 @@ public class SyncParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsInvalidTimeout.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " specified peered mode \"SYNCHRONOUS\" timeout value \"-10\" is illegal, "
- + "specify a non-negative timeout value in milliseconds\n"
- + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, specified peered mode \"SYNCHRONOUS\" timeout value \"-3\" is illegal, "
- + "specify a non-negative timeout value in milliseconds\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, specified peered mode \"SYNCHRONOUS\" timeout value \"-1\" is illegal, "
- + "specify a non-negative timeout value in milliseconds\n"
- + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " specified peered mode \"SYNCHRONOUS\" timeout value \"-99999999\" is illegal, "
- + "specify a non-negative timeout value in milliseconds\n");
+ .hasMessageContaining("src/test/resources/parameters/syncBadParamsInvalidTimeout.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("\"eventOutputParameters\" value \"SyncProducer0\" INVALID")
+ .hasMessageContaining("\"eventOutputParameters\" value \"SyncProducer1\" INVALID")
+ .hasMessageContaining("\"eventInputParameters\" value \"SyncConsumer0\" INVALID")
+ .hasMessageContaining("\"eventInputParameters\" value \"SyncConsumer1\" INVALID")
+ .hasMessageContaining("timeout value \"-10\" is illegal")
+ .hasMessageContaining("timeout value \"-3\" is illegal")
+ .hasMessageContaining("timeout value \"-1\" is illegal")
+ .hasMessageContaining("timeout value \"-99999999\" is illegal");
}
@Test
@@ -147,16 +108,10 @@ public class SyncParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsBadTimeout.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" "
- + "INVALID, parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"MyOtherProducer\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, specified peered mode \"SYNCHRONOUS\" "
- + "timeout is illegal on eventOutputParameters \"MyOtherProducer\"\n");
+ .hasMessageContaining("src/test/resources/parameters/syncBadParamsBadTimeout.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("\"eventOutputParameters\" value \"MyOtherProducer\" INVALID, "
+ + "specified peered mode \"SYNCHRONOUS\" timeout is illegal");
}
@Test
@@ -165,29 +120,16 @@ public class SyncParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncBadParamsUnpairedTimeout.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS timeout 10 on event handler "
- + "\"SyncProducer0\" does not equal timeout 1 on event handler \"SyncConsumer0\"\n"
- + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS timeout 3 on event handler "
- + "\"SyncProducer1\" does not equal timeout 99999999 on event handler \"SyncConsumer1\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS timeout 1 on event handler "
- + "\"SyncConsumer0\" does not equal timeout 10 on event handler \"SyncProducer0\"\n"
- + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS timeout 99999999 on event handler "
- + "\"SyncConsumer1\" does not equal timeout 3 on event handler \"SyncProducer1\"\n" + "");
+ .hasMessageContaining("src/test/resources/parameters/syncBadParamsUnpairedTimeout.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("\"eventOutputParameters\" value \"SyncProducer0\" INVALID, peer \"SyncConsumer0\"")
+ .hasMessageContaining("\"eventOutputParameters\" value \"SyncProducer1\" INVALID, peer \"SyncConsumer1\"")
+ .hasMessageContaining("\"eventInputParameters\" value \"SyncConsumer0\" INVALID, peer \"SyncProducer0\"")
+ .hasMessageContaining("\"eventInputParameters\" value \"SyncConsumer1\" INVALID, peer \"SyncProducer1\"")
+ .hasMessageContaining("timeout 10 does not equal peer timeout 1")
+ .hasMessageContaining("timeout 3 does not equal peer timeout 99999999")
+ .hasMessageContaining("timeout 1 does not equal peer timeout 10")
+ .hasMessageContaining("timeout 99999999 does not equal peer timeout 3");
}
@Test
@@ -226,23 +168,12 @@ public class SyncParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncUnusedConsumerPeers.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, peer \"SyncConsumer0 for peered mode SYNCHRONOUS, "
- + "value \"SyncProducer0\" on peer \"SyncConsumer0\" "
- + "does not equal event handler \"SyncProducer1\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" "
- + "INVALID, peer \"SyncProducer1 for peered mode SYNCHRONOUS, "
- + "value \"SyncConsumer0\" on peer \"SyncProducer1\" "
- + "does not equal event handler \"SyncConsumer1\"\n");
+ .hasMessageContaining("src/test/resources/parameters/syncUnusedConsumerPeers.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("\"eventOutputParameters\" value \"SyncProducer1\" INVALID, peer \"SyncConsumer0\"")
+ .hasMessageContaining("\"eventInputParameters\" value \"SyncConsumer1\" INVALID, peer \"SyncProducer1\"")
+ .hasMessageContaining("value \"SyncProducer0\" on peer does not equal event handler")
+ .hasMessageContaining("value \"SyncConsumer0\" on peer does not equal event handler");
}
@Test
@@ -251,29 +182,16 @@ public class SyncParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncMismatchedPeers.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer1 for peered mode SYNCHRONOUS, value \"SyncProducer1\" "
- + "on peer \"SyncConsumer1\" does not equal event handler \"SyncProducer0\"\n"
- + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS, value \"SyncProducer0\" "
- + "on peer \"SyncConsumer0\" does not equal event handler \"SyncProducer1\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer0 for peered mode SYNCHRONOUS, value \"SyncConsumer1\" "
- + "on peer \"SyncProducer0\" does not equal event handler \"SyncConsumer0\"\n"
- + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS, value \"SyncConsumer0\" "
- + "on peer \"SyncProducer1\" does not equal event handler \"SyncConsumer1\"\n");
+ .hasMessageContaining("src/test/resources/parameters/syncMismatchedPeers.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("\"eventOutputParameters\" value \"SyncProducer0\" INVALID, peer \"SyncConsumer1\"")
+ .hasMessageContaining("\"eventOutputParameters\" value \"SyncProducer1\" INVALID, peer \"SyncConsumer0\"")
+ .hasMessageContaining("\"eventInputParameters\" value \"SyncConsumer0\" INVALID, peer \"SyncProducer0\"")
+ .hasMessageContaining("\"eventInputParameters\" value \"SyncConsumer1\" INVALID, peer \"SyncProducer1\"")
+ .hasMessageContaining("value \"SyncProducer1\" on peer does not equal event handler")
+ .hasMessageContaining("value \"SyncProducer0\" on peer does not equal event handler")
+ .hasMessageContaining("value \"SyncConsumer1\" on peer does not equal event handler")
+ .hasMessageContaining("value \"SyncConsumer0\" on peer does not equal event handler");
}
@Test
@@ -282,21 +200,12 @@ public class SyncParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncUnusedProducerPeers.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n"
- + " parameter group map \"eventOutputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncProducer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncConsumer0 for peered mode SYNCHRONOUS, value \"SyncProducer1\" on peer "
- + "\"SyncConsumer0\" does not equal event handler \"SyncProducer0\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, parameter group map has status "
- + "INVALID\n parameter group \"SyncConsumer0\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID"
- + ", peer \"SyncProducer1 for peered mode SYNCHRONOUS, value \"SyncConsumer1\" on peer "
- + "\"SyncProducer1\" does not equal event handler \"SyncConsumer0\"\n");
+ .hasMessageContaining("src/test/resources/parameters/syncUnusedProducerPeers.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("\"eventOutputParameters\" value \"SyncProducer0\" INVALID, peer \"SyncConsumer0\"")
+ .hasMessageContaining("\"eventInputParameters\" value \"SyncConsumer0\" INVALID, peer \"SyncProducer1\"")
+ .hasMessageContaining("value \"SyncProducer1\" on peer does not equal event handler")
+ .hasMessageContaining("value \"SyncConsumer1\" on peer does not equal event handler");
}
@Test
@@ -305,23 +214,12 @@ public class SyncParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("validation error(s) on parameters from "
- + "\"src/test/resources/parameters/syncMismatchedTimeout.json\"\n"
- + "parameter group \"APEX_PARAMETERS\" type "
- + "\"org.onap.policy.apex.service.parameters.ApexParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " parameter group map \"eventOutputParameters\" "
- + "INVALID, parameter group map has status INVALID\n"
- + " parameter group \"SyncProducer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " peer \"SyncConsumer1 for peered mode SYNCHRONOUS timeout 456 "
- + "on event handler \"SyncProducer1\" does not equal timeout 123 "
- + "on event handler \"SyncConsumer1\"\n"
- + " parameter group map \"eventInputParameters\" INVALID, "
- + "parameter group map has status INVALID\n" + " parameter group \"SyncConsumer1\" type "
- + "\"org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters\" INVALID,"
- + " peer \"SyncProducer1 for peered mode SYNCHRONOUS timeout 123 "
- + "on event handler \"SyncConsumer1\" does not equal timeout 456 "
- + "on event handler \"SyncProducer1\"\n");
+ .hasMessageContaining("src/test/resources/parameters/syncMismatchedTimeout.json")
+ .hasMessageContaining("ApexParameters")
+ .hasMessageContaining("\"eventOutputParameters\" value \"SyncProducer1\" INVALID, peer \"SyncConsumer1\"")
+ .hasMessageContaining("\"eventInputParameters\" value \"SyncConsumer1\" INVALID, peer \"SyncProducer1\"")
+ .hasMessageContaining("timeout 123 does not equal peer timeout 456")
+ .hasMessageContaining("timeout 456 does not equal peer timeout 123");
}
@Test
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperDooperCarrierTechnologyParameters.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperDooperCarrierTechnologyParameters.java
index 6805a3d84..d7a502c7f 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperDooperCarrierTechnologyParameters.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/SuperDooperCarrierTechnologyParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * 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,15 +24,22 @@ package org.onap.policy.apex.service.engine.parameters.dummyclasses;
import java.util.Arrays;
import java.util.Collection;
import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.models.base.Validated;
/**
* Apex parameters for SuperDooper as an event carrier technology.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
+@NotNull
+@NotBlank
public class SuperDooperCarrierTechnologyParameters extends CarrierTechnologyParameters {
// Default parameter values
private static final String DEFAULT_ACKS = "all";
@@ -71,16 +79,16 @@ public class SuperDooperCarrierTechnologyParameters extends CarrierTechnologyPar
// superDooper carrier parameters
private String bootstrapServers = DEFAULT_BOOTSTRAP_SERVERS;
private String acks = DEFAULT_ACKS;
- private int retries = DEFAULT_RETRIES;
- private int batchSize = DEFAULT_BATCH_SIZE;
- private int lingerTime = DEFAULT_LINGER_TIME;
- private long bufferMemory = DEFAULT_BUFFER_MEMORY;
+ private @Min(0) int retries = DEFAULT_RETRIES;
+ private @Min(0) int batchSize = DEFAULT_BATCH_SIZE;
+ private @Min(0) int lingerTime = DEFAULT_LINGER_TIME;
+ private @Min(0) long bufferMemory = DEFAULT_BUFFER_MEMORY;
private String groupId = DEFAULT_GROUP_ID;
private boolean enableAutoCommit = DEFAULT_ENABLE_AUTO_COMMIT;
- private int autoCommitTime = DEFAULT_AUTO_COMMIT_TIME;
+ private @Min(0) int autoCommitTime = DEFAULT_AUTO_COMMIT_TIME;
private int sessionTimeout = DEFAULT_SESSION_TIMEOUT;
private String producerTopic = DEFAULT_PRODUCER_TOPIC;
- private int consumerPollTime = DEFAULT_CONSUMER_POLL_TIME;
+ private @Min(0) int consumerPollTime = DEFAULT_CONSUMER_POLL_TIME;
private String[] consumerTopicList = DEFAULT_CONSUMER_TOPIC_LIST;
private String keySerializer = DEFAULT_KEYSERZER;
private String valueSerializer = DEFAULT_VALSERZER;
@@ -459,98 +467,30 @@ public class SuperDooperCarrierTechnologyParameters extends CarrierTechnologyPar
* {@inheritDoc}.
*/
@Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = super.validate();
+ public BeanValidationResult validate() {
+ final BeanValidationResult result = super.validate();
- if (bootstrapServers == null || bootstrapServers.trim().length() == 0) {
- result.setResult("bootstrapServers", ValidationStatus.INVALID,
- "bootstrapServers not specified, must be specified as a string of form host:port");
+ if (consumerTopicList == null) {
+ return result;
}
- if (acks == null || acks.trim().length() == 0) {
- result.setResult("acks", ValidationStatus.INVALID,
- "acks not specified, must be specified as a string with values [0|1|all]");
- }
-
- if (retries < 0) {
- result.setResult("retries", ValidationStatus.INVALID,
- "[" + retries + "] invalid, must be specified as retries >= 0");
- }
-
- if (batchSize < 0) {
- result.setResult("batchSize", ValidationStatus.INVALID,
- "[" + batchSize + "] invalid, must be specified as batchSize >= 0");
- }
-
- if (lingerTime < 0) {
- result.setResult("lingerTime", ValidationStatus.INVALID,
- "[" + lingerTime + "] invalid, must be specified as lingerTime >= 0");
- }
-
- if (bufferMemory < 0) {
- result.setResult("bufferMemory", ValidationStatus.INVALID,
- "[" + bufferMemory + "] invalid, must be specified as bufferMemory >= 0");
- }
-
- if (groupId == null || groupId.trim().length() == 0) {
- result.setResult("groupId", ValidationStatus.INVALID, "not specified, must be specified as a string");
- }
-
- if (autoCommitTime < 0) {
- result.setResult("autoCommitTime", ValidationStatus.INVALID,
- "[" + autoCommitTime + "] invalid, must be specified as autoCommitTime >= 0");
- }
-
- if (sessionTimeout < 0) {
- result.setResult("sessionTimeout", ValidationStatus.INVALID,
- "sessionTimeout [" + sessionTimeout + "] invalid, must be specified as sessionTimeout >= 0");
- }
-
- if (producerTopic == null || producerTopic.trim().length() == 0) {
- result.setResult("producerTopic", ValidationStatus.INVALID,
- "producerTopic not specified, must be specified as a string");
- }
-
- if (consumerPollTime < 0) {
- result.setResult("consumerPollTime", ValidationStatus.INVALID,
- "[" + consumerPollTime + "] invalid, must be specified as consumerPollTime >= 0");
- }
-
- if (consumerTopicList == null || consumerTopicList.length == 0) {
- result.setResult("consumerTopicList", ValidationStatus.INVALID,
+ if (consumerTopicList.length == 0) {
+ result.addResult("consumerTopicList", consumerTopicList, ValidationStatus.INVALID,
"not specified, must be specified as a list of strings");
+ return result;
}
- StringBuilder consumerTopicMessageBuilder = new StringBuilder();
+ BeanValidationResult result2 = new BeanValidationResult("consumerTopicList", consumerTopicList);
+ int item = 0;
for (final String consumerTopic : consumerTopicList) {
- if (consumerTopic == null || consumerTopic.trim().length() == 0) {
- consumerTopicMessageBuilder.append(" invalid consumer topic \"" + consumerTopic
- + "\" specified on consumerTopicList, consumer topics must be specified as strings");
+ if (StringUtils.isBlank(consumerTopic)) {
+ result2.addResult("entry " + item, consumerTopic, ValidationStatus.INVALID, Validated.IS_BLANK);
}
- }
- if (consumerTopicMessageBuilder.length() > 0) {
- result.setResult("consumerTopicList", ValidationStatus.INVALID, consumerTopicMessageBuilder.toString());
+ ++item;
}
- if (keySerializer == null || keySerializer.trim().length() == 0) {
- result.setResult("keySerializer", ValidationStatus.INVALID, "not specified, must be specified as a string");
- }
-
- if (valueSerializer == null || valueSerializer.trim().length() == 0) {
- result.setResult("valueSerializer", ValidationStatus.INVALID,
- "not specified, must be specified as a string");
- }
-
- if (keyDeserializer == null || keyDeserializer.trim().length() == 0) {
- result.setResult("keyDeserializer", ValidationStatus.INVALID,
- "not specified, must be specified as a string");
- }
-
- if (valueDeserializer == null || valueDeserializer.trim().length() == 0) {
- result.setResult("valueDeserializer", ValidationStatus.INVALID,
- "not specified, must be specified as a string");
- }
+ result.addResult(result2);
return result;
}
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterGroup.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterGroup.java
index 17550d003..f752348b4 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterGroup.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterGroup.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.
@@ -26,6 +27,7 @@ import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.parameters.ParameterGroupImpl;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
/**
* Class to hold all parameters needed for apex starter component.
@@ -36,9 +38,9 @@ import org.onap.policy.common.parameters.annotations.NotNull;
@NotBlank
@Getter
public class ApexStarterParameterGroup extends ParameterGroupImpl {
- private RestServerParameters restServerParameters;
- private PdpStatusParameters pdpStatusParameters;
- private TopicParameterGroup topicParameterGroup;
+ private @Valid RestServerParameters restServerParameters;
+ private @Valid PdpStatusParameters pdpStatusParameters;
+ private @Valid TopicParameterGroup topicParameterGroup;
/**
* Create the apex starter parameter group.
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterHandler.java
index 05ae8fd57..691b30d2d 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/parameters/ApexStarterParameterHandler.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 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.
@@ -23,7 +24,7 @@ package org.onap.policy.apex.services.onappf.parameters;
import java.io.File;
import org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments;
import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -70,7 +71,7 @@ public class ApexStarterParameterHandler {
}
// validate the parameters
- final GroupValidationResult validationResult = apexStarterParameterGroup.validate();
+ final ValidationResult validationResult = apexStarterParameterGroup.validate();
if (!validationResult.isValid()) {
String returnMessage =
"validation error(s) on parameters from \"" + arguments.getConfigurationFilePath() + "\"\n";
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java
index 00b6cce74..c44964921 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.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.
@@ -20,6 +21,7 @@
package org.onap.policy.apex.services.onappf.parameters;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -28,7 +30,7 @@ import java.util.Map;
import org.junit.Test;
import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
/**
* Class to perform unit test of {@link ApexStarterParameterGroup}.
@@ -52,7 +54,7 @@ public class TestApexStarterParameterGroup {
final RestServerParameters restServerParameters = apexStarterParameters.getRestServerParameters();
final PdpStatusParameters pdpStatusParameters = apexStarterParameters.getPdpStatusParameters();
final TopicParameterGroup topicParameterGroup = apexStarterParameters.getTopicParameterGroup();
- final GroupValidationResult validationResult = apexStarterParameters.validate();
+ final ValidationResult validationResult = apexStarterParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarterParameters.getName());
assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeIntervalMs());
@@ -73,7 +75,7 @@ public class TestApexStarterParameterGroup {
public void testApexStarterParameterGroup_NullName() {
final ApexStarterParameterGroup apexStarterParameters = commonTestData
.toObject(commonTestData.getApexStarterParameterGroupMap(null), ApexStarterParameterGroup.class);
- final GroupValidationResult validationResult = apexStarterParameters.validate();
+ final ValidationResult validationResult = apexStarterParameters.validate();
assertFalse(validationResult.isValid());
assertEquals(null, apexStarterParameters.getName());
assertTrue(validationResult.getResult().contains("is null"));
@@ -83,11 +85,10 @@ public class TestApexStarterParameterGroup {
public void testApexStarterParameterGroup_EmptyName() {
final ApexStarterParameterGroup apexStarterParameters = commonTestData
.toObject(commonTestData.getApexStarterParameterGroupMap(""), ApexStarterParameterGroup.class);
- final GroupValidationResult validationResult = apexStarterParameters.validate();
+ final ValidationResult validationResult = apexStarterParameters.validate();
+ assertThat(validationResult.getResult()).contains("\"name\" value \"\" INVALID, is blank");
assertFalse(validationResult.isValid());
assertEquals("", apexStarterParameters.getName());
- assertTrue(validationResult.getResult().contains(
- "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
}
@Test
@@ -96,7 +97,7 @@ public class TestApexStarterParameterGroup {
commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
ApexStarterParameterGroup.class);
apexStarterParameters.setName("ApexStarterNewGroup");
- final GroupValidationResult validationResult = apexStarterParameters.validate();
+ final ValidationResult validationResult = apexStarterParameters.validate();
assertTrue(validationResult.isValid());
assertEquals("ApexStarterNewGroup", apexStarterParameters.getName());
}
@@ -108,11 +109,10 @@ public class TestApexStarterParameterGroup {
map.put("pdpStatusParameters", commonTestData.getPdpStatusParametersMap(true));
final ApexStarterParameterGroup apexStarterParameters =
commonTestData.toObject(map, ApexStarterParameterGroup.class);
- final GroupValidationResult validationResult = apexStarterParameters.validate();
+ final ValidationResult validationResult = apexStarterParameters.validate();
+ assertThat(validationResult.getResult())
+ .contains("\"ApexStarterParameterGroup\" INVALID, item has status INVALID");
assertFalse(validationResult.isValid());
- assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup\" INVALID, "
- + "parameter group has status INVALID"));
}
@Test
@@ -123,11 +123,9 @@ public class TestApexStarterParameterGroup {
final ApexStarterParameterGroup apexStarterParameters =
commonTestData.toObject(map, ApexStarterParameterGroup.class);
- final GroupValidationResult validationResult = apexStarterParameters.validate();
+ final ValidationResult validationResult = apexStarterParameters.validate();
+ assertThat(validationResult.getResult()).contains("\"RestServerParameters\" INVALID, item has status INVALID");
assertFalse(validationResult.isValid());
- assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.common.endpoints.parameters.RestServerParameters\" INVALID, "
- + "parameter group has status INVALID"));
}
@@ -139,10 +137,8 @@ public class TestApexStarterParameterGroup {
final ApexStarterParameterGroup apexStarterParameters =
commonTestData.toObject(map, ApexStarterParameterGroup.class);
- final GroupValidationResult validationResult = apexStarterParameters.validate();
+ final ValidationResult validationResult = apexStarterParameters.validate();
+ assertThat(validationResult.getResult()).contains("\"TopicParameterGroup\" INVALID, item has status INVALID");
assertFalse(validationResult.isValid());
- assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.common.endpoints.parameters.TopicParameterGroup\" INVALID, "
- + "parameter group has status INVALID"));
}
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
index dd424c15b..90c2ef743 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2021 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.
@@ -105,8 +106,7 @@ public class TestApexStarterParameterHandler {
arguments.parse(apexStarterConfigParameters);
assertThatThrownBy(() -> new ApexStarterParameterHandler().getParameters(arguments))
- .hasMessageContaining("field \"name\" type \"java.lang.String\" value \" \" INVALID, must be a "
- + "non-blank string");
+ .hasMessageContaining("\"name\" value \" \" INVALID, is blank");
}
@Test
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java
index 95cf35093..765bb70a9 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.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.
@@ -20,6 +21,7 @@
package org.onap.policy.apex.services.onappf.parameters;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -27,7 +29,7 @@ import static org.junit.Assert.assertTrue;
import java.util.Map;
import org.junit.Test;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
/**
* Class to perform unit test of {@link PdpStatusParameters}.
@@ -41,7 +43,7 @@ public class TestPdpStatusParameters {
public void test() throws Exception {
final PdpStatusParameters pdpStatusParameters =
testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
- final GroupValidationResult validationResult = pdpStatusParameters.validate();
+ final ValidationResult validationResult = pdpStatusParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeIntervalMs());
assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
@@ -54,7 +56,7 @@ public class TestPdpStatusParameters {
public void testValidate() throws Exception {
final PdpStatusParameters pdpStatusParameters =
testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
- final GroupValidationResult result = pdpStatusParameters.validate();
+ final ValidationResult result = pdpStatusParameters.validate();
assertNull(result.getResult());
assertTrue(result.isValid());
}
@@ -65,10 +67,9 @@ public class TestPdpStatusParameters {
pdpStatusParametersMap.remove("pdpGroup");
final PdpStatusParameters pdpStatusParameters =
testData.toObject(pdpStatusParametersMap, PdpStatusParameters.class);
- final GroupValidationResult validationResult = pdpStatusParameters.validate();
+ final ValidationResult validationResult = pdpStatusParameters.validate();
assertFalse(validationResult.isValid());
- assertTrue(validationResult.getResult()
- .contains("field \"pdpGroup\" type \"java.lang.String\" value \"null\" INVALID"));
+ assertThat(validationResult.getResult()).contains("\"pdpGroup\" value \"null\" INVALID");
}
@Test
@@ -77,9 +78,8 @@ public class TestPdpStatusParameters {
pdpStatusParametersMap.put("pdpGroup", "");
final PdpStatusParameters pdpStatusParameters =
testData.toObject(pdpStatusParametersMap, PdpStatusParameters.class);
- final GroupValidationResult validationResult = pdpStatusParameters.validate();
+ final ValidationResult validationResult = pdpStatusParameters.validate();
assertFalse(validationResult.isValid());
- assertTrue(validationResult.getResult()
- .contains("field \"pdpGroup\" type \"java.lang.String\" value \"\" INVALID, must be a non-blank string"));
+ assertThat(validationResult.getResult()).contains("\"pdpGroup\" value \"\" INVALID");
}
}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java
index b3f27c52e..8596ceec9 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
+ * 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.
@@ -158,8 +159,9 @@ public class TestExecutionPropertyRest {
final String outString = outContent.toString();
LOGGER.info("testReplaceUrlTag-OUTSTRING=\n" + outString + "\nEnd-TagUrl");
- assertThat(outString).contains("invalid URL http://localhost:32801/TestExecutionRest/apex/event/tagId}"
- + " has been set for event sending on RESTCLIENT");
+ assertThat(outString).contains("item \"url\" "
+ + "value \"http://localhost:32801/TestExecutionRest/apex/event/tagId}\" INVALID, "
+ + "invalid URL has been set for event sending on RESTCLIENT");
}
/**
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java
index 0596a65e8..7f460bb15 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServer.java
@@ -3,6 +3,7 @@
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
+ * 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.
@@ -316,8 +317,7 @@ public class TestRestServer {
final String outString = outContent.toString();
- assertThat(outString)
- .contains("the parameters \"host\", \"port\", and \"standalone\" are illegal on REST Server producer");
+ assertThat(outString).contains("\"host\" value \"null\" INVALID, is blank");
LOGGER.debug("testRestServerProducerStandalone end");
}
@@ -341,7 +341,7 @@ public class TestRestServer {
await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive());
final String outString = outContent.toString();
- assertThat(outString).contains(" host is specified only in standalone mode");
+ assertThat(outString).contains("\"host\"", "should be specified only in standalone mode");
LOGGER.debug("testRestServerProducerHost end");
}
@@ -365,7 +365,7 @@ public class TestRestServer {
await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive());
final String outString = outContent.toString();
- assertThat(outString).contains(" port is specified only in standalone mode");
+ assertThat(outString).contains("\"port\"", "should be specified only in standalone mode");
LOGGER.debug("testRestServerProducerPort end");
}
@@ -387,8 +387,7 @@ public class TestRestServer {
await().atMost(10L, TimeUnit.SECONDS).until(() -> !apexMain.isAlive());
final String outString = outContent.toString();
- assertThat(outString).contains("the parameters \"host\" and \"port\" must be defined for REST Server consumer "
- + "(FirstConsumer) in standalone mode");
+ assertThat(outString).contains("\"host\" value \"null\" INVALID, is blank");
LOGGER.debug("testRestServerConsumerStandaloneNoHost end");
}
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/executionproperties/DummyCarrierTechnologyParameters.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/executionproperties/DummyCarrierTechnologyParameters.java
index fca676b9b..bf645a1ac 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/executionproperties/DummyCarrierTechnologyParameters.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/executionproperties/DummyCarrierTechnologyParameters.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.
@@ -22,10 +23,9 @@ package org.onap.policy.apex.testsuites.integration.uservice.executionproperties
import lombok.Data;
import lombok.EqualsAndHashCode;
-import org.apache.commons.lang3.StringUtils;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
/**
* Dummy carrier technology parameters.
@@ -48,8 +48,8 @@ public class DummyCarrierTechnologyParameters extends CarrierTechnologyParameter
/** The consumer plugin class for the dummy carrier technology. */
public static final String DUMMY_EVENT_CONSUMER_PLUGIN_CLASS = DummyApexEventConsumer.class.getName();
- private String testToRun = null;
- private String propertyFileName = null;
+ private @NotNull @NotBlank String testToRun = null;
+ private @NotNull @NotBlank String propertyFileName = null;
/**
* Constructor to create a dummy carrier technology parameters instance and register the instance with the parameter
@@ -64,24 +64,4 @@ public class DummyCarrierTechnologyParameters extends CarrierTechnologyParameter
this.setEventConsumerPluginClass(DUMMY_EVENT_CONSUMER_PLUGIN_CLASS);
}
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = super.validate();
-
- if (StringUtils.isEmpty(testToRun)) {
- result.setResult("testToRun", ValidationStatus.INVALID,
- "no test has been specified on the dummy carrier technology plugin");
- }
-
- if (StringUtils.isEmpty(propertyFileName)) {
- result.setResult("propertyFileName", ValidationStatus.INVALID,
- "no propertyFileName has been specified on the dummy carrier technology plugin");
- }
-
- return result;
- }
}
diff --git a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParameters.java b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParameters.java
index 619100176..9846c0463 100644
--- a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParameters.java
+++ b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParameters.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * 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.
@@ -20,14 +21,20 @@
package org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
-import org.onap.policy.common.parameters.ValidationStatus;
+import lombok.Getter;
+import lombok.Setter;
+import org.onap.policy.common.parameters.ParameterGroupImpl;
+import org.onap.policy.common.parameters.annotations.Max;
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
/**
* This class defines the parameters for event generation.
*/
-public class EventGeneratorParameters implements ParameterGroup {
+@Getter
+@Setter
+public class EventGeneratorParameters extends ParameterGroupImpl {
// @formatter:off
private static final String DEFAULT_NAME = EventGeneratorParameters.class.getSimpleName();
private static final String DEFAULT_HOST = "localhost";
@@ -36,11 +43,16 @@ public class EventGeneratorParameters implements ParameterGroup {
private static final int DEFAULT_BATCH_SIZE = 1;
private static final long DEFAULT_DELAY_BETWEEN_BATCHES = 2000;
- private String name = DEFAULT_NAME;
+ @NotNull @NotBlank
private String host = DEFAULT_HOST;
+ @Min(1024)
+ @Max(65535)
private int port = DEFAULT_PORT;
+ @Min(0)
private int batchCount = DEFAULT_BATCH_COUNT;
+ @Min(1)
private int batchSize = DEFAULT_BATCH_SIZE;
+ @Min(0)
private long delayBetweenBatches = DEFAULT_DELAY_BETWEEN_BATCHES;
private String outFile = null;
// @formatter:on
@@ -49,108 +61,6 @@ public class EventGeneratorParameters implements ParameterGroup {
* Create default parameters.
*/
public EventGeneratorParameters() {
- // Default parameters are generated
+ super(DEFAULT_NAME);
}
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void setName(String name) {
- this.name = name;
- }
-
- public String getHost() {
- return host;
- }
-
- public void setHost(String host) {
- this.host = host;
- }
-
- public int getPort() {
- return port;
- }
-
- public void setPort(int port) {
- this.port = port;
- }
-
- public int getBatchCount() {
- return batchCount;
- }
-
- public void setBatchCount(int batchCount) {
- this.batchCount = batchCount;
- }
-
- public int getBatchSize() {
- return batchSize;
- }
-
- public void setBatchSize(int batchSize) {
- this.batchSize = batchSize;
- }
-
- public long getDelayBetweenBatches() {
- return delayBetweenBatches;
- }
-
- public void setDelayBetweenBatches(long delayBetweenBatches) {
- this.delayBetweenBatches = delayBetweenBatches;
- }
-
- public String getOutFile() {
- return outFile;
- }
-
- public void setOutFile(String outFile) {
- this.outFile = outFile;
- }
-
- /**
- * {@inheritDoc}.
- */
- @Override
- public GroupValidationResult validate() {
- GroupValidationResult validationResult = new GroupValidationResult(this);
-
- if (isNullOrBlank(name)) {
- validationResult.setResult("name", ValidationStatus.INVALID, "name must be a non-blank string");
- }
-
- if (isNullOrBlank(host)) {
- validationResult.setResult("host", ValidationStatus.INVALID, "host must be a non-blank string");
- }
-
- if (port < 1024 || port > 65535) {
- validationResult.setResult("port", ValidationStatus.INVALID,
- "port must be an integer between 1024 and 65535 inclusive");
- }
-
- if (batchCount < 0) {
- validationResult.setResult("batchCount", ValidationStatus.INVALID,
- "batchCount must be an integer with a value of zero or more, "
- + "zero means generate batches forever");
- }
-
- if (batchSize < 1) {
- validationResult.setResult("batchSize", ValidationStatus.INVALID,
- "batchSize must be an integer greater than zero");
- }
-
- if (delayBetweenBatches < 0) {
- validationResult.setResult("batchSize", ValidationStatus.INVALID,
- "batchSize must be an integer with a value of zero or more");
- }
-
- return validationResult;
- }
-
- private boolean isNullOrBlank(final String stringValue) {
- return stringValue == null || stringValue.trim().length() == 0;
- }
-
}
diff --git a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersHandlerTest.java b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersHandlerTest.java
index 6b15ae454..fd41d81e6 100644
--- a/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersHandlerTest.java
+++ b/testsuites/performance/performance-benchmark-test/src/test/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorParametersHandlerTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 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.
@@ -82,12 +83,8 @@ public class EventGeneratorParametersHandlerTest {
assertThatThrownBy(() -> {
String[] arguments = new String[] { "-c", "src/test/resources/parameters/unit/Default.json", "-bc", "-1" };
handler.parse(arguments);
- }).hasMessage("specified parameters are not valid: parameter group \"EventGeneratorParameters\" "
- + "type \"org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator."
- + "EventGeneratorParameters\" INVALID, parameter group has status INVALID\n"
- + " field \"batchCount\" type \"int\" value \"-1\" INVALID, "
- + "batchCount must be an integer with a value of zero or more, "
- + "zero means generate batches forever\n");
+ }).hasMessageContaining("specified parameters are not valid", "EventGeneratorParameters",
+ "\"batchCount\" value \"-1\" INVALID, is below the minimum");
args = new String[] { "-c", "src/test/resources/parameters/unit/Default.json", "-bs", "12345" };
parameters = handler.parse(args);
assertEquals(12345, parameters.getBatchSize());
@@ -95,11 +92,8 @@ public class EventGeneratorParametersHandlerTest {
assertThatThrownBy(() -> {
String[] arguments = new String[] { "-c", "src/test/resources/parameters/unit/Default.json", "-bs", "0" };
handler.parse(arguments);
- }).hasMessage("specified parameters are not valid: parameter group \"EventGeneratorParameters\" "
- + "type \"org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator."
- + "EventGeneratorParameters\" INVALID, parameter group has status INVALID\n"
- + " field \"batchSize\" type \"int\" value \"0\" INVALID, "
- + "batchSize must be an integer greater than zero\n");
+ }).hasMessageContaining("specified parameters are not valid", "EventGeneratorParameters",
+ "\"batchSize\" value \"0\" INVALID, is below the minimum");
args = new String[] { "-c", "src/test/resources/parameters/unit/Default.json", "-bd", "1000" };
parameters = handler.parse(args);
assertEquals(1000, parameters.getDelayBetweenBatches());
@@ -107,11 +101,8 @@ public class EventGeneratorParametersHandlerTest {
assertThatThrownBy(() -> {
String[] arguments = new String[] { "-c", "src/test/resources/parameters/unit/Default.json", "-bd", "-1" };
handler.parse(arguments);
- }).hasMessage("specified parameters are not valid: parameter group \"EventGeneratorParameters\" "
- + "type \"org.onap.policy.apex.testsuites.performance.benchmark.eventgenerator."
- + "EventGeneratorParameters\" INVALID, parameter group has status INVALID\n"
- + " field \"batchSize\" type \"int\" value \"1\" INVALID, "
- + "batchSize must be an integer with a value of zero or more\n");
+ }).hasMessageContaining("specified parameters are not valid", "EventGeneratorParameters",
+ "\"batchSize\" value \"1\" INVALID, is below the minimum");
args = new String[] { "-c", "src/test/resources/parameters/unit/Default.json", "-o", "Zooby" };
parameters = handler.parse(args);
@@ -181,19 +172,13 @@ public class EventGeneratorParametersHandlerTest {
assertThatThrownBy(() -> {
String[] arguments = new String[] { "-c", "src/test/resources/parameters/unit/NullHost.json" };
handler.parse(arguments);
- }).hasMessage("specified parameters are not valid: parameter group \"ValidPars\" "
- + "type \"org.onap.policy.apex.testsuites.performance."
- + "benchmark.eventgenerator.EventGeneratorParameters\" INVALID, "
- + "parameter group has status INVALID\n" + " field \"host\" type \"java.lang.String\" "
- + "value \"null\" INVALID, host must be a non-blank string\n");
+ }).hasMessageContaining("specified parameters are not valid", "EventGeneratorParameters",
+ "\"host\" value \"null\" INVALID, is null");
assertThatThrownBy(() -> {
String[] arguments = new String[] { "-p", "1023" };
handler.parse(arguments);
- }).hasMessage("specified parameters are not valid: parameter group \""
- + "EventGeneratorParameters\" type \"org.onap.policy.apex.testsuites.performance.benchmark."
- + "eventgenerator.EventGeneratorParameters\" INVALID, parameter group has status INVALID\n"
- + " field \"port\" type \"int\" value \"1023\" INVALID, "
- + "port must be an integer between 1024 and 65535 inclusive\n" + "");
+ }).hasMessageContaining("specified parameters are not valid", "EventGeneratorParameters",
+ "\"port\" value \"1023\" INVALID, is below the minimum");
}
}