put identifier in validation error in quotes

This commit is contained in:
Michael Hoennig 2024-06-14 07:02:17 +02:00
parent 5f2117b5b5
commit 6c30109bad
16 changed files with 46 additions and 45 deletions

View File

@ -56,12 +56,12 @@ public class HsBookingItemEntityValidator extends HsEntityValidator<HsBookingIte
final var maxValue = getNonNullIntegerValue(propDef, bookingItem.getResources());
if (propDef.thresholdPercentage() != null ) {
return totalValue > (maxValue * propDef.thresholdPercentage() / 100)
? "total %s is %d%s exceeds max total %s %d%s, which is above threshold of %d%%"
? "%s' total is %d%s, thus exceeds max total %s %d%s, which is above threshold of %d%%"
.formatted(propName, totalValue, propUnit, propName, maxValue, propUnit, propDef.thresholdPercentage())
: null;
} else {
return totalValue > maxValue
? "total %s is %d%s exceeds max total %s %d%s"
? "%s' total is %d%s, thus exceeds max total %s %d%s"
.formatted(propName, totalValue, propUnit, propName, maxValue, propUnit)
: null;
}

View File

@ -60,7 +60,7 @@ public class HsHostingAssetEntityValidator extends HsEntityValidator<HsHostingAs
.reduce(0, Integer::sum);
final var maxValue = getNonNullIntegerValue(propDef, hostingAsset.getConfig());
return totalValue > maxValue
? "total %s is %d%s exceeds max total %s %d%s".formatted(
? "%s' total is %d%s, thus exceeds max total %s %d%s".formatted(
propName, totalValue, propUnit, propName, maxValue, propUnit)
: null;
}

View File

@ -33,7 +33,7 @@ public class BooleanProperty extends ValidatableProperty<Boolean> {
if (falseIf != null && propValue) {
final Object referencedValue = props.get(falseIf.getKey());
if (Objects.equals(referencedValue, falseIf.getValue())) {
result.add(propertyName + " is expected to be false because " +
result.add(propertyName + "' is expected to be false because " +
falseIf.getKey() + "=" + referencedValue + " but is " + propValue);
}
}

View File

@ -33,7 +33,7 @@ public class EnumerationProperty extends ValidatableProperty<String> {
@Override
protected void validate(final ArrayList<String> result, final String propValue, final Map<String, Object> props) {
if (Arrays.stream(values).noneMatch(v -> v.equals(propValue))) {
result.add(propertyName + " is expected to be one of " + Arrays.toString(values) + " but is '" + propValue + "'");
result.add(propertyName + "' is expected to be one of " + Arrays.toString(values) + " but is '" + propValue + "'");
}
}

View File

@ -22,7 +22,8 @@ public abstract class HsEntityValidator<E> {
protected static List<String> enrich(final String prefix, final List<String> messages) {
return messages.stream()
.map(message -> prefix + "." + message)
// FIXME: this is a bit hacky, I need to find the right place to add the prefix
.map(message -> message.startsWith("'") ? message : ("'" + prefix + "." + message))
.toList();
}
@ -42,7 +43,7 @@ public abstract class HsEntityValidator<E> {
final var result = new ArrayList<String>();
properties.keySet().forEach( givenPropName -> {
if (stream(propertyValidators).map(pv -> pv.propertyName).noneMatch(propName -> propName.equals(givenPropName))) {
result.add(givenPropName + " is not expected but is set to '" + properties.get(givenPropName) + "'");
result.add(givenPropName + "' is not expected but is set to '" + properties.get(givenPropName) + "'");
}
});
stream(propertyValidators).forEach(pv -> {

View File

@ -39,13 +39,13 @@ public class IntegerProperty extends ValidatableProperty<Integer> {
@Override
protected void validate(final ArrayList<String> result, final Integer propValue, final Map<String, Object> props) {
if (min != null && propValue < min) {
result.add(propertyName + " is expected to be >= " + min + " but is " + propValue);
result.add(propertyName + "' is expected to be >= " + min + " but is " + propValue);
}
if (max != null && propValue > max) {
result.add(propertyName + " is expected to be <= " + max + " but is " + propValue);
result.add(propertyName + "' is expected to be <= " + max + " but is " + propValue);
}
if (step != null && propValue % step != 0) {
result.add(propertyName + " is expected to be multiple of " + step + " but is " + propValue);
result.add(propertyName + "' is expected to be multiple of " + step + " but is " + propValue);
}
}

View File

@ -92,7 +92,7 @@ public abstract class ValidatableProperty<T> {
final var propValue = props.get(propertyName);
if (propValue == null) {
if (required) {
result.add(propertyName + " is required but missing");
result.add(propertyName + "' is required but missing");
}
}
if (propValue != null){
@ -100,7 +100,7 @@ public abstract class ValidatableProperty<T> {
//noinspection unchecked
validate(result, (T) propValue, props);
} else {
result.add(propertyName + " is expected to be of type " + type + ", " +
result.add(propertyName + "' is expected to be of type " + type + ", " +
"but is of type '" + propValue.getClass().getSimpleName() + "'");
}
}

View File

@ -38,10 +38,10 @@ class HsBookingItemEntityValidatorUnitTest {
// then
assertThat(result).isInstanceOf(ValidationException.class)
.hasMessageContaining(
"D-12345:test project:Test-Server.resources.CPUs is required but missing",
"D-12345:test project:Test-Server.resources.RAM is required but missing",
"D-12345:test project:Test-Server.resources.SSD is required but missing",
"D-12345:test project:Test-Server.resources.Traffic is required but missing");
"D-12345:test project:Test-Server.resources.CPUs' is required but missing",
"D-12345:test project:Test-Server.resources.RAM' is required but missing",
"D-12345:test project:Test-Server.resources.SSD' is required but missing",
"D-12345:test project:Test-Server.resources.Traffic' is required but missing");
}
@Test

View File

@ -45,7 +45,7 @@ class HsCloudServerBookingItemValidatorUnitTest {
final var result = HsBookingItemEntityValidatorRegistry.doValidate(cloudServerBookingItemEntity);
// then
assertThat(result).containsExactly("D-12345:Test-Project:Test-Server.resources.SLA-EMail is not expected but is set to 'true'");
assertThat(result).containsExactly("'D-12345:Test-Project:Test-Server.resources.SLA-EMail' is not expected but is set to 'true'");
}
@Test
@ -109,10 +109,10 @@ class HsCloudServerBookingItemValidatorUnitTest {
// then
assertThat(result).containsExactlyInAnyOrder(
"D-12345:Test-Project:Test Cloud-Server.parentItem.total CPUs is 5 exceeds max total CPUs 4",
"D-12345:Test-Project:Test Cloud-Server.parentItem.total RAM is 30 GB exceeds max total RAM 20 GB",
"D-12345:Test-Project:Test Cloud-Server.parentItem.total SSD is 150 GB exceeds max total SSD 100 GB",
"D-12345:Test-Project:Test Cloud-Server.parentItem.total Traffic is 5500 GB exceeds max total Traffic 5000 GB"
"'D-12345:Test-Project:Test Cloud-Server.parentItem.CPUs' total is 5, thus exceeds max total CPUs 4",
"'D-12345:Test-Project:Test Cloud-Server.parentItem.RAM' total is 30 GB, thus exceeds max total RAM 20 GB",
"'D-12345:Test-Project:Test Cloud-Server.parentItem.SSD' total is 150 GB, thus exceeds max total SSD 100 GB",
"'D-12345:Test-Project:Test Cloud-Server.parentItem.Traffic' total is 5500 GB, thus exceeds max total Traffic 5000 GB"
);
}
}

View File

@ -53,7 +53,7 @@ class HsManagedServerBookingItemValidatorUnitTest {
final var result = HsBookingItemEntityValidatorRegistry.doValidate(mangedServerBookingItemEntity);
// then
assertThat(result).containsExactly("D-12345:Test-Project:null.resources.SLA-EMail is expected to be false because SLA-Platform=BASIC but is true");
assertThat(result).containsExactly("'D-12345:Test-Project:null.resources.SLA-EMail' is expected to be false because SLA-Platform=BASIC but is true");
}
@Test
@ -120,10 +120,10 @@ class HsManagedServerBookingItemValidatorUnitTest {
// then
assertThat(result).containsExactlyInAnyOrder(
"D-12345:Test-Project:null.parentItem.total CPUs is 5 exceeds max total CPUs 4",
"D-12345:Test-Project:null.parentItem.total RAM is 30 GB exceeds max total RAM 20 GB",
"D-12345:Test-Project:null.parentItem.total SSD is 150 GB exceeds max total SSD 100 GB",
"D-12345:Test-Project:null.parentItem.total Traffic is 5500 GB exceeds max total Traffic 5000 GB"
"'D-12345:Test-Project:null.parentItem.CPUs' total is 5, thus exceeds max total CPUs 4",
"'D-12345:Test-Project:null.parentItem.RAM' total is 30 GB, thus exceeds max total RAM 20 GB",
"'D-12345:Test-Project:null.parentItem.SSD' total is 150 GB, thus exceeds max total SSD 100 GB",
"'D-12345:Test-Project:null.parentItem.Traffic' total is 5500 GB, thus exceeds max total Traffic 5000 GB"
);
}

View File

@ -41,10 +41,10 @@ class HsManagedWebspaceBookingItemValidatorUnitTest {
// then
assertThat(result).containsExactlyInAnyOrder(
"D-12345:Test-Project:Test Managed-Webspace.resources.CPUs is not expected but is set to '2'",
"D-12345:Test-Project:Test Managed-Webspace.resources.RAM is not expected but is set to '25'",
"D-12345:Test-Project:Test Managed-Webspace.resources.SSD is required but missing",
"D-12345:Test-Project:Test Managed-Webspace.resources.SLA-EMail is not expected but is set to 'true'"
"'D-12345:Test-Project:Test Managed-Webspace.resources.CPUs' is not expected but is set to '2'",
"'D-12345:Test-Project:Test Managed-Webspace.resources.RAM' is not expected but is set to '25'",
"'D-12345:Test-Project:Test Managed-Webspace.resources.SSD' is required but missing",
"'D-12345:Test-Project:Test Managed-Webspace.resources.SLA-EMail' is not expected but is set to 'true'"
);
}

View File

@ -91,10 +91,10 @@ class HsPrivateCloudBookingItemValidatorTest {
// then
assertThat(result).containsExactlyInAnyOrder(
"total CPUs is 5 exceeds max total CPUs 4",
"total RAM is 30 GB exceeds max total RAM 20 GB",
"total SSD is 150 GB exceeds max total SSD 100 GB",
"total Traffic is 5500 GB exceeds max total Traffic 5000 GB"
"CPUs' total is 5, thus exceeds max total CPUs 4",
"RAM' total is 30 GB, thus exceeds max total RAM 20 GB",
"SSD' total is 150 GB, thus exceeds max total SSD 100 GB",
"Traffic' total is 5500 GB, thus exceeds max total Traffic 5000 GB"
);
}

View File

@ -279,10 +279,10 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
{
"statusPhrase": "Bad Request",
"message": "[
<<<MANAGED_SERVER:vm1400.config.extra is not expected but is set to '42',
<<<MANAGED_SERVER:vm1400.config.monit_max_ssd_usage is expected to be >= 10 but is 0,
<<<MANAGED_SERVER:vm1400.config.monit_max_cpu_usage is expected to be <= 100 but is 101,
<<<MANAGED_SERVER:vm1400.config.monit_max_ram_usage is required but missing
<<<'MANAGED_SERVER:vm1400.config.extra' is not expected but is set to '42',
<<<'MANAGED_SERVER:vm1400.config.monit_max_ssd_usage' is expected to be >= 10 but is 0,
<<<'MANAGED_SERVER:vm1400.config.monit_max_cpu_usage' is expected to be <= 100 but is 101,
<<<'MANAGED_SERVER:vm1400.config.monit_max_ram_usage' is required but missing
<<<]"
}
""".replaceAll(" +<<<", ""))); // @formatter:on
@ -334,7 +334,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
{
"statusPhrase": "Bad Request",
"message": "[
<<<UNIX_USER:fir01-extra.parentAsset.MANAGED_WEBSPACE:fir01.bookingItem.Multi=1 allows at maximum 25 unix users, but 26 found
<<<'MANAGED_WEBSPACE:fir01.bookingItem.Multi=1 allows at maximum 25 unix users, but 26 found
<<<]"
}
""".replaceAll(" +<<<", ""))); // @formatter:on

View File

@ -28,7 +28,7 @@ class HsCloudServerHostingAssetValidatorUnitTest {
final var result = validator.validate(cloudServerHostingAssetEntity);
// then
assertThat(result).containsExactly("CLOUD_SERVER:vm1234.config.RAM is not expected but is set to '2000'");
assertThat(result).containsExactly("'CLOUD_SERVER:vm1234.config.RAM' is not expected but is set to '2000'");
}
@Test

View File

@ -30,9 +30,9 @@ class HsManagedServerHostingAssetValidatorUnitTest {
// then
assertThat(result).containsExactlyInAnyOrder(
"MANAGED_SERVER:vm1234.config.monit_max_ssd_usage is required but missing",
"MANAGED_SERVER:vm1234.config.monit_max_hdd_usage is expected to be of type class java.lang.Integer, but is of type 'String'",
"MANAGED_SERVER:vm1234.config.monit_max_cpu_usage is expected to be >= 10 but is 2",
"MANAGED_SERVER:vm1234.config.monit_max_ram_usage is expected to be <= 100 but is 101");
"'MANAGED_SERVER:vm1234.config.monit_max_cpu_usage' is expected to be >= 10 but is 2",
"'MANAGED_SERVER:vm1234.config.monit_max_ram_usage' is expected to be <= 100 but is 101",
"'MANAGED_SERVER:vm1234.config.monit_max_ssd_usage' is required but missing",
"'MANAGED_SERVER:vm1234.config.monit_max_hdd_usage' is expected to be of type class java.lang.Integer, but is of type 'String'");
}
}

View File

@ -73,7 +73,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
final var result = validator.validate(mangedWebspaceHostingAssetEntity);
// then
assertThat(result).containsExactly("MANAGED_WEBSPACE:abc00.config.unknown is not expected but is set to 'some value'");
assertThat(result).containsExactly("'MANAGED_WEBSPACE:abc00.config.unknown' is not expected but is set to 'some value'");
}
@Test