From c6e0bd8606309b7e9b6b57cca16d7e4cf079a647 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 19 Jun 2024 17:44:13 +0200 Subject: [PATCH] improve error message --- .../HsBookingItemEntityValidator.java | 6 +++--- .../HsHostingAssetEntityValidator.java | 2 +- .../hs/validation/ValidatableProperty.java | 4 +++- ...vateCloudBookingItemValidatorUnitTest.java | 20 +++++++++---------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsBookingItemEntityValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsBookingItemEntityValidator.java index 5a4a7624..c7a1dfa1 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsBookingItemEntityValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsBookingItemEntityValidator.java @@ -60,18 +60,18 @@ public class HsBookingItemEntityValidator extends HsEntityValidator propDef.getValue(subItem.getResources())) - .map(v -> v instanceof Boolean ? BooleanUtils.toInteger((Boolean)v) : v) + .map(v -> v instanceof Boolean ? BooleanUtils.toInteger((Boolean)v) : v) // FIXME: remove? .map(HsBookingItemEntityValidator::toIntegerWithDefault0) .reduce(0, Integer::sum); final var maxValue = getIntegerValueWithDefault0(propDef, bookingItem.getResources()); if (propDef.thresholdPercentage() != null ) { return totalValue > (maxValue * propDef.thresholdPercentage() / 100) - ? "%s' maximum total is %d%s, but actual total %s %d%s, which exceeds threshold of %d%%" + ? "%s' maximum total is %d%s, but actual total %s is %d%s, which exceeds threshold of %d%%" .formatted(propName, maxValue, propUnit, propName, totalValue, propUnit, propDef.thresholdPercentage()) : null; } else { return totalValue > maxValue - ? "%s' maximum total is %d%s, but actual total %s %d%s" + ? "%s' maximum total is %d%s, but actual total %s is %d%s" .formatted(propName, maxValue, propUnit, propName, totalValue, propUnit) : null; } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidator.java index ec844cf7..c452d378 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidator.java @@ -69,7 +69,7 @@ public class HsHostingAssetEntityValidator extends HsEntityValidator maxValue - ? "%s' maximum total is %d%s, but actual total is %s %d%s".formatted( + ? "%s' maximum total is %d%s, but actual total %s is %d%s".formatted( propName, maxValue, propUnit, propName, totalValue, propUnit) : null; } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/validation/ValidatableProperty.java b/src/main/java/net/hostsharing/hsadminng/hs/validation/ValidatableProperty.java index f26485d4..3b0bb099 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/validation/ValidatableProperty.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/validation/ValidatableProperty.java @@ -81,7 +81,9 @@ public abstract class ValidatableProperty { final long limitingValue = ofNullable(prop.getValue(entity.getResources())).orElse(0); if (total > factor*limitingValue) { - return List.of(limitingValue*factor + " total " + propertyName + "=" + propertyValue + " booked, but " + total + " utilized"); + return List.of( + prop.propertyName() + " maximum total is " + (factor*limitingValue) + ", but actual total for " + propertyName + "=" + propertyValue + " is " + total + ); } return emptyList(); }; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsPrivateCloudBookingItemValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsPrivateCloudBookingItemValidatorUnitTest.java index e916f8c7..2a100d2c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsPrivateCloudBookingItemValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsPrivateCloudBookingItemValidatorUnitTest.java @@ -124,16 +124,16 @@ class HsPrivateCloudBookingItemValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( - "'D-12345:Test-Project:myPC.resources.1 total SLA-Platform=EXT2H booked, but 2 utilized", - "'D-12345:Test-Project:myPC.resources.CPUs' maximum total is 4, but actual total CPUs 5", - "'D-12345:Test-Project:myPC.resources.RAM' maximum total is 20 GB, but actual total RAM 30 GB", - "'D-12345:Test-Project:myPC.resources.SSD' maximum total is 100 GB, but actual total SSD 150 GB", - "'D-12345:Test-Project:myPC.resources.Traffic' maximum total is 5000 GB, but actual total Traffic 5500 GB", - "'D-12345:Test-Project:myPC.resources.SLA-EMail' maximum total is 1, but actual total SLA-EMail 2", - "'D-12345:Test-Project:myPC.resources.SLA-Maria' maximum total is 0, but actual total SLA-Maria 1", - "'D-12345:Test-Project:myPC.resources.SLA-PgSQL' maximum total is 0, but actual total SLA-PgSQL 1", - "'D-12345:Test-Project:myPC.resources.SLA-Office' maximum total is 0, but actual total SLA-Office 1", - "'D-12345:Test-Project:myPC.resources.SLA-Web' maximum total is 0, but actual total SLA-Web 1" + "'D-12345:Test-Project:myPC.resources.CPUs' maximum total is 4, but actual total CPUs is 5", + "'D-12345:Test-Project:myPC.resources.RAM' maximum total is 20 GB, but actual total RAM is 30 GB", + "'D-12345:Test-Project:myPC.resources.SSD' maximum total is 100 GB, but actual total SSD is 150 GB", + "'D-12345:Test-Project:myPC.resources.Traffic' maximum total is 5000 GB, but actual total Traffic is 5500 GB", + "'D-12345:Test-Project:myPC.resources.SLA-Platform EXT2H maximum total is 1, but actual total for SLA-Platform=EXT2H is 2", + "'D-12345:Test-Project:myPC.resources.SLA-EMail' maximum total is 1, but actual total SLA-EMail is 2", + "'D-12345:Test-Project:myPC.resources.SLA-Maria' maximum total is 0, but actual total SLA-Maria is 1", + "'D-12345:Test-Project:myPC.resources.SLA-PgSQL' maximum total is 0, but actual total SLA-PgSQL is 1", + "'D-12345:Test-Project:myPC.resources.SLA-Office' maximum total is 0, but actual total SLA-Office is 1", + "'D-12345:Test-Project:myPC.resources.SLA-Web' maximum total is 0, but actual total SLA-Web is 1" ); } }