From 766510e078c06e9c3a138e8631d134bd82646c82 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 19 Jun 2024 17:20:13 +0200 Subject: [PATCH] implement asTotalLimit(...) validation for SLA-EMail etc. --- .../HsBookingItemEntityValidator.java | 2 + .../HsPrivateCloudBookingItemValidator.java | 10 ++--- ...vateCloudBookingItemValidatorUnitTest.java | 45 ++++++++++++++----- 3 files changed, 40 insertions(+), 17 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 f99a8cb8..5a4a7624 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 @@ -3,6 +3,7 @@ package net.hostsharing.hsadminng.hs.booking.item.validators; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.validation.HsEntityValidator; import net.hostsharing.hsadminng.hs.validation.ValidatableProperty; +import org.apache.commons.lang3.BooleanUtils; import java.util.Collection; import java.util.List; @@ -59,6 +60,7 @@ public class HsBookingItemEntityValidator extends HsEntityValidator propDef.getValue(subItem.getResources())) + .map(v -> v instanceof Boolean ? BooleanUtils.toInteger((Boolean)v) : v) .map(HsBookingItemEntityValidator::toIntegerWithDefault0) .reduce(0, Integer::sum); final var maxValue = getIntegerValueWithDefault0(propDef, bookingItem.getResources()); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsPrivateCloudBookingItemValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsPrivateCloudBookingItemValidator.java index c869af6f..236a000a 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsPrivateCloudBookingItemValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsPrivateCloudBookingItemValidator.java @@ -29,11 +29,11 @@ class HsPrivateCloudBookingItemValidator extends HsBookingItemEntityValidator { integerProperty("SLA-Platform EXT4H") .min( 0).max( 20).withDefault(0).asTotalLimitFor("SLA-Platform", "EXT4H"), integerProperty("SLA-Platform EXT2H") .min( 0).max( 20).withDefault(0).asTotalLimitFor("SLA-Platform", "EXT2H"), - integerProperty("SLA-EMail") .min( 0).max( 20).optional().asTotalLimitFor("SLA-Platform", "BASIC"), - integerProperty("SLA-Maria") .min( 0).max( 20).optional().asTotalLimitFor("SLA-Platform", "BASIC"), - integerProperty("SLA-PgSQL") .min( 0).max( 20).optional().asTotalLimitFor("SLA-Platform", "BASIC"), - integerProperty("SLA-Office") .min( 0).max( 20).optional().asTotalLimitFor("SLA-Platform", "BASIC"), - integerProperty("SLA-Web") .min( 0).max( 20).optional().asTotalLimitFor("SLA-Platform", "BASIC") + integerProperty("SLA-EMail") .min( 0).max( 20).withDefault(0).asTotalLimit(), + integerProperty("SLA-Maria") .min( 0).max( 20).withDefault(0).asTotalLimit(), + integerProperty("SLA-PgSQL") .min( 0).max( 20).withDefault(0).asTotalLimit(), + integerProperty("SLA-Office") .min( 0).max( 20).withDefault(0).asTotalLimit(), + integerProperty("SLA-Web") .min( 0).max( 20).withDefault(0).asTotalLimit() // @formatter:on ); } 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 3023c5b9..e916f8c7 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 @@ -28,32 +28,38 @@ class HsPrivateCloudBookingItemValidatorUnitTest { // given final var privateCloudBookingItemEntity = HsBookingItemEntity.builder() .type(PRIVATE_CLOUD) + .caption("myPC") .resources(ofEntries( entry("CPUs", 4), entry("RAM", 20), entry("SSD", 100), entry("Traffic", 5000), - entry("SLA-Platform EXT4H", 2) + entry("SLA-Platform EXT4H", 2), + entry("SLA-EMail", 2) )) .subBookingItems(of( HsBookingItemEntity.builder() .type(MANAGED_SERVER) + .caption("myMS-1") .resources(ofEntries( entry("CPUs", 2), entry("RAM", 10), entry("SSD", 50), entry("Traffic", 2500), - entry("SLA-Platform", "EXT4H") + entry("SLA-Platform", "EXT4H"), + entry("SLA-EMail", true) )) .build(), HsBookingItemEntity.builder() .type(CLOUD_SERVER) + .caption("myMS-2") .resources(ofEntries( entry("CPUs", 2), entry("RAM", 10), entry("SSD", 50), entry("Traffic", 2500), - entry("SLA-Platform", "EXT4H") + entry("SLA-Platform", "EXT4H"), + entry("SLA-EMail", true) )) .build() )) @@ -72,32 +78,42 @@ class HsPrivateCloudBookingItemValidatorUnitTest { final var privateCloudBookingItemEntity = HsBookingItemEntity.builder() .project(project) .type(PRIVATE_CLOUD) + .caption("myPC") .resources(ofEntries( entry("CPUs", 4), entry("RAM", 20), entry("SSD", 100), entry("Traffic", 5000), - entry("SLA-Platform EXT2H", 1) + entry("SLA-Platform EXT2H", 1), + entry("SLA-EMail", 1) )) .subBookingItems(of( HsBookingItemEntity.builder() .type(MANAGED_SERVER) + .caption("myMS-1") .resources(ofEntries( entry("CPUs", 3), entry("RAM", 20), entry("SSD", 100), entry("Traffic", 3000), - entry("SLA-Platform", "EXT2H") + entry("SLA-Platform", "EXT2H"), + entry("SLA-EMail", true) )) .build(), HsBookingItemEntity.builder() .type(CLOUD_SERVER) + .caption("myMS-2") .resources(ofEntries( entry("CPUs", 2), entry("RAM", 10), entry("SSD", 50), entry("Traffic", 2500), - entry("SLA-Platform", "EXT2H") + entry("SLA-Platform", "EXT2H"), + entry("SLA-EMail", true), + entry("SLA-Maria", true), + entry("SLA-PgSQL", true), + entry("SLA-Office", true), + entry("SLA-Web", true) )) .build() )) @@ -108,11 +124,16 @@ class HsPrivateCloudBookingItemValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( - "'D-12345:Test-Project:null.resources.CPUs' maximum total is 4, but actual total CPUs 5", - "'D-12345:Test-Project:null.resources.RAM' maximum total is 20 GB, but actual total RAM 30 GB", - "'D-12345:Test-Project:null.resources.SSD' maximum total is 100 GB, but actual total SSD 150 GB", - "'D-12345:Test-Project:null.resources.Traffic' maximum total is 5000 GB, but actual total Traffic 5500 GB", - "'D-12345:Test-Project:null.resources.1 total SLA-Platform=EXT2H booked, but 2 utilized" - ); + "'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" + ); } }