Refactor Parameter Group classes 30/143330/3
authordanielhanrahan <daniel.hanrahan@est.tech>
Wed, 18 Feb 2026 13:01:17 +0000 (13:01 +0000)
committerDaniel Hanrahan <daniel.hanrahan@est.tech>
Tue, 24 Feb 2026 11:42:56 +0000 (11:42 +0000)
Remove unneeded ParameterGroup, ParameterGroupImpl classes.
Replace ParameterGroupConstraint with standard annotations.

Issue-ID: POLICY-5509
Change-Id: I329bad819d9930e68ece0ac7a6bb986462f75fe3
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
15 files changed:
participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/ConfigService.java
participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/service/ConfigServiceTest.java
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/parameters/ParticipantIntermediaryParameters.java
policy-common/src/main/java/org/onap/policy/common/parameters/ParameterGroup.java [deleted file]
policy-common/src/main/java/org/onap/policy/common/parameters/ParameterGroupImpl.java [deleted file]
policy-common/src/main/java/org/onap/policy/common/parameters/topic/BusTopicParams.java
policy-common/src/main/java/org/onap/policy/common/parameters/topic/TopicParameterGroup.java
policy-common/src/main/java/org/onap/policy/common/parameters/validation/ParameterGroupConstraint.java [deleted file]
policy-common/src/main/java/org/onap/policy/common/parameters/validation/ParameterGroupValidator.java [deleted file]
policy-common/src/test/java/org/onap/policy/common/message/bus/event/CommonTestData.java
policy-common/src/test/java/org/onap/policy/common/message/bus/event/TopicParameterGroupTest.java
policy-common/src/test/java/org/onap/policy/common/parameters/ParameterGroupTest.java [deleted file]
policy-common/src/test/java/org/onap/policy/common/parameters/validation/ParameterGroupValidatorTest.java [deleted file]
policy-models/src/test/java/org/onap/policy/models/base/validation/annotations/VerifyKeyValidatorTest.java
runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/parameters/AcRuntimeParameterGroup.java

index 902f76c..e7bacb0 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2022,2024 Nordix Foundation.
+ * Copyright (C) 2022-2026 OpenInfra Foundation Europe. 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.
@@ -30,6 +30,7 @@ import org.onap.policy.clamp.acm.element.handler.MessageHandler;
 import org.onap.policy.clamp.acm.element.main.concepts.ElementConfig;
 import org.onap.policy.clamp.acm.element.main.parameters.ElementTopicParameters;
 import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
+import org.onap.policy.common.parameters.BeanValidator;
 import org.onap.policy.common.parameters.topic.TopicParameterGroup;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -62,7 +63,7 @@ public class ConfigService {
         parameters.setTopicSinks(List.of(publisherTopicParameters));
         parameters.setTopicSources(List.of(listenerTopicParameters));
 
-        if (!parameters.isValid()) {
+        if (!BeanValidator.validate(parameters).isValid()) {
             throw new AutomationCompositionRuntimeException(Response.Status.BAD_REQUEST,
                     "Validation failed for topic parameter group. Kafka config not activated");
         }
index b0e823c..984148e 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2022,2024 Nordix Foundation.
+ * Copyright (C) 2022-2026 OpenInfra Foundation Europe. 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 +21,7 @@
 package org.onap.policy.clamp.acm.element.service;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -30,6 +31,7 @@ import org.onap.policy.clamp.acm.element.handler.MessageActivator;
 import org.onap.policy.clamp.acm.element.handler.MessageHandler;
 import org.onap.policy.clamp.acm.element.main.concepts.ElementConfig;
 import org.onap.policy.clamp.acm.element.main.concepts.KafkaConfig;
+import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
 import org.onap.policy.common.parameters.topic.TopicParameterGroup;
 
 class ConfigServiceTest {
@@ -59,5 +61,11 @@ class ConfigServiceTest {
         verify(handler).deactivateElement();
 
         assertThat(configService.getElementConfig()).isNotEqualTo(elementConfig);
+
+        // validation fails due to blank parameter
+        elementConfig.getTopicParameterGroup().setTopicCommInfrastructure("");
+        assertThatThrownBy(() -> configService.activateElement(elementConfig))
+                .isInstanceOf(AutomationCompositionRuntimeException.class)
+                .hasMessageContaining("Validation failed for topic parameter group");
     }
 }
index aea2d7d..fb4d18b 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
+ *  Copyright (C) 2021-2026 OpenInfra Foundation Europe. 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.
@@ -31,7 +31,6 @@ import lombok.Setter;
 import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
 import org.onap.policy.common.parameters.topic.TopicParameterGroup;
 import org.onap.policy.common.parameters.topic.TopicParameters;
-import org.onap.policy.common.parameters.validation.ParameterGroupConstraint;
 
 /**
  * Class to hold all parameters needed for participant component.
@@ -58,7 +57,7 @@ public class ParticipantIntermediaryParameters {
     private int threadPoolSize = 10;
 
     @NotNull
-    @ParameterGroupConstraint
+    @Valid
     private TopicParameterGroup clampAutomationCompositionTopics;
 
     @NotNull
diff --git a/policy-common/src/main/java/org/onap/policy/common/parameters/ParameterGroup.java b/policy-common/src/main/java/org/onap/policy/common/parameters/ParameterGroup.java
deleted file mode 100644 (file)
index c26b7b4..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*-
- * ============LICENSE_START=========================================================
- *  Copyright (C) 2018 Ericsson. All rights reserved.
- *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2024 Nordix Foundation.
- * ==================================================================================
- * 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.common.parameters;
-
-/**
- * This interface acts as a base interface for all parameter groups in the ONAP Policy Framework. All parameter group
- * POJOs are implementations of the parameter group interface and can be used with the {@link ParameterService}.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-public interface ParameterGroup {
-    /**
-     * Get the group name.
-     *
-     * @return the group name
-     */
-    String getName();
-
-    /**
-     * Set the group name.
-     *
-     * @param name the group name
-     */
-    void setName(final String name);
-
-    /**
-     * Validate parameters.
-     *
-     * @return the result of the parameter validation
-     */
-    BeanValidationResult validate();
-
-    /**
-     * Check if the parameters are valid.
-     *
-     * @return true if the parameters are valid
-     */
-    default boolean isValid() {
-        return validate().getStatus().isValid();
-    }
-}
diff --git a/policy-common/src/main/java/org/onap/policy/common/parameters/ParameterGroupImpl.java b/policy-common/src/main/java/org/onap/policy/common/parameters/ParameterGroupImpl.java
deleted file mode 100644 (file)
index 7fc0e5c..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2026 OpenInfra Foundation Europe. 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.parameters;
-
-import jakarta.validation.constraints.NotBlank;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
-/**
- * Implementation of a parameter group.
- */
-@Getter
-@Setter
-@NoArgsConstructor
-@AllArgsConstructor
-public class ParameterGroupImpl implements ParameterGroup {
-    /**
-     * Group name.
-     */
-    @NotBlank
-    private String name;
-
-    @Override
-    public BeanValidationResult validate() {
-        return BeanValidator.validate(this);
-    }
-}
index e83154c..adbe67e 100644 (file)
@@ -4,7 +4,7 @@
  * ================================================================================
  * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
  * Modifications Copyright (C) 2018-2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019, 2023-2024,2026 OpenInfra Foundation Europe. All rights reserved.
+ * Modifications Copyright (C) 2019-2026 OpenInfra Foundation Europe. 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 +23,8 @@
 package org.onap.policy.common.parameters.topic;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotEmpty;
 import java.util.List;
 import java.util.Map;
 import lombok.AccessLevel;
@@ -57,8 +59,10 @@ import org.apache.commons.lang3.StringUtils;
 public class BusTopicParams {
 
     private int port;
+    @NotEmpty
     private List<String> servers;
     private Map<String, String> additionalProps;
+    @NotBlank
     private String topic;
     private String effectiveTopic;
     private String apiKey;
index 5e4f662..c410883 100644 (file)
@@ -25,11 +25,8 @@ import jakarta.validation.Valid;
 import jakarta.validation.constraints.NotNull;
 import java.util.List;
 import lombok.Getter;
+import lombok.NoArgsConstructor;
 import lombok.Setter;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.policy.common.parameters.BeanValidationResult;
-import org.onap.policy.common.parameters.ParameterGroupImpl;
-import org.onap.policy.common.parameters.ValidationStatus;
 
 /**
  * Class to hold all parameters needed for topic properties.
@@ -38,55 +35,10 @@ import org.onap.policy.common.parameters.ValidationStatus;
  */
 @Getter
 @Setter
-public class TopicParameterGroup extends ParameterGroupImpl {
-
+@NoArgsConstructor
+public class TopicParameterGroup {
     @NotNull
     private List<@Valid TopicParameters> topicSources;
     @NotNull
     private List<@Valid TopicParameters> topicSinks;
-
-    public TopicParameterGroup() {
-        super(TopicParameterGroup.class.getSimpleName());
-    }
-
-    /**
-     * {@inheritDoc}.
-     */
-    @Override
-    public BeanValidationResult validate() {
-        BeanValidationResult result = super.validate();
-        if (result.isValid()) {
-            var errorMsg = new StringBuilder();
-            StringBuilder missingSourceParams = checkMissingMandatoryParams(topicSources);
-            if (!missingSourceParams.isEmpty()) {
-                errorMsg.append(missingSourceParams.append("missing in topicSources. "));
-            }
-            StringBuilder missingSinkParams = checkMissingMandatoryParams(topicSinks);
-            if (!missingSinkParams.isEmpty()) {
-                errorMsg.append(missingSinkParams.append("missing in topicSinks."));
-            }
-
-            if (!errorMsg.isEmpty()) {
-                errorMsg.insert(0, "Mandatory parameters are missing. ");
-                result.setResult(ValidationStatus.INVALID, errorMsg.toString());
-            }
-        }
-        return result;
-    }
-
-    private StringBuilder checkMissingMandatoryParams(List<TopicParameters> topicParametersList) {
-        var missingParams = new StringBuilder();
-        for (TopicParameters topicParameters : topicParametersList) {
-            if (StringUtils.isBlank(topicParameters.getTopic())) {
-                missingParams.append("topic, ");
-            }
-            if (StringUtils.isBlank(topicParameters.getTopicCommInfrastructure())) {
-                missingParams.append("topicCommInfrastructure, ");
-            }
-            if (null == topicParameters.getServers() || topicParameters.getServers().isEmpty()) {
-                missingParams.append("servers, ");
-            }
-        }
-        return missingParams;
-    }
 }
diff --git a/policy-common/src/main/java/org/onap/policy/common/parameters/validation/ParameterGroupConstraint.java b/policy-common/src/main/java/org/onap/policy/common/parameters/validation/ParameterGroupConstraint.java
deleted file mode 100644 (file)
index c73d135..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2021, 2023 Nordix Foundation.
- * ================================================================================
- * 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.common.parameters.validation;
-
-import jakarta.validation.Constraint;
-import jakarta.validation.Payload;
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Documented
-@Constraint(validatedBy = ParameterGroupValidator.class)
-@Target({ElementType.FIELD})
-@Retention(RetentionPolicy.RUNTIME)
-public @interface ParameterGroupConstraint {
-
-    /**
-     * Get error Message.
-     *
-     * @return error Message
-     */
-    String message() default "validation error(s) on parameters";
-
-    /**
-     * Get groups.
-     *
-     * @return Class arrays
-     */
-    Class<?>[] groups() default {};
-
-    /**
-     * Get payload.
-     *
-     * @return Class arrays
-     */
-    Class<? extends Payload>[] payload() default {};
-}
diff --git a/policy-common/src/main/java/org/onap/policy/common/parameters/validation/ParameterGroupValidator.java b/policy-common/src/main/java/org/onap/policy/common/parameters/validation/ParameterGroupValidator.java
deleted file mode 100644 (file)
index 024ca13..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2021, 2023 Nordix Foundation.
- * ================================================================================
- * 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.common.parameters.validation;
-
-import jakarta.validation.ConstraintValidator;
-import jakarta.validation.ConstraintValidatorContext;
-import org.onap.policy.common.parameters.BeanValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
-
-public class ParameterGroupValidator implements ConstraintValidator<ParameterGroupConstraint, ParameterGroup> {
-
-    @Override
-    public boolean isValid(ParameterGroup value, ConstraintValidatorContext context) {
-        if (value == null) {
-            return true;
-        }
-        final BeanValidationResult result = value.validate();
-        if (!result.isValid()) {
-            context.buildConstraintViolationWithTemplate(result.getMessage()).addConstraintViolation();
-        }
-        return result.isValid();
-    }
-
-}
index ecd2f20..d2b1a36 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019, 2024 Nordix Foundation.
+ *  Copyright (C) 2019-2026 OpenInfra Foundation Europe. All rights reserved.
  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,7 +27,7 @@ import java.nio.file.Files;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
-import org.onap.policy.common.parameters.ParameterGroup;
+import org.onap.policy.common.parameters.topic.TopicParameterGroup;
 import org.onap.policy.common.parameters.topic.TopicParameters;
 import org.onap.policy.common.utils.coder.Coder;
 import org.onap.policy.common.utils.coder.CoderException;
@@ -69,15 +69,14 @@ public class CommonTestData {
      * Converts the contents of a map to a parameter class.
      *
      * @param source property map
-     * @param clazz  class of object to be created from the map
      * @return a new object represented by the map
      */
-    public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
+    public TopicParameterGroup toObject(final Map<String, Object> source) {
         try {
-            return coder.decode(coder.encode(source), clazz);
+            return coder.decode(coder.encode(source), TopicParameterGroup.class);
 
         } catch (final CoderException e) {
-            throw new RuntimeException("cannot create " + clazz.getName() + " from map", e);
+            throw new RuntimeException("cannot create TopicParameterGroup from map", e);
         }
     }
 
index db28892..e50d78f 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2024 Nordix Foundation.
+ *  Copyright (C) 2019-2026 OpenInfra Foundation Europe. All rights reserved.
  *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +23,6 @@ package org.onap.policy.common.message.bus.event;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.beans.PropertyDescriptor;
@@ -32,6 +31,7 @@ import java.lang.reflect.Modifier;
 import java.util.List;
 import org.apache.commons.lang3.StringUtils;
 import org.junit.jupiter.api.Test;
+import org.onap.policy.common.parameters.BeanValidator;
 import org.onap.policy.common.parameters.ValidationResult;
 import org.onap.policy.common.parameters.topic.BusTopicParams;
 import org.onap.policy.common.parameters.topic.TopicParameterGroup;
@@ -53,9 +53,8 @@ class TopicParameterGroupTest {
     @Test
     void test() throws CoderException {
         final TopicParameterGroup topicParameterGroup =
-                testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class);
-        final ValidationResult validationResult = topicParameterGroup.validate();
-        assertTrue(validationResult.isValid());
+                testData.toObject(testData.getTopicParameterGroupMap(false));
+        assertTrue(BeanValidator.isValid(topicParameterGroup));
         assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks());
         assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources());
 
@@ -70,10 +69,8 @@ class TopicParameterGroupTest {
     @Test
     void testValidate() {
         final TopicParameterGroup topicParameterGroup =
-            testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class);
-        final ValidationResult result = topicParameterGroup.validate();
-        assertNull(result.getResult());
-        assertTrue(result.isValid());
+            testData.toObject(testData.getTopicParameterGroupMap(false));
+        assertTrue(BeanValidator.isValid(topicParameterGroup));
     }
 
     @Test
@@ -81,9 +78,7 @@ class TopicParameterGroupTest {
         String json = testData.getParameterGroupAsString(
             packageDir + "TopicParameters_valid.json");
         TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
-        final ValidationResult result = topicParameterGroup.validate();
-        assertNull(result.getResult());
-        assertTrue(result.isValid());
+        assertTrue(BeanValidator.isValid(topicParameterGroup));
     }
 
     @Test
@@ -91,9 +86,7 @@ class TopicParameterGroupTest {
         String json = testData.getParameterGroupAsString(
             packageDir + "TopicParameters_invalid.json");
         TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
-        final ValidationResult result = topicParameterGroup.validate();
-        assertFalse(result.isValid());
-        assertTrue(result.getResult().contains("INVALID"));
+        assertFalse(BeanValidator.isValid(topicParameterGroup));
     }
 
     @Test
@@ -101,8 +94,8 @@ class TopicParameterGroupTest {
         String json = testData.getParameterGroupAsString(
             packageDir + "TopicParameters_missing_mandatory.json");
         TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
-        final ValidationResult result = topicParameterGroup.validate();
-        assertTrue(result.getResult().contains("Mandatory parameters are missing"));
+        final ValidationResult result = BeanValidator.validate("", topicParameterGroup);
+        assertTrue(result.getResult().contains("\"topicSources[0].servers\" value \"[]\" INVALID, must not be empty"));
         assertFalse(result.isValid());
     }
 
@@ -111,9 +104,7 @@ class TopicParameterGroupTest {
         String json = testData.getParameterGroupAsString(
             packageDir + "TopicParameters_all_params.json");
         TopicParameterGroup topicParameterGroup = coder.decode(json, TopicParameterGroup.class);
-        final ValidationResult result = topicParameterGroup.validate();
-        assertNull(result.getResult());
-        assertTrue(result.isValid());
+        assertTrue(BeanValidator.isValid(topicParameterGroup));
         assertTrue(checkIfAllParamsNotEmpty(topicParameterGroup.getTopicSinks()));
         assertTrue(checkIfAllParamsNotEmpty(topicParameterGroup.getTopicSources()));
     }
diff --git a/policy-common/src/test/java/org/onap/policy/common/parameters/ParameterGroupTest.java b/policy-common/src/test/java/org/onap/policy/common/parameters/ParameterGroupTest.java
deleted file mode 100644 (file)
index d90b13d..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.parameters;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-class ParameterGroupTest {
-
-    private ParameterGroup parameterGroup;
-
-    @BeforeEach
-    void setUp() {
-        parameterGroup = new ParameterGroup() {
-            private String name;
-            private BeanValidationResult validationResult = new BeanValidationResult("testGroup", "testObject");
-
-            @Override
-            public String getName() {
-                return name;
-            }
-
-            @Override
-            public void setName(final String name) {
-                this.name = name;
-            }
-
-            @Override
-            public BeanValidationResult validate() {
-                return validationResult;
-            }
-        };
-    }
-
-    @Test
-    void testGetName() {
-        String testName = "TestGroupName";
-        parameterGroup.setName(testName);
-        assertEquals(testName, parameterGroup.getName(), "The group name should match the one set");
-    }
-
-    @Test
-    void testSetName() {
-        String testName = "AnotherGroupName";
-        parameterGroup.setName(testName);
-        assertEquals(testName, parameterGroup.getName(), "The group name should match the one set");
-    }
-
-    @Test
-    void testValidate() {
-        BeanValidationResult result = parameterGroup.validate();
-        assertNotNull(result, "The validation result should not be null");
-        assertEquals("testGroup", result.getName(), "The validation result should have the correct group name");
-    }
-
-    @Test
-    void testIsValid() {
-        BeanValidationResult mockValidationResult = mock(BeanValidationResult.class);
-        ValidationStatus mockStatus = mock(ValidationStatus.class);
-
-        when(mockStatus.isValid()).thenReturn(true);
-        when(mockValidationResult.getStatus()).thenReturn(mockStatus);
-
-        ParameterGroup mockedParameterGroup = spy(parameterGroup);
-        doReturn(mockValidationResult).when(mockedParameterGroup).validate();
-
-        assertTrue(mockedParameterGroup.isValid(), "The parameters should be valid");
-    }
-}
diff --git a/policy-common/src/test/java/org/onap/policy/common/parameters/validation/ParameterGroupValidatorTest.java b/policy-common/src/test/java/org/onap/policy/common/parameters/validation/ParameterGroupValidatorTest.java
deleted file mode 100644 (file)
index 0c7f29b..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.common.parameters.validation;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.anyString;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import jakarta.validation.ConstraintValidatorContext;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.InOrder;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.onap.policy.common.parameters.BeanValidationResult;
-import org.onap.policy.common.parameters.ParameterGroup;
-
-class ParameterGroupValidatorTest {
-
-    private ParameterGroupValidator validator;
-
-    @Mock
-    private ParameterGroup mockParameterGroup;
-
-    @Mock
-    private BeanValidationResult mockBeanValidationResult;
-
-    @Mock
-    private ConstraintValidatorContext mockContext;
-
-    @Mock
-    private ConstraintValidatorContext.ConstraintViolationBuilder mockViolationBuilder;
-
-    @BeforeEach
-    void setUp() {
-        MockitoAnnotations.openMocks(this);
-        validator = new ParameterGroupValidator();
-    }
-
-    @Test
-    void testIsValid_NullValue() {
-        boolean result = validator.isValid(null, mockContext);
-        assertTrue(result, "Expected isValid to return true when value is null");
-    }
-
-    @Test
-    void testIsValid_ValidParameterGroup() {
-        when(mockParameterGroup.validate()).thenReturn(mockBeanValidationResult);
-        when(mockBeanValidationResult.isValid()).thenReturn(true);
-
-        boolean result = validator.isValid(mockParameterGroup, mockContext);
-        assertTrue(result, "Expected isValid to return true when ParameterGroup is valid");
-
-        verify(mockContext, never()).buildConstraintViolationWithTemplate(anyString());
-    }
-
-    @Test
-    void testIsValid_InvalidParameterGroup() {
-        when(mockParameterGroup.validate()).thenReturn(mockBeanValidationResult);
-        when(mockBeanValidationResult.isValid()).thenReturn(false);
-        when(mockBeanValidationResult.getMessage()).thenReturn("Invalid parameters");
-        when(mockContext.buildConstraintViolationWithTemplate(anyString())).thenReturn(mockViolationBuilder);
-
-        boolean result = validator.isValid(mockParameterGroup, mockContext);
-        assertFalse(result, "Expected isValid to return false when ParameterGroup is invalid");
-
-        InOrder inOrder = inOrder(mockContext, mockViolationBuilder);
-        inOrder.verify(mockContext).buildConstraintViolationWithTemplate("Invalid parameters");
-        inOrder.verify(mockViolationBuilder).addConstraintViolation();
-    }
-}
index 8866865..2db9b58 100644 (file)
@@ -40,10 +40,10 @@ class VerifyKeyValidatorTest {
     void testStandardAnnotation() {
         StdAnnotation data = new StdAnnotation();
         data.strValue = STRING_VALUE;
-        assertThat(BeanValidator.validate("", data).getResult()).isNull();
+        assertThat(BeanValidator.validate(data).getResult()).isNull();
 
         data.strValue = null;
-        assertThat(BeanValidator.validate("", data).getResult()).contains("strValue", "null");
+        assertThat(BeanValidator.validate(data).getResult()).contains("strValue", "null");
     }
 
     @Test
@@ -52,7 +52,7 @@ class VerifyKeyValidatorTest {
 
         // null key - Jakarta validation will include all constraint violations
         data.key = new PfConceptKey();
-        assertThat(BeanValidator.validate("", data).getResult())
+        assertThat(BeanValidator.validate(data).getResult())
             .contains(KEY_FIELD, IS_A_NULL_KEY);
 
         // invalid version - should invoke cascade validation
@@ -71,11 +71,11 @@ class VerifyKeyValidatorTest {
 
         // null name
         data.key = new PfConceptKey(PfKey.NULL_KEY_NAME, "2.3.4");
-        assertThat(BeanValidator.validate("", data).getResult()).contains(KEY_FIELD, "name", IS_NULL);
+        assertThat(BeanValidator.validate(data).getResult()).contains(KEY_FIELD, "name", IS_NULL);
 
         // null version
         data.key = new PfConceptKey(STRING_VALUE, PfKey.NULL_KEY_VERSION);
-        assertThat(BeanValidator.validate("", data).getResult()).contains(KEY_FIELD, "version", IS_NULL);
+        assertThat(BeanValidator.validate(data).getResult()).contains(KEY_FIELD, "version", IS_NULL);
 
         // null name, invalid version - should get two messages
         // Create object with invalid version using reflection to bypass setter validation
@@ -97,14 +97,14 @@ class VerifyKeyValidatorTest {
         data.key = new PfConceptKey(); // totally invalid key
 
         // should be ok, since no validations are performed
-        assertThat(BeanValidator.validate("", data).getResult()).isNull();
+        assertThat(BeanValidator.validate(data).getResult()).isNull();
     }
 
     @Test
     void testVerifyKeyOnGetters() {
         GetterKeyAnnot data = new GetterKeyAnnot();
 
-        var result = BeanValidator.validate("", data);
+        var result = BeanValidator.validate(data);
         assertThat(result.getResult())
                 .contains("nullKey", IS_A_NULL_KEY)
                 .contains("nullVersionKey", "version", IS_NULL)
index 67befe3..f1633c2 100644 (file)
@@ -25,7 +25,6 @@ import jakarta.validation.constraints.NotNull;
 import lombok.Getter;
 import lombok.Setter;
 import org.onap.policy.common.parameters.topic.TopicParameterGroup;
-import org.onap.policy.common.parameters.validation.ParameterGroupConstraint;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.validation.annotation.Validated;
 
@@ -43,8 +42,8 @@ public class AcRuntimeParameterGroup {
     @NotNull
     private ParticipantParameters participantParameters;
 
+    @Valid
     @NotNull
-    @ParameterGroupConstraint
     private TopicParameterGroup topicParameterGroup;
 
     @Valid