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: I9597dc84e8a81ac5b8954bb2ce4ad0d7e2a3a4a7
Signed-off-by: Jim Hahn <jrh3@att.com>
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
* ================================================================================
* 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.common.parameters.ParameterGroupImpl;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
/**
@NotBlank
@Getter
public class PapParameterGroup extends ParameterGroupImpl {
+ @Valid
private RestServerParameters restServerParameters;
+ @Valid
private PdpParameters pdpParameters;
+ @Valid
private PolicyModelsProviderParameters databaseProviderParameters;
+ @Valid
private TopicParameterGroup topicParameterGroup;
// API, Distribution Health Check restClient parameters.
- private List<BusTopicParams> healthCheckRestClientParameters;
+ private List<@NotNull @Valid BusTopicParams> healthCheckRestClientParameters;
/**
* Create the pap parameter group.
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
* ================================================================================
* 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.pap.main.parameters;
import java.io.File;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
}
// validate the parameters
- final GroupValidationResult validationResult = papParameterGroup.validate();
+ final ValidationResult validationResult = papParameterGroup.validate();
if (!validationResult.isValid()) {
String returnMessage =
"validation error(s) on parameters from \"" + arguments.getConfigurationFilePath() + "\"\n";
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-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.
import org.onap.policy.common.parameters.annotations.Min;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
/**
* Parameters for communicating with PDPs.
@Min(1)
private long maxMessageAgeMs = DEFAULT_MAX_AGE_MS;
+ @Valid
private PdpUpdateParameters updateParameters;
+ @Valid
private PdpStateChangeParameters stateChangeParameters;
import java.util.stream.Collectors;
import javax.ws.rs.core.Response.Status;
import org.onap.policy.common.parameters.BeanValidationResult;
-import org.onap.policy.common.parameters.ObjectValidationResult;
import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.common.utils.services.Registry;
break;
default:
- result.addResult(new ObjectValidationResult("pdpGroupState", group.getPdpGroupState(),
- ValidationStatus.INVALID, "must be null, ACTIVE, or PASSIVE"));
+ result.addResult("pdpGroupState", group.getPdpGroupState(),
+ ValidationStatus.INVALID, "must be null, ACTIVE, or PASSIVE");
break;
}
}
BeanValidationResult result = new BeanValidationResult(group.getName(), group);
if (!Objects.equals(dbgroup.getProperties(), group.getProperties())) {
- result.addResult(
- new ObjectValidationResult("properties", "", ValidationStatus.INVALID, "cannot change properties"));
+ result.addResult("properties", "", ValidationStatus.INVALID, "cannot change properties");
}
boolean updated = updateField(dbgroup.getDescription(), group.getDescription(), dbgroup::setDescription);
BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp);
if (!Objects.equals(dbsub.getProperties(), subgrp.getProperties())) {
- result.addResult(
- new ObjectValidationResult("properties", "", ValidationStatus.INVALID, "cannot change properties"));
+ result.addResult("properties", "", ValidationStatus.INVALID, "cannot change properties");
}
container.addResult(result);
BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp);
for (ToscaConceptIdentifier type : subgrp.getSupportedPolicyTypes()) {
if (!type.getName().endsWith(".*") && data.getPolicyType(type) == null) {
- result.addResult(
- new ObjectValidationResult("policy type", type, ValidationStatus.INVALID, "unknown policy type"));
+ result.addResult("policy type", type, ValidationStatus.INVALID, "unknown policy type");
}
}
import lombok.Getter;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.BeanValidator;
-import org.onap.policy.common.parameters.ObjectValidationResult;
import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.common.parameters.annotations.NotNull;
PdpGroup dbgroup = data.getGroup(group.getName());
if (dbgroup == null) {
- result.addResult(new ObjectValidationResult(group.getName(), group,
- ValidationStatus.INVALID, "unknown group"));
+ result.addResult(group.getName(), group, ValidationStatus.INVALID, "unknown group");
} else {
result.addResult(updateGroup(data, dbgroup, group));
BeanValidationResult subResult = new BeanValidationResult(subgrp.getPdpType(), subgrp);
if (dbsub == null) {
- subResult.addResult(new ObjectValidationResult(subgrp.getPdpType(), subgrp,
- ValidationStatus.INVALID, "unknown subgroup"));
+ subResult.addResult(subgrp.getPdpType(), subgrp, ValidationStatus.INVALID, "unknown subgroup");
} else {
updated = updateSubGroup(data, dbgroup, dbsub, subgrp, subResult) || updated;
ToscaPolicy policy = data.getPolicy(new ToscaConceptIdentifierOptVersion(ident));
if (policy == null) {
- result.addResult(new ObjectValidationResult(POLICY_RESULT_NAME, ident, ValidationStatus.INVALID,
- "unknown policy"));
+ result.addResult(POLICY_RESULT_NAME, ident, ValidationStatus.INVALID, "unknown policy");
} else if (!isPolicySupported(dbsub.getSupportedPolicyTypes(), policy.getTypeIdentifier())) {
- result.addResult(new ObjectValidationResult(POLICY_RESULT_NAME, ident, ValidationStatus.INVALID,
- "not a supported policy for the subgroup"));
+ result.addResult(POLICY_RESULT_NAME, ident, ValidationStatus.INVALID,
+ "not a supported policy for the subgroup");
} else {
// replace version with the fully qualified version from the policy
return;
}
- result.addResult(new ObjectValidationResult(POLICY_RESULT_NAME, ident, ValidationStatus.INVALID,
- "different version already deployed: " + dbvers));
+ result.addResult(POLICY_RESULT_NAME, ident, ValidationStatus.INVALID,
+ "different version already deployed: " + dbvers);
}
/**
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
* ================================================================================
* 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.pap.main.parameters;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(1);
final RestServerParameters restServerParameters = papParameters.getRestServerParameters();
final TopicParameterGroup topicParameterGroup = papParameters.getTopicParameterGroup();
- final GroupValidationResult validationResult = papParameters.validate();
+ final ValidationResult validationResult = papParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(CommonTestData.PAP_GROUP_NAME, papParameters.getName());
assertEquals(restServerParameters.getHost(), papParameters.getRestServerParameters().getHost());
public void testPapParameterGroup_NullName() throws Exception {
String json = commonTestData.getPapParameterGroupAsString(1).replace("\"PapGroup\"", "null");
final PapParameterGroup papParameters = coder.decode(json, PapParameterGroup.class);
- final GroupValidationResult validationResult = papParameters.validate();
+ final ValidationResult validationResult = papParameters.validate();
assertFalse(validationResult.isValid());
assertEquals(null, papParameters.getName());
- assertTrue(validationResult.getResult().contains("is null"));
+ assertThat(validationResult.getResult()).contains("is null");
}
@Test
public void testPapParameterGroup_EmptyName() throws Exception {
String json = commonTestData.getPapParameterGroupAsString(1).replace(CommonTestData.PAP_GROUP_NAME, "");
final PapParameterGroup papParameters = coder.decode(json, PapParameterGroup.class);
- final GroupValidationResult validationResult = papParameters.validate();
+ final ValidationResult validationResult = papParameters.validate();
assertFalse(validationResult.isValid());
assertEquals("", papParameters.getName());
- assertTrue(validationResult.getResult().contains(
- "field \"name\" type \"java.lang.String\" value \"\" INVALID, " + "must be a non-blank string"));
+ assertThat(validationResult.getResult()).contains("\"name\" value \"\" INVALID, " + "is blank");
}
@Test
public void testPapParameterGroup_SetName() {
final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(1);
papParameters.setName("PapNewGroup");
- final GroupValidationResult validationResult = papParameters.validate();
+ final ValidationResult validationResult = papParameters.validate();
assertTrue(validationResult.isValid());
assertEquals("PapNewGroup", papParameters.getName());
}
String json = commonTestData.getPapParameterGroupAsString(1);
json = commonTestData.nullifyField(json, "restServerParameters");
final PapParameterGroup papParameters = commonTestData.getPapParameterGroup(0);
- final GroupValidationResult validationResult = papParameters.validate();
+ final ValidationResult validationResult = papParameters.validate();
assertFalse(validationResult.isValid());
- assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.common.endpoints.parameters.RestServerParameters\" INVALID, "
- + "parameter group has status INVALID"));
+ assertThat(validationResult.getResult())
+ .contains("\"RestServerParameters\" INVALID, item has status INVALID");
}
}
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
* Modifications Copyright (C) 2020-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
arguments.parse(papConfigParameters);
assertThatThrownBy(() -> new PapParameterHandler().getParameters(arguments))
- .hasMessageContaining("field \"name\" type \"java.lang.String\" value \" \" "
- + "INVALID, must be a non-blank string");
+ .hasMessageContaining("\"name\" value \" \" INVALID, is blank");
}
@Test
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-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.
package org.onap.policy.pap.main.parameters;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
// valid
String json2 = json;
- GroupValidationResult result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate();
+ ValidationResult result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate();
assertNull(result.getResult());
assertTrue(result.isValid());
json2 = json.replaceFirst(": 6", ": 0");
result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate();
assertFalse(result.isValid());
- assertTrue(result.getResult().contains(
- "field 'heartBeatMs' type 'long' value '0' INVALID, must be >= 1".replace('\'', '"')));
+ assertThat(result.getResult()).contains(
+ "'heartBeatMs' value '0' INVALID, is below the minimum value: 1".replace('\'', '"'));
// invalid max message age
json2 = json.replaceFirst(": 20000", ": 0");
result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate();
assertFalse(result.isValid());
- assertTrue(result.getResult().contains(
- "field 'maxMessageAgeMs' type 'long' value '0' INVALID, must be >= 1".replace('\'', '"')));
+ assertThat(result.getResult()).contains(
+ "'maxMessageAgeMs' value '0' INVALID, is below the minimum value: 1".replace('\'', '"'));
// no update params
json2 = testData.nullifyField(json, "updateParameters");
result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate();
assertFalse(result.isValid());
- assertTrue(result.getResult().contains("field 'updateParameters'".replace('\'', '"')));
- assertTrue(result.getResult().contains("is null"));
+ assertThat(result.getResult()).contains("\"updateParameters\"", "is null");
// invalid update params
json2 = json.replaceFirst(": 2", ": -2");
result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate();
assertFalse(result.isValid());
- assertTrue(result.getResult().contains("parameter group 'PdpUpdateParameters'".replace('\'', '"')));
- assertTrue(result.getResult().contains(
- "field 'maxWaitMs' type 'long' value '-2' INVALID, must be >= 0".replace('\'', '"')));
+ assertThat(result.getResult()).contains("\"PdpUpdateParameters\"",
+ "'maxWaitMs' value '-2' INVALID, is below the minimum value: 0".replace('\'', '"'));
// no state-change params
json2 = testData.nullifyField(json, "stateChangeParameters");
json2 = json.replaceFirst(": 5", ": -5");
result = coder.decode(json2, PapParameterGroup.class).getPdpParameters().validate();
assertFalse(result.isValid());
- assertTrue(result.getResult().contains("parameter group 'PdpStateChangeParameters'".replace('\'', '"')));
- assertTrue(result.getResult().contains(
- "field 'maxWaitMs' type 'long' value '-5' INVALID, must be >= 0".replace('\'', '"')));
+ assertThat(result.getResult()).contains("\"PdpStateChangeParameters\"",
+ "'maxWaitMs' value '-5' INVALID, is below the minimum value: 0".replace('\'', '"'));
}
}
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 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.
package org.onap.policy.pap.main.parameters;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
public void testValidate() throws Exception {
// valid, zeroes
PdpRequestParameters params = makeParams(0, 0);
- GroupValidationResult result = params.validate();
+ ValidationResult result = params.validate();
assertNull(result.getResult());
assertTrue(result.isValid());
params = makeParams(-1, 120);
result = params.validate();
assertFalse(result.isValid());
- assertTrue(result.getResult().contains(
- "field 'maxRetryCount' type 'int' value '-1' INVALID, must be >= 0".replace('\'', '"')));
+ assertThat(result.getResult()).contains(
+ "'maxRetryCount' value '-1' INVALID, is below the minimum value: 0".replace('\'', '"'));
// invalid wait time
params = makeParams(130, -1);
result = params.validate();
assertFalse(result.isValid());
- assertTrue(result.getResult()
- .contains("field 'maxWaitMs' type 'long' value '-1' INVALID, must be >= 0".replace('\'', '"')));
+ assertThat(result.getResult()).contains(
+ "'maxWaitMs' value '-1' INVALID, is below the minimum value: 0".replace('\'', '"'));
}
private PdpRequestParameters makeParams(int maxRetry, long maxWait) throws Exception {
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 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.
import static org.junit.Assert.assertTrue;
import org.junit.Test;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
public void testValidate() throws Exception {
// valid, zeroes
PdpStateChangeParameters params = makeParams(10, 20);
- GroupValidationResult result = params.validate();
+ ValidationResult result = params.validate();
assertNull(result.getResult());
assertTrue(result.isValid());
}
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 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.
import static org.junit.Assert.assertTrue;
import org.junit.Test;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
public void testValidate() throws Exception {
// valid, zeroes
PdpUpdateParameters params = makeParams(10, 20);
- GroupValidationResult result = params.validate();
+ ValidationResult result = params.validate();
assertNull(result.getResult());
assertTrue(result.isValid());
}