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>
/*-
* ============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.
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;
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");
}
/*-
* ============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.
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;
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 {
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");
}
}
/*-
* ============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.
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.
private int threadPoolSize = 10;
@NotNull
- @ParameterGroupConstraint
+ @Valid
private TopicParameterGroup clampAutomationCompositionTopics;
@NotNull
+++ /dev/null
-/*-
- * ============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();
- }
-}
+++ /dev/null
-/*
- * ============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);
- }
-}
* ================================================================================
* 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.
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;
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;
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.
*/
@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;
- }
}
+++ /dev/null
-/*-
- * ============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 {};
-}
+++ /dev/null
-/*-
- * ============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();
- }
-
-}
/*-
* ============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");
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;
* 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);
}
}
/*-
* ============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");
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;
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;
@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());
@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
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
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
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());
}
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()));
}
+++ /dev/null
-/*-
- * ============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");
- }
-}
+++ /dev/null
-/*-
- * ============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();
- }
-}
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
// 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
// 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
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)
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;
@NotNull
private ParticipantParameters participantParameters;
+ @Valid
@NotNull
- @ParameterGroupConstraint
private TopicParameterGroup topicParameterGroup;
@Valid