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 0db195f3..a126bcf7 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 @@ -167,7 +167,7 @@ public abstract class HsHostingAssetEntityValidator extends HsEntityValidator bi.getRelatedProject().getCaption().contains(projectCaption)) - .findAny().orElseThrow(); + HsBookingItemEntity givenSomeNewBookingItem(final String projectCaption, final HsBookingItemType bookingItemType, final String bookingItemCaption) { + return jpaAttempt.transacted(() -> { + context.define("superuser-alex@hostsharing.net"); + final var project = projectRepo.findByCaption(projectCaption).getFirst(); + final var resources = switch (bookingItemType) { + case MANAGED_SERVER -> Map.ofEntries(entry("CPUs", 1), entry("RAM", 20), entry("SSD", 25), entry("Traffic", 250)); + default -> new HashMap(); + }; + final var newBookingItem = HsBookingItemEntity.builder() + .project(project) + .type(bookingItemType) + .caption(bookingItemCaption) + .resources(resources) + .build(); + return toCleanup(bookingItemRepo.save(newBookingItem)); + }).assertSuccessful().returnedValue(); } HsHostingAssetEntity givenParentAsset(final HsHostingAssetType assetType, final String assetIdentifier) { @@ -574,16 +587,23 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup @SafeVarargs private HsHostingAssetEntity givenSomeTemporaryHostingAsset(final String identifierSuffix, final HsHostingAssetType hostingAssetType, - final Map.Entry... resources) { + final Map.Entry... config) { return jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net"); + final var bookingItemType = switch (hostingAssetType) { + case CLOUD_SERVER -> HsBookingItemType.CLOUD_SERVER; + case MANAGED_SERVER -> HsBookingItemType.MANAGED_SERVER; + case MANAGED_WEBSPACE -> HsBookingItemType.MANAGED_WEBSPACE; + default -> null; + }; + final var newBookingItem = givenSomeNewBookingItem("D-1000111 default project", bookingItemType, "temp ManagedServer"); final var newAsset = HsHostingAssetEntity.builder() .uuid(UUID.randomUUID()) - .bookingItem(givenBookingItem("D-1000111 default project", "some ManagedServer")) + .bookingItem(newBookingItem) .type(hostingAssetType) .identifier("vm" + identifierSuffix) .caption("some test-asset") - .config(Map.ofEntries(resources)) + .config(Map.ofEntries(config)) .build(); return assetRepo.save(newAsset); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityUnitTest.java index c53effff..1dd7c0e1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityUnitTest.java @@ -58,7 +58,7 @@ class HsHostingAssetEntityUnitTest { void toStringContainsAllPropertiesAndResourcesSortedByKey() { assertThat(givenWebspace.toString()).isEqualTo( - "HsHostingAssetEntity(MANAGED_WEBSPACE, xyz00, some managed webspace, MANAGED_SERVER:vm1234, D-1234500:test project:test booking item, { CPUs: 2, HDD-storage: 2048, SSD-storage: 512 })"); + "HsHostingAssetEntity(MANAGED_WEBSPACE, xyz00, some managed webspace, MANAGED_SERVER:vm1234, D-1234500:test project:test cloud server booking item, { CPUs: 2, HDD-storage: 2048, SSD-storage: 512 })"); assertThat(givenUnixUser.toString()).isEqualTo( "HsHostingAssetEntity(UNIX_USER, xyz00-web, some unix-user, MANAGED_WEBSPACE:xyz00, { HDD-hard-quota: 512, HDD-soft-quota: 256, SSD-hard-quota: 256, SSD-soft-quota: 128 })"); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidatorUnitTest.java index b3f6d02e..73776e89 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidatorUnitTest.java @@ -3,7 +3,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import org.junit.jupiter.api.Test; @@ -21,6 +20,7 @@ class HsHostingAssetEntityValidatorUnitTest { .identifier("vm1234") .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.MANAGED_SERVER).build()) .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build()) + .assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build()) .build(); // when @@ -28,8 +28,8 @@ class HsHostingAssetEntityValidatorUnitTest { // then assertThat(result.getMessage()).contains( - "'MANAGED_SERVER:vm1234.parentAsset' must not be null but is set to D-???????-?:null", - "'MANAGED_SERVER:vm1234.assignedToAsset' must not be null but is set to D-???????-?:null" + "'MANAGED_SERVER:vm1234.parentAsset' must be null but is set to D-???????-?:null", + "'MANAGED_SERVER:vm1234.assignedToAsset' must be null but is set to D-???????-?:null" ); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedServerHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedServerHostingAssetValidatorUnitTest.java index 08d2b777..24189add 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedServerHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedServerHostingAssetValidatorUnitTest.java @@ -20,6 +20,8 @@ class HsManagedServerHostingAssetValidatorUnitTest { .type(MANAGED_SERVER) .identifier("vm1234") .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.MANAGED_SERVER).build()) + .parentAsset(HsHostingAssetEntity.builder().build()) + .assignedToAsset(HsHostingAssetEntity.builder().build()) .config(Map.ofEntries( entry("monit_max_hdd_usage", "90"), entry("monit_max_cpu_usage", 2), @@ -33,8 +35,8 @@ class HsManagedServerHostingAssetValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( - "'MANAGED_SERVER:vm1234.parentAsset' must not be null but is set to D-???????-?:null", - "'MANAGED_SERVER:vm1234.assignedToAsset' must not be null but is set to D-???????-?:null", + "'MANAGED_SERVER:vm1234.parentAsset' must be null but is set to D-???????-?:null", + "'MANAGED_SERVER:vm1234.assignedToAsset' must be null but is set to D-???????-?:null", "'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_hdd_usage' is expected to be of type class java.lang.Integer, but is of type 'String'"); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedWebspaceHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedWebspaceHostingAssetValidatorUnitTest.java index 1037e32c..014721af 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedWebspaceHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedWebspaceHostingAssetValidatorUnitTest.java @@ -84,7 +84,11 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder() .type(MANAGED_WEBSPACE) - .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.MANAGED_WEBSPACE).build()) + .bookingItem(HsBookingItemEntity.builder() + .type(HsBookingItemType.MANAGED_WEBSPACE) + .caption("some ManagedWebspace") + .resources(Map.ofEntries(entry("SSD", 25), entry("Traffic", 250))) + .build()) .parentAsset(mangedServerAssetEntity) .identifier("abc00") .build(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidatorUnitTest.java index 427061e5..afe265b0 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidatorUnitTest.java @@ -3,6 +3,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; import org.junit.jupiter.api.Test; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.UNIX_USER; import static org.assertj.core.api.Assertions.assertThat; @@ -13,7 +14,8 @@ class HsUnixUserHostingAssetValidatorUnitTest { // given final var unixUserHostingAsset = HsHostingAssetEntity.builder() .type(UNIX_USER) - .identifier("abc") + .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).identifier("abc00").build()) + .identifier("xyz99-temp") .build(); final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType()); @@ -22,6 +24,7 @@ class HsUnixUserHostingAssetValidatorUnitTest { final var result = validator.validate(unixUserHostingAsset); // then - assertThat(result).containsExactly("'identifier' expected to match '^vm[0-9][0-9][0-9][0-9]$', but is 'xyz99'"); + assertThat(result).containsExactly( + "'identifier' expected to match '^abc00$|^abc00-[a-z0-9]+$', but is 'xyz99-temp'"); } }