diff options
author | Jim Hahn <jrh3@att.com> | 2021-04-28 15:45:22 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-05-03 15:44:08 -0400 |
commit | e168ce2fad71650ad730519c772a9b093c0a8f43 (patch) | |
tree | 8d97f8823eb4f97916b2c19909c6b13e6a008e4a /plugins | |
parent | cb09008c4d252dbc9a62f3a1d0b463a74380aa77 (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>
Diffstat (limited to 'plugins')
11 files changed, 117 insertions, 134 deletions
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. |