From b85706674bb43a897b66bab424e6891154a01059 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 5 Jun 2024 15:07:32 +0200 Subject: [PATCH] add assigned asset and more test-data --- .../hs/booking/item/HsBookingItemEntity.java | 4 + .../booking/item/HsBookingItemRepository.java | 3 +- .../project/HsBookingProjectEntity.java | 2 +- .../project/HsBookingProjectRepository.java | 2 +- .../hosting/asset/HsHostingAssetEntity.java | 20 +++- .../asset/HsHostingAssetRepository.java | 3 +- .../hs/hosting/asset/HsHostingAssetType.java | 6 +- .../HsCloudServerHostingAssetValidator.java | 20 ---- .../HsHostingAssetEntityValidators.java | 2 +- .../HsManagedServerHostingAssetValidator.java | 12 +- ...sManagedWebspaceHostingAssetValidator.java | 6 - .../hs-hosting/hs-hosting-asset-schemas.yaml | 4 +- .../7010-hs-hosting-asset.sql | 11 +- .../7013-hs-hosting-asset-rbac.md | 24 ++-- .../7013-hs-hosting-asset-rbac.sql | 15 ++- .../7018-hs-hosting-asset-test-data.sql | 18 ++- ...HsBookingItemControllerAcceptanceTest.java | 8 +- ...sBookingItemRepositoryIntegrationTest.java | 3 +- ...ookingProjectControllerAcceptanceTest.java | 9 +- ...sHostingAssetControllerAcceptanceTest.java | 107 +++++++----------- .../asset/HsHostingAssetEntityUnitTest.java | 38 ++++++- ...ingAssetPropsControllerAcceptanceTest.java | 69 ++++++----- ...HostingAssetRepositoryIntegrationTest.java | 23 ++-- 23 files changed, 207 insertions(+), 202 deletions(-) delete mode 100644 src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidator.java diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntity.java index 4739c638..07d9311d 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemEntity.java @@ -160,6 +160,10 @@ public class HsBookingItemEntity implements Stringifyable, RbacObject, Validatab return resources; } + public HsBookingProjectEntity getRelatedProject() { + return project != null ? project : parentItem.getRelatedProject(); + } + public static RbacView rbac() { return rbacViewFor("bookingItem", HsBookingItemEntity.class) .withIdentityView(SQL.projection("caption")) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRepository.java index cda96233..9ee9badc 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRepository.java @@ -8,9 +8,10 @@ import java.util.UUID; public interface HsBookingItemRepository extends Repository { - List findAll(); Optional findByUuid(final UUID bookingItemUuid); + List findByCaption(String bookingItemCaption); + List findAllByProjectUuid(final UUID projectItemUuid); HsBookingItemEntity save(HsBookingItemEntity current); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectEntity.java index aee3242f..90fa1ea5 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectEntity.java @@ -49,7 +49,7 @@ public class HsBookingProjectEntity implements Stringifyable, RbacObject { @ManyToOne(optional = false) @JoinColumn(name = "debitoruuid") - private HsOfficeDebitorEntity debitor; + private HsOfficeDebitorEntity debitor; // FIXME: introduce HsBookingDebitorEntity @Column(name = "caption") private String caption; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectRepository.java index b224dad6..f8a171b4 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectRepository.java @@ -8,8 +8,8 @@ import java.util.UUID; public interface HsBookingProjectRepository extends Repository { - List findAll(); Optional findByUuid(final UUID bookingProjectUuid); + List findByCaption(final String projectCaption); List findAllByDebitorUuid(final UUID bookingProjectUuid); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java index 04a812a2..8d573c48 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java @@ -33,9 +33,7 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; -import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_SERVER; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Column.dependsOnColumn; -import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.ColumnValue.usingCase; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.ColumnValue.usingDefaultCase; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.GLOBAL; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Nullable.NULLABLE; @@ -65,6 +63,7 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject, Validata .withProp(HsHostingAssetEntity::getIdentifier) .withProp(HsHostingAssetEntity::getCaption) .withProp(HsHostingAssetEntity::getParentAsset) + .withProp(HsHostingAssetEntity::getAssignedToAsset) .withProp(HsHostingAssetEntity::getBookingItem) .withProp(HsHostingAssetEntity::getConfig) .quotedValues(false); @@ -84,6 +83,10 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject, Validata @JoinColumn(name = "parentassetuuid") private HsHostingAssetEntity parentAsset; + @ManyToOne + @JoinColumn(name = "assignedtoassetuuid") + private HsHostingAssetEntity assignedToAsset; + @Column(name = "type") @Enumerated(EnumType.STRING) private HsHostingAssetType type; @@ -144,12 +147,17 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject, Validata NULLABLE) .toRole("bookingItem", AGENT).grantPermission(INSERT) - .importEntityAlias("parentAsset", HsHostingAssetEntity.class, usingCase(MANAGED_SERVER), + .importEntityAlias("parentAsset", HsHostingAssetEntity.class, usingDefaultCase(), dependsOnColumn("parentAssetUuid"), directlyFetchedByDependsOnColumn(), NULLABLE) .toRole("parentAsset", ADMIN).grantPermission(INSERT) + .importEntityAlias("assignedToAsset", HsHostingAssetEntity.class, usingDefaultCase(), + dependsOnColumn("assignedToAssetUuid"), + directlyFetchedByDependsOnColumn(), + NULLABLE) + .createRole(OWNER, (with) -> { with.incomingSuperRole("bookingItem", ADMIN); with.incomingSuperRole("parentAsset", ADMIN); @@ -160,13 +168,15 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject, Validata with.incomingSuperRole("parentAsset", AGENT); with.permission(UPDATE); }) - .createSubRole(AGENT) + .createSubRole(AGENT, (with) -> { + with.outgoingSubRole("assignedToAsset", TENANT); + }) .createSubRole(TENANT, (with) -> { with.outgoingSubRole("bookingItem", TENANT); with.outgoingSubRole("parentAsset", TENANT); with.permission(SELECT); }) - .limitDiagramTo("asset", "bookingItem", "bookingItem.debitorRel", "parentServer", "global"); + .limitDiagramTo("asset", "bookingItem", "bookingItem.debitorRel", "parentAsset", "assignedToAsset", "global"); } public static void main(String[] args) throws IOException { diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepository.java index 7de7726b..cefe79f6 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepository.java @@ -10,9 +10,10 @@ import java.util.UUID; public interface HsHostingAssetRepository extends Repository { - List findAll(); Optional findByUuid(final UUID serverUuid); + List findByIdentifier(String assetIdentifier); + @Query(""" SELECT asset FROM HsHostingAssetEntity asset WHERE (:projectUuid IS NULL OR asset.bookingItem.project.uuid = :projectUuid) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetType.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetType.java index f4040046..f02a50f0 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetType.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetType.java @@ -6,11 +6,13 @@ public enum HsHostingAssetType { MANAGED_SERVER, // named e.g. vm1234 MANAGED_WEBSPACE(MANAGED_SERVER), // named eg. xyz00 UNIX_USER(MANAGED_WEBSPACE), // named e.g. xyz00-abc - DOMAIN_SETUP(UNIX_USER), // named e.g. example.org + DOMAIN_DNS_SETUP(MANAGED_WEBSPACE), // named e.g. example.org + DOMAIN_HTTP_SETUP(MANAGED_WEBSPACE), // named e.g. example.org + DOMAIN_EMAIL_SETUP(MANAGED_WEBSPACE), // named e.g. example.org // TODO.spec: SECURE_MX EMAIL_ALIAS(MANAGED_WEBSPACE), // named e.g. xyz00-abc - EMAIL_ADDRESS(DOMAIN_SETUP), // named e.g. sample@example.org + EMAIL_ADDRESS(DOMAIN_EMAIL_SETUP), // named e.g. sample@example.org PGSQL_USER(MANAGED_WEBSPACE), // named e.g. xyz00_abc PGSQL_DATABASE(MANAGED_WEBSPACE), // named e.g. xyz00_abc, TODO.spec: or PGSQL_USER? MARIADB_USER(MANAGED_WEBSPACE), // named e.g. xyz00_abc diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidator.java deleted file mode 100644 index 8c43dd43..00000000 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidator.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.hostsharing.hsadminng.hs.hosting.asset.validators; - -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; -import net.hostsharing.hsadminng.hs.validation.HsEntityValidator; - -import static net.hostsharing.hsadminng.hs.validation.IntegerPropertyValidator.integerProperty; - -class HsCloudServerHostingAssetValidator extends HsEntityValidator { - - public HsCloudServerHostingAssetValidator() { - super( - integerProperty("CPUs").min(1).max(32).required(), - integerProperty("RAM").unit("GB").min(1).max(128).required(), - integerProperty("SSD").unit("GB").min(25).max(1000).step(25).required(), - integerProperty("HDD").unit("GB").min(0).max(4000).step(250).optional(), - integerProperty("Traffic").unit("GB").min(250).max(10000).step(250).required() - ); - } -} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidators.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidators.java index c4eaef0f..11df9a84 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidators.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidators.java @@ -20,7 +20,7 @@ public class HsHostingAssetEntityValidators { private static final Map, HsEntityValidator> validators = new HashMap<>(); static { - register(CLOUD_SERVER, new HsCloudServerHostingAssetValidator()); + register(CLOUD_SERVER, new HsEntityValidator<>()); register(MANAGED_SERVER, new HsManagedServerHostingAssetValidator()); register(MANAGED_WEBSPACE, new HsManagedWebspaceHostingAssetValidator()); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedServerHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedServerHostingAssetValidator.java index aee10839..35f3b81d 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedServerHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsManagedServerHostingAssetValidator.java @@ -10,11 +10,13 @@ class HsManagedServerHostingAssetValidator extends HsEntityValidator { public HsManagedWebspaceHostingAssetValidator() { - super( - integerProperty("SSD").unit("GB").min(1).max(100).step(1).required(), - integerProperty("HDD").unit("GB").min(0).max(250).step(10).optional(), - integerProperty("Traffic").unit("GB").min(10).max(1000).step(10).required() - ); } @Override diff --git a/src/main/resources/api-definition/hs-hosting/hs-hosting-asset-schemas.yaml b/src/main/resources/api-definition/hs-hosting/hs-hosting-asset-schemas.yaml index 7390c3c8..8e9dbe02 100644 --- a/src/main/resources/api-definition/hs-hosting/hs-hosting-asset-schemas.yaml +++ b/src/main/resources/api-definition/hs-hosting/hs-hosting-asset-schemas.yaml @@ -10,7 +10,9 @@ components: - MANAGED_SERVER - MANAGED_WEBSPACE - UNIX_USER - - DOMAIN_SETUP + - DOMAIN_DNS_SETUP + - DOMAIN_HTTP_SETUP + - DOMAIN_EMAIL_SETUP - EMAIL_ALIAS - EMAIL_ADDRESS - PGSQL_USER diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql index 755dbbec..c6fedb72 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql @@ -9,7 +9,9 @@ create type HsHostingAssetType as enum ( 'MANAGED_SERVER', 'MANAGED_WEBSPACE', 'UNIX_USER', - 'DOMAIN_SETUP', + 'DOMAIN_DNS_SETUP', + 'DOMAIN_HTTP_SETUP', + 'DOMAIN_EMAIL_SETUP', 'EMAIL_ALIAS', 'EMAIL_ADDRESS', 'PGSQL_USER', @@ -27,6 +29,7 @@ create table if not exists hs_hosting_asset bookingItemUuid uuid null references hs_booking_item(uuid), type HsHostingAssetType not null, parentAssetUuid uuid null references hs_hosting_asset(uuid) initially deferred, + assignedToAssetUuid uuid null references hs_hosting_asset(uuid) initially deferred, identifier varchar(80) not null, caption varchar(80), config jsonb not null, @@ -59,9 +62,11 @@ begin when 'MANAGED_SERVER' then null when 'MANAGED_WEBSPACE' then 'MANAGED_SERVER' when 'UNIX_USER' then 'MANAGED_WEBSPACE' - when 'DOMAIN_SETUP' then 'UNIX_USER' + when 'DOMAIN_DNS_SETUP' then 'MANAGED_WEBSPACE' + when 'DOMAIN_HTTP_SETUP' then 'MANAGED_WEBSPACE' + when 'DOMAIN_EMAIL_SETUP' then 'MANAGED_WEBSPACE' when 'EMAIL_ALIAS' then 'MANAGED_WEBSPACE' - when 'EMAIL_ADDRESS' then 'DOMAIN_SETUP' + when 'EMAIL_ADDRESS' then 'DOMAIN_EMAIL_SETUP' when 'PGSQL_USER' then 'MANAGED_WEBSPACE' when 'PGSQL_DATABASE' then 'MANAGED_WEBSPACE' when 'MARIADB_USER' then 'MANAGED_WEBSPACE' diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.md b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.md index b9a65745..bf7780e1 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.md +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.md @@ -25,40 +25,30 @@ subgraph asset["`**asset**`"] perm:asset:INSERT{{asset:INSERT}} perm:asset:DELETE{{asset:DELETE}} perm:asset:UPDATE{{asset:UPDATE}} - perm:asset:SELECT{{asset:SELECT}} end end -subgraph bookingItem["`**bookingItem**`"] +subgraph assignedToAsset["`**assignedToAsset**`"] direction TB - style bookingItem fill:#99bcdb,stroke:#274d6e,stroke-width:8px + style assignedToAsset fill:#99bcdb,stroke:#274d6e,stroke-width:8px - subgraph bookingItem:roles[ ] - style bookingItem:roles fill:#99bcdb,stroke:white + subgraph assignedToAsset:roles[ ] + style assignedToAsset:roles fill:#99bcdb,stroke:white - role:bookingItem:OWNER[[bookingItem:OWNER]] - role:bookingItem:ADMIN[[bookingItem:ADMIN]] - role:bookingItem:AGENT[[bookingItem:AGENT]] - role:bookingItem:TENANT[[bookingItem:TENANT]] + role:assignedToAsset:TENANT[[assignedToAsset:TENANT]] end end %% granting roles to roles -role:bookingItem:OWNER -.-> role:bookingItem:ADMIN -role:bookingItem:ADMIN -.-> role:bookingItem:AGENT -role:bookingItem:AGENT -.-> role:bookingItem:TENANT -role:bookingItem:ADMIN ==> role:asset:OWNER role:asset:OWNER ==> role:asset:ADMIN -role:bookingItem:AGENT ==> role:asset:ADMIN role:asset:ADMIN ==> role:asset:AGENT +role:asset:AGENT ==> role:assignedToAsset:TENANT role:asset:AGENT ==> role:asset:TENANT -role:asset:TENANT ==> role:bookingItem:TENANT +role:assignedToAsset:TENANT ==> role:asset:TENANT %% granting permissions to roles role:global:ADMIN ==> perm:asset:INSERT -role:bookingItem:AGENT ==> perm:asset:INSERT role:asset:OWNER ==> perm:asset:DELETE role:asset:ADMIN ==> perm:asset:UPDATE -role:asset:TENANT ==> perm:asset:SELECT ``` diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql index ae6c51c7..f14430a7 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7013-hs-hosting-asset-rbac.sql @@ -31,6 +31,7 @@ create or replace procedure buildRbacSystemForHsHostingAsset( declare newBookingItem hs_booking_item; + newAssignedToAsset hs_hosting_asset; newParentAsset hs_hosting_asset; begin @@ -38,6 +39,8 @@ begin SELECT * FROM hs_booking_item WHERE uuid = NEW.bookingItemUuid INTO newBookingItem; + SELECT * FROM hs_hosting_asset WHERE uuid = NEW.assignedToAssetUuid INTO newAssignedToAsset; + SELECT * FROM hs_hosting_asset WHERE uuid = NEW.parentAssetUuid INTO newParentAsset; perform createRoleWithGrants( @@ -59,13 +62,15 @@ begin perform createRoleWithGrants( hsHostingAssetAGENT(NEW), - incomingSuperRoles => array[hsHostingAssetADMIN(NEW)] + incomingSuperRoles => array[hsHostingAssetADMIN(NEW)], + outgoingSubRoles => array[hsHostingAssetTENANT(newAssignedToAsset)] ); perform createRoleWithGrants( hsHostingAssetTENANT(NEW), - permissions => array['SELECT'], - incomingSuperRoles => array[hsHostingAssetAGENT(NEW)], + incomingSuperRoles => array[ + hsHostingAssetAGENT(NEW), + hsHostingAssetTENANT(newAssignedToAsset)], outgoingSubRoles => array[ hsBookingItemTENANT(newBookingItem), hsHostingAssetTENANT(newParentAsset)] @@ -197,11 +202,11 @@ create or replace function new_hs_hosting_asset_grants_insert_to_hs_hosting_asse language plpgsql strict as $$ begin - if NEW.type = 'MANAGED_SERVER' then + -- unconditional for all rows in that table call grantPermissionToRole( createPermission(NEW.uuid, 'INSERT', 'hs_hosting_asset'), hsHostingAssetADMIN(NEW)); - end if; + -- end. return NEW; end; $$; diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql index 737b691a..964acdec 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql @@ -16,7 +16,11 @@ declare relatedDebitor hs_office_debitor; relatedPrivateCloudBookingItem hs_booking_item; relatedManagedServerBookingItem hs_booking_item; + debitorNumberSuffix varchar; + defaultPrefix varchar; managedServerUuid uuid; + managedWebspaceUuid uuid; + webUnixUserUuid uuid; begin currentTask := 'creating hosting-asset test-data ' || givenProjectCaption; call defineContext(currentTask, null, 'superuser-alex@hostsharing.net', 'global#global:ADMIN'); @@ -45,12 +49,18 @@ begin assert relatedManagedServerBookingItem.uuid is not null, 'relatedManagedServerBookingItem for "' || givenProjectCaption|| '" must not be null'; select uuid_generate_v4() into managedServerUuid; + select uuid_generate_v4() into managedWebspaceUuid; + select uuid_generate_v4() into webUnixUserUuid; + debitorNumberSuffix := relatedDebitor.debitorNumberSuffix; + defaultPrefix := relatedDebitor.defaultPrefix; insert into hs_hosting_asset - (uuid, bookingitemuuid, type, parentAssetUuid, identifier, caption, config) - values (managedServerUuid, relatedPrivateCloudBookingItem.uuid, 'MANAGED_SERVER', null, 'vm10' || relatedDebitor.debitorNumberSuffix, 'some ManagedServer', '{ "CPU": 2, "SDD": 512, "extra": 42 }'::jsonb), - (uuid_generate_v4(), relatedPrivateCloudBookingItem.uuid, 'CLOUD_SERVER', null, 'vm20' || relatedDebitor.debitorNumberSuffix, 'another CloudServer', '{ "CPU": 2, "HDD": 1024, "extra": 42 }'::jsonb), - (uuid_generate_v4(), relatedManagedServerBookingItem.uuid, 'MANAGED_WEBSPACE', managedServerUuid, relatedDebitor.defaultPrefix || '01', 'some Webspace', '{ "RAM": 1, "SDD": 512, "HDD": 2048, "extra": 42 }'::jsonb); + (uuid, bookingitemuuid, type, parentAssetUuid, assignedToAssetUuid, identifier, caption, config) + values (managedServerUuid, relatedPrivateCloudBookingItem.uuid, 'MANAGED_SERVER', null, null, 'vm10' || debitorNumberSuffix, 'some ManagedServer', '{ "extra": 42 }'::jsonb), + (uuid_generate_v4(), relatedPrivateCloudBookingItem.uuid, 'CLOUD_SERVER', null, null, 'vm20' || debitorNumberSuffix, 'another CloudServer', '{ "extra": 42 }'::jsonb), + (managedWebspaceUuid, relatedManagedServerBookingItem.uuid, 'MANAGED_WEBSPACE', managedServerUuid, null, defaultPrefix || '01', 'some Webspace', '{ "extra": 42 }'::jsonb), + (webUnixUserUuid, null, 'UNIX_USER', managedWebspaceUuid, null, defaultPrefix || '01-web', 'some UnixUser for Website', '{ "SSD-soft-quota": "128", "SSD-hard-quota": "256", "HDD-soft-quota": "512", "HDD-hard-quota": "1024", "extra": 42 }'::jsonb), + (uuid_generate_v4(), null, 'DOMAIN_HTTP_SETUP', managedWebspaceUuid, webUnixUserUuid, defaultPrefix || '.example.org', 'some Domain-HTTP-Setup', '{ "option-htdocsfallback": true, "use-fcgiphpbin": "/usr/lib/cgi-bin/php", "validsubdomainnames": "*", "extra": 42 }'::jsonb); end; $$; --// diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemControllerAcceptanceTest.java index 7f385824..bd3959c9 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemControllerAcceptanceTest.java @@ -180,9 +180,8 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup @Test void globalAdmin_canGetArbitraryBookingItem() { context.define("superuser-alex@hostsharing.net"); - final var givenBookingItemUuid = bookingItemRepo.findAll().stream() + final var givenBookingItemUuid = bookingItemRepo.findByCaption("some ManagedWebspace").stream() .filter(bi -> belongsToDebitorNumber(bi, 1000111)) - .filter(item -> item.getCaption().equals("some ManagedWebspace")) .findAny().orElseThrow().getUuid(); RestAssured // @formatter:off @@ -213,7 +212,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup @Test void normalUser_canNotGetUnrelatedBookingItem() { context.define("superuser-alex@hostsharing.net"); - final var givenBookingItemUuid = bookingItemRepo.findAll().stream() + final var givenBookingItemUuid = bookingItemRepo.findByCaption("separate ManagedServer").stream() .filter(bi -> belongsToDebitorNumber(bi, 1000212)) .map(HsBookingItemEntity::getUuid) .findAny().orElseThrow(); @@ -231,9 +230,8 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup @Test void debitorAgentUser_canGetRelatedBookingItem() { context.define("superuser-alex@hostsharing.net"); - final var givenBookingItemUuid = bookingItemRepo.findAll().stream() + final var givenBookingItemUuid = bookingItemRepo.findByCaption("separate ManagedServer").stream() .filter(bi -> belongsToDebitorNumber(bi, 1000313)) - .filter(item -> item.getCaption().equals("separate ManagedServer")) .findAny().orElseThrow().getUuid(); RestAssured // @formatter:off diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRepositoryIntegrationTest.java index f4ac6fee..6ca6a60a 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemRepositoryIntegrationTest.java @@ -326,8 +326,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup private HsBookingItemEntity givenSomeTemporaryBookingItem(final String projectCaption) { return jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); - final var givenProject = projectRepo.findAll().stream() - .filter(p -> p.getCaption().equals(projectCaption)) + final var givenProject = projectRepo.findByCaption(projectCaption).stream() .findAny().orElseThrow(); final var newBookingItem = HsBookingItemEntity.builder() .project(givenProject) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectControllerAcceptanceTest.java index 31bd8ba0..8a81312e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/project/HsBookingProjectControllerAcceptanceTest.java @@ -128,8 +128,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean @Test void globalAdmin_canGetArbitraryBookingProject() { context.define("superuser-alex@hostsharing.net"); - final var givenBookingProjectUuid = bookingProjectRepo.findAll().stream() - .filter(project -> project.getDebitor().getDebitorNumber() == 1000111) + final var givenBookingProjectUuid = bookingProjectRepo.findByCaption("D-1000111 default project").stream() .findAny().orElseThrow().getUuid(); RestAssured // @formatter:off @@ -151,8 +150,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean @Test void normalUser_canNotGetUnrelatedBookingProject() { context.define("superuser-alex@hostsharing.net"); - final var givenBookingProjectUuid = bookingProjectRepo.findAll().stream() - .filter(project -> project.getDebitor().getDebitorNumber() == 1000212) + final var givenBookingProjectUuid = bookingProjectRepo.findByCaption("D-1000212 default project").stream() .map(HsBookingProjectEntity::getUuid) .findAny().orElseThrow(); @@ -169,8 +167,7 @@ class HsBookingProjectControllerAcceptanceTest extends ContextBasedTestWithClean @Test void debitorAgentUser_canGetRelatedBookingProject() { context.define("superuser-alex@hostsharing.net"); - final var givenBookingProjectUuid = bookingProjectRepo.findAll().stream() - .filter(project -> project.getDebitor().getDebitorNumber() == 1000313) + final var givenBookingProjectUuid = bookingProjectRepo.findByCaption("D-1000313 default project").stream() .findAny().orElseThrow().getUuid(); RestAssured // @formatter:off diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java index d11e7278..b02edb04 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerAcceptanceTest.java @@ -5,7 +5,6 @@ import io.restassured.http.ContentType; import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRepository; -import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRepository; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; @@ -21,8 +20,6 @@ import java.util.Map; import java.util.UUID; import static java.util.Map.entry; -import static java.util.Optional.ofNullable; -import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.CLOUD_SERVER; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_SERVER; import static net.hostsharing.hsadminng.rbac.test.JsonMatcher.lenientlyEquals; import static org.assertj.core.api.Assertions.assertThat; @@ -61,8 +58,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup // given context("superuser-alex@hostsharing.net"); - final var givenProject = projectRepo.findAll().stream() - .filter(p -> p.getCaption().equals("D-1000111 default project")) + final var givenProject = projectRepo.findByCaption("D-1000111 default project").stream() .findAny().orElseThrow(); RestAssured // @formatter:off @@ -81,9 +77,6 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup "identifier": "sec01", "caption": "some Webspace", "config": { - "HDD": 2048, - "RAM": 1, - "SDD": 512, "extra": 42 } }, @@ -92,9 +85,6 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup "identifier": "fir01", "caption": "some Webspace", "config": { - "HDD": 2048, - "RAM": 1, - "SDD": 512, "extra": 42 } }, @@ -103,9 +93,6 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup "identifier": "thi01", "caption": "some Webspace", "config": { - "HDD": 2048, - "RAM": 1, - "SDD": 512, "extra": 42 } } @@ -136,18 +123,6 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup "identifier": "vm1011", "caption": "some ManagedServer", "config": { - "CPU": 2, - "SDD": 512, - "extra": 42 - } - }, - { - "type": "MANAGED_SERVER", - "identifier": "vm1013", - "caption": "some ManagedServer", - "config": { - "CPU": 2, - "SDD": 512, "extra": 42 } }, @@ -156,8 +131,14 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup "identifier": "vm1012", "caption": "some ManagedServer", "config": { - "CPU": 2, - "SDD": 512, + "extra": 42 + } + }, + { + "type": "MANAGED_SERVER", + "identifier": "vm1013", + "caption": "some ManagedServer", + "config": { "extra": 42 } } @@ -186,7 +167,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup "type": "MANAGED_SERVER", "identifier": "vm1400", "caption": "some new ManagedServer", - "config": { "CPUs": 2, "RAM": 100, "SSD": 300, "Traffic": 250 } + "config": { "monit_max_ssd_usage": 80, "monit_max_cpu_usage": 90, "monit_max_ram_usage": 70 } } """.formatted(givenBookingItem.getUuid())) .port(port) @@ -200,7 +181,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup "type": "MANAGED_SERVER", "identifier": "vm1400", "caption": "some new ManagedServer", - "config": { "CPUs": 2, "RAM": 100, "SSD": 300, "Traffic": 250 } + "config": { "monit_max_ssd_usage": 80, "monit_max_cpu_usage": 90, "monit_max_ram_usage": 70 } } """)) .header("Location", matchesRegex("http://localhost:[1-9][0-9]*/api/hs/hosting/assets/[^/]*")) @@ -216,7 +197,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup void parentAssetAgent_canAddSubAsset() { context.define("superuser-alex@hostsharing.net"); - final var givenParentAsset = givenParentAsset("D-1000111 default project", MANAGED_SERVER); + final var givenParentAsset = givenParentAsset(MANAGED_SERVER, "vm1011"); context.define("person-FirbySusan@example.com"); @@ -231,7 +212,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup "type": "MANAGED_WEBSPACE", "identifier": "fir90", "caption": "some new ManagedWebspace in client's ManagedServer", - "config": { "SSD": 100, "Traffic": 250 } + "config": {} } """.formatted(givenParentAsset.getUuid())) .port(port) @@ -245,7 +226,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup "type": "MANAGED_WEBSPACE", "identifier": "fir90", "caption": "some new ManagedWebspace in client's ManagedServer", - "config": { "SSD": 100, "Traffic": 250 } + "config": {} } """)) .header("Location", matchesRegex("http://localhost:[1-9][0-9]*/api/hs/hosting/assets/[^/]*")) @@ -263,7 +244,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup context.define("superuser-alex@hostsharing.net"); final var givenBookingItem = givenBookingItem("D-1000111 default project", "some PrivateCloud"); - final var location = RestAssured // @formatter:off + RestAssured // @formatter:off .given() .header("current-user", "superuser-alex@hostsharing.net") .contentType(ContentType.JSON) @@ -273,7 +254,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup "type": "MANAGED_SERVER", "identifier": "vm1400", "caption": "some new ManagedServer", - "config": { "CPUs": 0, "extra": 42 } + "config": { "monit_max_ssd_usage": 0, "monit_max_cpu_usage": 101, "extra": 42 } } """.formatted(givenBookingItem.getUuid())) .port(port) @@ -285,7 +266,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup .body("", lenientlyEquals(""" { "statusPhrase": "Bad Request", - "message": "['config.extra' is not expected but is set to '42', 'config.CPUs' is expected to be >= 1 but is 0, 'config.RAM' is required but missing, 'config.SSD' is required but missing, 'config.Traffic' is required but missing]" + "message": "['config.extra' is not expected but is set to '42', 'config.monit_max_ssd_usage' is expected to be >= 10 but is 0, 'config.monit_max_cpu_usage' is expected to be <= 100 but is 101, 'config.monit_max_ram_usage' is required but missing]" } """)); // @formatter:on } @@ -297,7 +278,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup @Test void globalAdmin_canGetArbitraryAsset() { context.define("superuser-alex@hostsharing.net"); - final var givenAssetUuid = assetRepo.findAll().stream() + final var givenAssetUuid = assetRepo.findByIdentifier("vm1011").stream() .filter(bi -> bi.getBookingItem().getProject().getDebitor().getDebitorNumber() == 1000111) .filter(item -> item.getCaption().equals("some ManagedServer")) .findAny().orElseThrow().getUuid(); @@ -315,8 +296,6 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup { "caption": "some ManagedServer", "config": { - "CPU": 2, - "SDD": 512, "extra": 42 } } @@ -326,7 +305,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup @Test void normalUser_canNotGetUnrelatedAsset() { context.define("superuser-alex@hostsharing.net"); - final var givenAssetUuid = assetRepo.findAll().stream() + final var givenAssetUuid = assetRepo.findByIdentifier("vm1012").stream() .filter(bi -> bi.getBookingItem().getProject().getDebitor().getDebitorNumber() == 1000212) .map(HsHostingAssetEntity::getUuid) .findAny().orElseThrow(); @@ -344,7 +323,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup @Test void debitorAgentUser_canGetRelatedAsset() { context.define("superuser-alex@hostsharing.net"); - final var givenAssetUuid = assetRepo.findAll().stream() + final var givenAssetUuid = assetRepo.findByIdentifier("vm1013").stream() .filter(bi -> bi.getBookingItem().getProject().getDebitor().getDebitorNumber() == 1000313) .filter(bi -> bi.getCaption().equals("some ManagedServer")) .findAny().orElseThrow().getUuid(); @@ -363,8 +342,6 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup "identifier": "vm1013", "caption": "some ManagedServer", "config": { - "CPU": 2, - "SDD": 512, "extra": 42 } } @@ -378,8 +355,8 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup @Test void globalAdmin_canPatchAllUpdatablePropertiesOfAsset() { - final var givenAsset = givenSomeTemporaryHostingAsset("2001", CLOUD_SERVER, - config("CPUs", 4), config("RAM", 100), config("HDD", 100), config("Traffic", 2000)); + final var givenAsset = givenSomeTemporaryHostingAsset("2001", MANAGED_SERVER, + config("monit_max_ssd_usage", 80), config("monit_max_hdd_usage", 90), config("monit_max_cpu_usage", 90), config("monit_max_ram_usage", 70)); RestAssured // @formatter:off .given() @@ -388,9 +365,9 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup .body(""" { "config": { - "CPUs": 2, - "HDD": null, - "SSD": 250 + "monit_max_ssd_usage": 85, + "monit_max_hdd_usage": null, + "monit_min_free_ssd": 5 } } """) @@ -402,13 +379,14 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup .contentType(ContentType.JSON) .body("", lenientlyEquals(""" { - "type": "CLOUD_SERVER", + "type": "MANAGED_SERVER", "identifier": "vm2001", "caption": "some test-asset", "config": { - "CPUs": 2, - "RAM": 100, - "SSD": 250 + "monit_max_cpu_usage": 90, + "monit_max_ram_usage": 70, + "monit_max_ssd_usage": 85, + "monit_min_free_ssd": 5 } } """)); // @formatter:on @@ -417,7 +395,8 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup context.define("superuser-alex@hostsharing.net"); assertThat(assetRepo.findByUuid(givenAsset.getUuid())).isPresent().get() .matches(asset -> { - assertThat(asset.toString()).isEqualTo("HsHostingAssetEntity(CLOUD_SERVER, vm2001, some test-asset, D-1000111:D-1000111 default project:test CloudServer, { CPUs: 2, RAM: 100, SSD: 250, Traffic: 2000 })"); + assertThat(asset.toString()).isEqualTo( + "HsHostingAssetEntity(MANAGED_SERVER, vm2001, some test-asset, D-1000111:D-1000111 default project:some ManagedServer, { monit_max_cpu_usage: 90, monit_max_ram_usage: 70, monit_max_ssd_usage: 85, monit_min_free_ssd: 5 })"); return true; }); } @@ -429,7 +408,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup @Test void globalAdmin_canDeleteArbitraryAsset() { context.define("superuser-alex@hostsharing.net"); - final var givenAsset = givenSomeTemporaryHostingAsset("2002", CLOUD_SERVER, + final var givenAsset = givenSomeTemporaryHostingAsset("2002", MANAGED_SERVER, config("CPUs", 4), config("RAM", 100), config("HDD", 100), config("Traffic", 2000)); RestAssured // @formatter:off @@ -448,7 +427,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup @Test void normalUser_canNotDeleteUnrelatedAsset() { context.define("superuser-alex@hostsharing.net"); - final var givenAsset = givenSomeTemporaryHostingAsset("2003", CLOUD_SERVER, + final var givenAsset = givenSomeTemporaryHostingAsset("2003", MANAGED_SERVER, config("CPUs", 4), config("RAM", 100), config("HDD", 100), config("Traffic", 2000)); RestAssured // @formatter:off @@ -466,22 +445,14 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup } HsBookingItemEntity givenBookingItem(final String projectCaption, final String bookingItemCaption) { - return bookingItemRepo.findAll().stream() - .filter(a -> ofNullable(a) - .filter(bi -> bi.getCaption().equals(bookingItemCaption)) - .isPresent()) + return bookingItemRepo.findByCaption(bookingItemCaption).stream() + .filter(bi -> bi.getRelatedProject().getCaption().contains(projectCaption)) .findAny().orElseThrow(); } - HsHostingAssetEntity givenParentAsset(final String projectCaption, final HsHostingAssetType assetType) { - final var givenAsset = assetRepo.findAll().stream() + HsHostingAssetEntity givenParentAsset(final HsHostingAssetType assetType, final String assetIdentifier) { + final var givenAsset = assetRepo.findByIdentifier(assetIdentifier).stream() .filter(a -> a.getType() == assetType) - .filter(a -> ofNullable(a) - .map(HsHostingAssetEntity::getBookingItem) - .map(HsBookingItemEntity::getProject) - .map(HsBookingProjectEntity::getCaption) - .filter(c -> c.equals(projectCaption)) - .isPresent()) .findAny().orElseThrow(); return givenAsset; } @@ -494,7 +465,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup context.define("superuser-alex@hostsharing.net"); final var newAsset = HsHostingAssetEntity.builder() .uuid(UUID.randomUUID()) - .bookingItem(givenBookingItem("D-1000111 default project", "test CloudServer")) + .bookingItem(givenBookingItem("D-1000111 default project", "some ManagedServer")) .type(hostingAssetType) .identifier("vm" + identifierSuffix) .caption("some test-asset") 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 d87d14f0..e9d47068 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 @@ -20,7 +20,7 @@ class HsHostingAssetEntityUnitTest { entry("SSD-storage", 512), entry("HDD-storage", 2048))) .build(); - final HsHostingAssetEntity givenServer = HsHostingAssetEntity.builder() + final HsHostingAssetEntity givenWebspace = HsHostingAssetEntity.builder() .bookingItem(TEST_BOOKING_ITEM) .type(HsHostingAssetType.MANAGED_WEBSPACE) .parentAsset(givenParentAsset) @@ -31,19 +31,47 @@ class HsHostingAssetEntityUnitTest { entry("SSD-storage", 512), entry("HDD-storage", 2048))) .build(); + final HsHostingAssetEntity givenUnixUser = HsHostingAssetEntity.builder() + .type(HsHostingAssetType.UNIX_USER) + .parentAsset(givenWebspace) + .identifier("xyz00-web") + .caption("some unix-user") + .config(Map.ofEntries( + entry("SSD-soft-quota", 128), + entry("SSD-hard-quota", 256), + entry("HDD-soft-quota", 256), + entry("HDD-hard-quota", 512))) + .build(); + final HsHostingAssetEntity givenDomainHttpSetup = HsHostingAssetEntity.builder() + .type(HsHostingAssetType.DOMAIN_HTTP_SETUP) + .parentAsset(givenWebspace) + .identifier("example.org") + .assignedToAsset(givenUnixUser) + .caption("some domain setup") + .config(Map.ofEntries( + entry("option-htdocsfallback", true), + entry("use-fcgiphpbin", "/usr/lib/cgi-bin/php"), + entry("validsubdomainnames", "*"))) + .build(); @Test void toStringContainsAllPropertiesAndResourcesSortedByKey() { - final var result = givenServer.toString(); - assertThat(result).isEqualTo( + assertThat(givenWebspace.toString()).isEqualTo( "HsHostingAssetEntity(MANAGED_WEBSPACE, xyz00, some managed webspace, MANAGED_SERVER:vm1234, D-1000100:test project:test 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 })"); + + assertThat(givenDomainHttpSetup.toString()).isEqualTo( + "HsHostingAssetEntity(DOMAIN_HTTP_SETUP, example.org, some domain setup, MANAGED_WEBSPACE:xyz00, UNIX_USER:xyz00-web, { option-htdocsfallback: true, use-fcgiphpbin: /usr/lib/cgi-bin/php, validsubdomainnames: * })"); } @Test void toShortStringContainsOnlyMemberNumberAndCaption() { - final var result = givenServer.toShortString(); - assertThat(result).isEqualTo("MANAGED_WEBSPACE:xyz00"); + assertThat(givenWebspace.toShortString()).isEqualTo("MANAGED_WEBSPACE:xyz00"); + assertThat(givenUnixUser.toShortString()).isEqualTo("UNIX_USER:xyz00-web"); + assertThat(givenDomainHttpSetup.toShortString()).isEqualTo("DOMAIN_HTTP_SETUP:example.org"); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java index e6cc9acd..55c2e29e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java @@ -54,48 +54,57 @@ class HsHostingAssetPropsControllerAcceptanceTest { [ { "type": "integer", - "propertyName": "CPUs", - "required": true, + "propertyName": "monit_min_free_ssd", + "required": false, "unit": null, "min": 1, - "max": 32, - "step": null - }, - { - "type": "integer", - "propertyName": "RAM", - "required": true, - "unit": "GB", - "min": 1, - "max": 128, - "step": null - }, - { - "type": "integer", - "propertyName": "SSD", - "required": true, - "unit": "GB", - "min": 25, "max": 1000, - "step": 25 + "step": null }, { "type": "integer", - "propertyName": "HDD", + "propertyName": "monit_min_free_hdd", "required": false, - "unit": "GB", - "min": 0, + "unit": null, + "min": 1, "max": 4000, - "step": 250 + "step": null }, { "type": "integer", - "propertyName": "Traffic", + "propertyName": "monit_max_ssd_usage", "required": true, - "unit": "GB", - "min": 250, - "max": 10000, - "step": 250 + "unit": "%", + "min": 10, + "max": 100, + "step": null + }, + { + "type": "integer", + "propertyName": "monit_max_hdd_usage", + "required": false, + "unit": "%", + "min": 10, + "max": 100, + "step": null + }, + { + "type": "integer", + "propertyName": "monit_max_cpu_usage", + "required": true, + "unit": "%", + "min": 10, + "max": 100, + "step": null + }, + { + "type": "integer", + "propertyName": "monit_max_ram_usage", + "required": true, + "unit": "%", + "min": 10, + "max": 100, + "step": null } ] """)); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java index e5408b4f..9260f54b 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java @@ -169,17 +169,16 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // then allTheseServersAreReturned( result, - "HsHostingAssetEntity(MANAGED_WEBSPACE, sec01, some Webspace, MANAGED_SERVER:vm1012, D-1000212:D-1000212 default project:separate ManagedServer, { HDD: 2048, RAM: 1, SDD: 512, extra: 42 })", - "HsHostingAssetEntity(MANAGED_WEBSPACE, thi01, some Webspace, MANAGED_SERVER:vm1013, D-1000313:D-1000313 default project:separate ManagedServer, { HDD: 2048, RAM: 1, SDD: 512, extra: 42 })", - "HsHostingAssetEntity(MANAGED_WEBSPACE, fir01, some Webspace, MANAGED_SERVER:vm1011, D-1000111:D-1000111 default project:separate ManagedServer, { HDD: 2048, RAM: 1, SDD: 512, extra: 42 })"); + "HsHostingAssetEntity(MANAGED_WEBSPACE, sec01, some Webspace, MANAGED_SERVER:vm1012, D-1000212:D-1000212 default project:separate ManagedServer, { extra: 42 })", + "HsHostingAssetEntity(MANAGED_WEBSPACE, thi01, some Webspace, MANAGED_SERVER:vm1013, D-1000313:D-1000313 default project:separate ManagedServer, { extra: 42 })", + "HsHostingAssetEntity(MANAGED_WEBSPACE, fir01, some Webspace, MANAGED_SERVER:vm1011, D-1000111:D-1000111 default project:separate ManagedServer, { extra: 42 })"); } @Test public void normalUser_canViewOnlyRelatedAsset() { // given: context("person-FirbySusan@example.com"); - final var projectUuid = projectRepo.findAll().stream() - .filter(p -> p.getCaption().equals("D-1000111 default project")) + final var projectUuid = projectRepo.findByCaption("D-1000111 default project").stream() .findAny().orElseThrow().getUuid(); // when: @@ -188,9 +187,9 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // then: exactlyTheseAssetsAreReturned( result, - "HsHostingAssetEntity(MANAGED_WEBSPACE, fir01, some Webspace, MANAGED_SERVER:vm1011, D-1000111:D-1000111 default project:separate ManagedServer, { HDD: 2048, RAM: 1, SDD: 512, extra: 42 })", - "HsHostingAssetEntity(MANAGED_SERVER, vm1011, some ManagedServer, D-1000111:D-1000111 default project:some PrivateCloud, { CPU: 2, SDD: 512, extra: 42 })", - "HsHostingAssetEntity(CLOUD_SERVER, vm2011, another CloudServer, D-1000111:D-1000111 default project:some PrivateCloud, { CPU: 2, HDD: 1024, extra: 42 })"); + "HsHostingAssetEntity(MANAGED_WEBSPACE, fir01, some Webspace, MANAGED_SERVER:vm1011, D-1000111:D-1000111 default project:separate ManagedServer, { extra: 42 })", + "HsHostingAssetEntity(MANAGED_SERVER, vm1011, some ManagedServer, D-1000111:D-1000111 default project:some PrivateCloud, { extra: 42 })", + "HsHostingAssetEntity(CLOUD_SERVER, vm2011, another CloudServer, D-1000111:D-1000111 default project:some PrivateCloud, { extra: 42 })"); } @Test @@ -206,7 +205,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // then allTheseServersAreReturned( result, - "HsHostingAssetEntity(MANAGED_WEBSPACE, thi01, some Webspace, MANAGED_SERVER:vm1013, D-1000313:D-1000313 default project:separate ManagedServer, { HDD: 2048, RAM: 1, SDD: 512, extra: 42 })"); + "HsHostingAssetEntity(MANAGED_WEBSPACE, thi01, some Webspace, MANAGED_SERVER:vm1013, D-1000313:D-1000313 default project:separate ManagedServer, { extra: 42 })"); } } @@ -373,8 +372,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu } HsBookingItemEntity givenBookingItem(final String projectCaption, final String bookingItemCaption) { - final var givenProject = projectRepo.findAll().stream() - .filter(p -> p.getCaption().equals(projectCaption)) + final var givenProject = projectRepo.findByCaption(projectCaption).stream() .findAny().orElseThrow(); return bookingItemRepo.findAllByProjectUuid(givenProject.getUuid()).stream() .filter(i -> i.getCaption().equals(bookingItemCaption)) @@ -382,8 +380,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu } HsHostingAssetEntity givenManagedServer(final String projectCaption, final HsHostingAssetType type) { - final var givenProject = projectRepo.findAll().stream() - .filter(p -> p.getCaption().equals(projectCaption)) + final var givenProject = projectRepo.findByCaption(projectCaption).stream() .findAny().orElseThrow(); return assetRepo.findAllByCriteria(givenProject.getUuid(), null, type).stream() .findAny().orElseThrow();