hierarchical-validation-baseline #59
@ -56,12 +56,12 @@ public class HsBookingItemEntityValidator extends HsEntityValidator<HsBookingIte
|
|||||||
final var maxValue = getNonNullIntegerValue(propDef, bookingItem.getResources());
|
final var maxValue = getNonNullIntegerValue(propDef, bookingItem.getResources());
|
||||||
if (propDef.thresholdPercentage() != null ) {
|
if (propDef.thresholdPercentage() != null ) {
|
||||||
return totalValue > (maxValue * propDef.thresholdPercentage() / 100)
|
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())
|
.formatted(propName, totalValue, propUnit, propName, maxValue, propUnit, propDef.thresholdPercentage())
|
||||||
: null;
|
: null;
|
||||||
} else {
|
} else {
|
||||||
return totalValue > maxValue
|
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)
|
.formatted(propName, totalValue, propUnit, propName, maxValue, propUnit)
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ public class HsHostingAssetEntityValidator extends HsEntityValidator<HsHostingAs
|
|||||||
.reduce(0, Integer::sum);
|
.reduce(0, Integer::sum);
|
||||||
final var maxValue = getNonNullIntegerValue(propDef, hostingAsset.getConfig());
|
final var maxValue = getNonNullIntegerValue(propDef, hostingAsset.getConfig());
|
||||||
return totalValue > maxValue
|
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)
|
propName, totalValue, propUnit, propName, maxValue, propUnit)
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public class BooleanProperty extends ValidatableProperty<Boolean> {
|
|||||||
if (falseIf != null && propValue) {
|
if (falseIf != null && propValue) {
|
||||||
final Object referencedValue = props.get(falseIf.getKey());
|
final Object referencedValue = props.get(falseIf.getKey());
|
||||||
if (Objects.equals(referencedValue, falseIf.getValue())) {
|
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);
|
falseIf.getKey() + "=" + referencedValue + " but is " + propValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public class EnumerationProperty extends ValidatableProperty<String> {
|
|||||||
@Override
|
@Override
|
||||||
protected void validate(final ArrayList<String> result, final String propValue, final Map<String, Object> props) {
|
protected void validate(final ArrayList<String> result, final String propValue, final Map<String, Object> props) {
|
||||||
if (Arrays.stream(values).noneMatch(v -> v.equals(propValue))) {
|
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 + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,8 @@ public abstract class HsEntityValidator<E> {
|
|||||||
|
|
||||||
protected static List<String> enrich(final String prefix, final List<String> messages) {
|
protected static List<String> enrich(final String prefix, final List<String> messages) {
|
||||||
return messages.stream()
|
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();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ public abstract class HsEntityValidator<E> {
|
|||||||
final var result = new ArrayList<String>();
|
final var result = new ArrayList<String>();
|
||||||
properties.keySet().forEach( givenPropName -> {
|
properties.keySet().forEach( givenPropName -> {
|
||||||
if (stream(propertyValidators).map(pv -> pv.propertyName).noneMatch(propName -> propName.equals(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 -> {
|
stream(propertyValidators).forEach(pv -> {
|
||||||
|
@ -39,13 +39,13 @@ public class IntegerProperty extends ValidatableProperty<Integer> {
|
|||||||
@Override
|
@Override
|
||||||
protected void validate(final ArrayList<String> result, final Integer propValue, final Map<String, Object> props) {
|
protected void validate(final ArrayList<String> result, final Integer propValue, final Map<String, Object> props) {
|
||||||
if (min != null && propValue < min) {
|
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) {
|
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) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ public abstract class ValidatableProperty<T> {
|
|||||||
final var propValue = props.get(propertyName);
|
final var propValue = props.get(propertyName);
|
||||||
if (propValue == null) {
|
if (propValue == null) {
|
||||||
if (required) {
|
if (required) {
|
||||||
result.add(propertyName + " is required but missing");
|
result.add(propertyName + "' is required but missing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (propValue != null){
|
if (propValue != null){
|
||||||
@ -100,7 +100,7 @@ public abstract class ValidatableProperty<T> {
|
|||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
validate(result, (T) propValue, props);
|
validate(result, (T) propValue, props);
|
||||||
} else {
|
} 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() + "'");
|
"but is of type '" + propValue.getClass().getSimpleName() + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,10 +38,10 @@ class HsBookingItemEntityValidatorUnitTest {
|
|||||||
// then
|
// then
|
||||||
assertThat(result).isInstanceOf(ValidationException.class)
|
assertThat(result).isInstanceOf(ValidationException.class)
|
||||||
.hasMessageContaining(
|
.hasMessageContaining(
|
||||||
"D-12345:test project:Test-Server.resources.CPUs is required but missing",
|
"D-12345:test project:Test-Server.resources.CPUs' is required but missing",
|
||||||
hsh-michaelhoennig marked this conversation as resolved
Outdated
|
|||||||
"D-12345:test project:Test-Server.resources.RAM 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.SSD' is required but missing",
|
||||||
"D-12345:test project:Test-Server.resources.Traffic is required but missing");
|
"D-12345:test project:Test-Server.resources.Traffic' is required but missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -45,7 +45,7 @@ class HsCloudServerBookingItemValidatorUnitTest {
|
|||||||
final var result = HsBookingItemEntityValidatorRegistry.doValidate(cloudServerBookingItemEntity);
|
final var result = HsBookingItemEntityValidatorRegistry.doValidate(cloudServerBookingItemEntity);
|
||||||
|
|
||||||
// then
|
// 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
|
@Test
|
||||||
@ -109,10 +109,10 @@ class HsCloudServerBookingItemValidatorUnitTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result).containsExactlyInAnyOrder(
|
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.CPUs' total is 5, thus 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.RAM' total is 30 GB, thus 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.SSD' total is 150 GB, thus 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.Traffic' total is 5500 GB, thus exceeds max total Traffic 5000 GB"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ class HsManagedServerBookingItemValidatorUnitTest {
|
|||||||
final var result = HsBookingItemEntityValidatorRegistry.doValidate(mangedServerBookingItemEntity);
|
final var result = HsBookingItemEntityValidatorRegistry.doValidate(mangedServerBookingItemEntity);
|
||||||
|
|
||||||
// then
|
// 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
|
@Test
|
||||||
@ -120,10 +120,10 @@ class HsManagedServerBookingItemValidatorUnitTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result).containsExactlyInAnyOrder(
|
assertThat(result).containsExactlyInAnyOrder(
|
||||||
"D-12345:Test-Project:null.parentItem.total CPUs is 5 exceeds max total CPUs 4",
|
"'D-12345:Test-Project:null.parentItem.CPUs' total is 5, thus 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.RAM' total is 30 GB, thus 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.SSD' total is 150 GB, thus 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.Traffic' total is 5500 GB, thus exceeds max total Traffic 5000 GB"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,10 +41,10 @@ class HsManagedWebspaceBookingItemValidatorUnitTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result).containsExactlyInAnyOrder(
|
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.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.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.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.SLA-EMail' is not expected but is set to 'true'"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,10 +91,10 @@ class HsPrivateCloudBookingItemValidatorTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result).containsExactlyInAnyOrder(
|
assertThat(result).containsExactlyInAnyOrder(
|
||||||
"total CPUs is 5 exceeds max total CPUs 4",
|
"CPUs' total is 5, thus exceeds max total CPUs 4",
|
||||||
"total RAM is 30 GB exceeds max total RAM 20 GB",
|
"RAM' total is 30 GB, thus exceeds max total RAM 20 GB",
|
||||||
"total SSD is 150 GB exceeds max total SSD 100 GB",
|
"SSD' total is 150 GB, thus exceeds max total SSD 100 GB",
|
||||||
"total Traffic is 5500 GB exceeds max total Traffic 5000 GB"
|
"Traffic' total is 5500 GB, thus exceeds max total Traffic 5000 GB"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,10 +279,10 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
|||||||
{
|
{
|
||||||
"statusPhrase": "Bad Request",
|
"statusPhrase": "Bad Request",
|
||||||
"message": "[
|
"message": "[
|
||||||
<<<MANAGED_SERVER:vm1400.config.extra is not expected but is set to '42',
|
<<<'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_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_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.monit_max_ram_usage' is required but missing
|
||||||
<<<]"
|
<<<]"
|
||||||
}
|
}
|
||||||
""".replaceAll(" +<<<", ""))); // @formatter:on
|
""".replaceAll(" +<<<", ""))); // @formatter:on
|
||||||
@ -334,7 +334,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
|||||||
{
|
{
|
||||||
"statusPhrase": "Bad Request",
|
"statusPhrase": "Bad Request",
|
||||||
"message": "[
|
"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
|
""".replaceAll(" +<<<", ""))); // @formatter:on
|
||||||
|
@ -28,7 +28,7 @@ class HsCloudServerHostingAssetValidatorUnitTest {
|
|||||||
final var result = validator.validate(cloudServerHostingAssetEntity);
|
final var result = validator.validate(cloudServerHostingAssetEntity);
|
||||||
|
|
||||||
// then
|
// 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
|
@Test
|
||||||
|
@ -30,9 +30,9 @@ class HsManagedServerHostingAssetValidatorUnitTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result).containsExactlyInAnyOrder(
|
assertThat(result).containsExactlyInAnyOrder(
|
||||||
"MANAGED_SERVER:vm1234.config.monit_max_ssd_usage is required but missing",
|
"'MANAGED_SERVER:vm1234.config.monit_max_cpu_usage' is expected to be >= 10 but is 2",
|
||||||
"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_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_ssd_usage' is required but missing",
|
||||||
"MANAGED_SERVER:vm1234.config.monit_max_ram_usage is expected to be <= 100 but is 101");
|
"'MANAGED_SERVER:vm1234.config.monit_max_hdd_usage' is expected to be of type class java.lang.Integer, but is of type 'String'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
|
|||||||
final var result = validator.validate(mangedWebspaceHostingAssetEntity);
|
final var result = validator.validate(mangedWebspaceHostingAssetEntity);
|
||||||
|
|
||||||
// then
|
// 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
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user
Hochkomma vorne einfügen