improve error message
This commit is contained in:
parent
766510e078
commit
c6e0bd8606
@ -60,18 +60,18 @@ public class HsBookingItemEntityValidator extends HsEntityValidator<HsBookingIte
|
||||
final var totalValue = ofNullable(bookingItem.getSubBookingItems()).orElse(emptyList())
|
||||
.stream()
|
||||
.map(subItem -> 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;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public class HsHostingAssetEntityValidator extends HsEntityValidator<HsHostingAs
|
||||
.reduce(0, Integer::sum);
|
||||
final var maxValue = getIntegerValueWithDefault0(propDef, hostingAsset.getConfig());
|
||||
return totalValue > 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;
|
||||
}
|
||||
|
@ -81,7 +81,9 @@ public abstract class ValidatableProperty<T> {
|
||||
|
||||
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();
|
||||
};
|
||||
|
@ -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"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user