From 23c45c0bd886d9e5f9b6edfed6de2c0ee53f8277 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 15 Aug 2024 09:07:16 +0200 Subject: [PATCH] properly split up HsHostingAssetEntity into HsHostingAssetReal+RbacEntity extending HsHostingAsset --- .../hs/booking/item/HsBookingItemEntity.java | 4 +- .../hs/hosting/asset/HsHostingAsset.java | 123 +++++++++++++++--- .../asset/HsHostingAssetController.java | 25 ++-- .../asset/HsHostingAssetEntityPatcher.java | 4 +- ...ity.java => HsHostingAssetRbacEntity.java} | 109 +--------------- ...java => HsHostingAssetRbacRepository.java} | 12 +- .../asset/HsHostingAssetRealEntity.java | 24 ++++ .../asset/HsHostingAssetRealRepository.java | 46 +++++++ .../hs/hosting/asset/HsHostingAssetType.java | 6 +- .../hsadminng/arch/ArchitectureTest.java | 21 ++- ...gedServerBookingItemValidatorUnitTest.java | 26 ++-- ...sHostingAssetControllerAcceptanceTest.java | 72 +++++----- .../HsHostingAssetControllerRestTest.java | 65 ++++----- .../HsHostingAssetEntityPatcherUnitTest.java | 18 +-- .../asset/HsHostingAssetEntityUnitTest.java | 14 +- ...ngAssetRbacRepositoryIntegrationTest.java} | 121 +++++++++-------- .../asset/HsHostingAssetTestEntities.java | 36 +++++ .../asset/TestHsHostingAssetEntities.java | 22 ---- ...udServerHostingAssetValidatorUnitTest.java | 15 ++- ...DnsSetupHostingAssetValidatorUnitTest.java | 16 +-- ...ttpSetupHostingAssetValidatorUnitTest.java | 14 +- ...mainMboxHostingAssetValidatorUnitTest.java | 14 +- ...ainSetupHostingAssetValidatorUnitTest.java | 12 +- ...mtpSetupHostingAssetValidatorUnitTest.java | 15 ++- ...lAddressHostingAssetValidatorUnitTest.java | 17 +-- ...ailAliasHostingAssetValidatorUnitTest.java | 28 ++-- ...v4NumberHostingAssetValidatorUnitTest.java | 14 +- ...v6NumberHostingAssetValidatorUnitTest.java | 14 +- ...edServerHostingAssetValidatorUnitTest.java | 17 +-- ...WebspaceHostingAssetValidatorUnitTest.java | 19 +-- ...DatabaseHostingAssetValidatorUnitTest.java | 20 +-- ...InstanceHostingAssetValidatorUnitTest.java | 18 +-- ...iaDbUserHostingAssetValidatorUnitTest.java | 18 +-- ...DatabaseHostingAssetValidatorUnitTest.java | 24 ++-- ...InstanceHostingAssetValidatorUnitTest.java | 18 +-- ...eSqlUserHostingAssetValidatorUnitTest.java | 18 +-- ...UnixUserHostingAssetValidatorUnitTest.java | 27 ++-- .../migration/HsHostingAssetRealEntity.java | 114 ---------------- .../hs/migration/ImportHostingAssets.java | 1 + 39 files changed, 598 insertions(+), 603 deletions(-) rename src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/{HsHostingAssetEntity.java => HsHostingAssetRbacEntity.java} (62%) rename src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/{HsHostingAssetRepository.java => HsHostingAssetRbacRepository.java} (70%) create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealEntity.java create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealRepository.java rename src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/{HsHostingAssetRepositoryIntegrationTest.java => HsHostingAssetRbacRepositoryIntegrationTest.java} (77%) create mode 100644 src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTestEntities.java delete mode 100644 src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/TestHsHostingAssetEntities.java delete mode 100644 src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetRealEntity.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 81c87e03..957ba171 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 @@ -10,7 +10,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; @@ -120,7 +120,7 @@ public class HsBookingItemEntity implements Stringifyable, BaseEntity subBookingItems; @OneToOne(mappedBy="bookingItem") - private HsHostingAssetEntity relatedHostingAsset; + private HsHostingAssetRbacEntity relatedHostingAsset; @Transient private PatchableMapWrapper resourcesWrapper; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java index 81b09512..efcba66f 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAsset.java @@ -1,13 +1,39 @@ package net.hostsharing.hsadminng.hs.hosting.asset; +import io.hypersistence.utils.hibernate.type.json.JsonType; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.Getter; +import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity; import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; +import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import net.hostsharing.hsadminng.stringify.Stringify; import net.hostsharing.hsadminng.stringify.Stringifyable; +import org.hibernate.annotations.Type; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.MappedSuperclass; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; +import jakarta.persistence.PostLoad; +import jakarta.persistence.Transient; +import jakarta.persistence.Version; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -16,9 +42,15 @@ import java.util.UUID; import static java.util.Collections.emptyMap; import static net.hostsharing.hsadminng.stringify.Stringify.stringify; -public interface HsHostingAsset extends Stringifyable, BaseEntity, PropertiesProvider { +@MappedSuperclass +@Getter +@Setter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PROTECTED) +@SuperBuilder(builderMethodName = "baseBuilder", toBuilder = true) +public class HsHostingAsset implements Stringifyable, BaseEntity, PropertiesProvider { - Stringify stringify = stringify(HsHostingAsset.class) + static Stringify stringify = stringify(HsHostingAsset.class) .withProp(HsHostingAsset::getType) .withProp(HsHostingAsset::getIdentifier) .withProp(HsHostingAsset::getCaption) @@ -28,20 +60,74 @@ public interface HsHostingAsset extends Stringifyable, BaseEntity getSubHostingAssets(); - String getCaption(); - Map getConfig(); + @Version + private int version; - default HsBookingProjectEntity getRelatedProject() { + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "bookingitemuuid") + private HsBookingItemEntity bookingItem; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "parentassetuuid") + private HsHostingAssetRealEntity parentAsset; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "assignedtoassetuuid") + private HsHostingAssetRealEntity assignedToAsset; + + @Column(name = "type") + @Enumerated(EnumType.STRING) + private HsHostingAssetType type; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "alarmcontactuuid") + private HsOfficeContactRealEntity alarmContact; + + @OneToMany(cascade = CascadeType.REFRESH, orphanRemoval = true, fetch = FetchType.LAZY) + @JoinColumn(name = "parentassetuuid", referencedColumnName = "uuid") + private List subHostingAssets; + + @Column(name = "identifier") + private String identifier; // e.g. vm1234, xyz00, example.org, xyz00_abc + + @Column(name = "caption") + private String caption; + + @Builder.Default + @Setter(AccessLevel.NONE) + @Type(JsonType.class) + @Column(columnDefinition = "config") + private Map config = new HashMap<>(); + + @Transient + private PatchableMapWrapper configWrapper; + + @Transient + private boolean isLoaded; + + @PostLoad + public void markAsLoaded() { + this.isLoaded = true; + } + + public PatchableMapWrapper getConfig() { + return PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper;}, config); + } + + public void putConfig(Map newConfig) { + PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper;}, config).assign(newConfig); + } + + @Override + public PatchableMapWrapper directProps() { + return getConfig(); + } + + public HsBookingProjectEntity getRelatedProject() { return Optional.ofNullable(getBookingItem()) .map(HsBookingItemEntity::getRelatedProject) .orElseGet(() -> Optional.ofNullable(getParentAsset()) @@ -50,7 +136,7 @@ public interface HsHostingAsset extends Stringifyable, BaseEntity mapper.map(e, HsHostingAssetResource.class)) .revampProperties(); @@ -98,7 +101,7 @@ public class HsHostingAssetController implements HsHostingAssetsApi { context.define(currentUser, assumedRoles); - final var result = assetRepo.findByUuid(assetUuid); + final var result = assetRbacRepo.findByUuid(assetUuid); return result .map(assetEntity -> ResponseEntity.ok( mapper.map(assetEntity, HsHostingAssetResource.class, ENTITY_TO_RESOURCE_POSTMAPPER))) @@ -113,7 +116,7 @@ public class HsHostingAssetController implements HsHostingAssetsApi { final UUID assetUuid) { context.define(currentUser, assumedRoles); - final var result = assetRepo.deleteByUuid(assetUuid); + final var result = assetRbacRepo.deleteByUuid(assetUuid); return result == 0 ? ResponseEntity.notFound().build() : ResponseEntity.noContent().build(); @@ -129,7 +132,7 @@ public class HsHostingAssetController implements HsHostingAssetsApi { context.define(currentUser, assumedRoles); - final var entity = assetRepo.findByUuid(assetUuid).orElseThrow(); + final var entity = assetRbacRepo.findByUuid(assetUuid).orElseThrow(); new HsHostingAssetEntityPatcher(em, entity).apply(body); @@ -137,7 +140,7 @@ public class HsHostingAssetController implements HsHostingAssetsApi { .preprocessEntity() .validateEntity() .prepareForSave() - .saveUsing(assetRepo::save) + .saveUsing(assetRbacRepo::save) .validateContext() .mapUsing(e -> mapper.map(e, HsHostingAssetResource.class)) .revampProperties(); @@ -145,7 +148,7 @@ public class HsHostingAssetController implements HsHostingAssetsApi { return ResponseEntity.ok(mapped); } - final BiConsumer RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> { + final BiConsumer RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> { entity.putConfig(KeyValueMap.from(resource.getConfig())); if (resource.getBookingItemUuid() != null) { entity.setBookingItem(bookingItemRepo.findByUuid(resource.getBookingItemUuid()) @@ -153,14 +156,14 @@ public class HsHostingAssetController implements HsHostingAssetsApi { resource.getBookingItemUuid())))); } if (resource.getParentAssetUuid() != null) { - entity.setParentAsset(assetRepo.findByUuid(resource.getParentAssetUuid()) + entity.setParentAsset(assetRealRepo.findByUuid(resource.getParentAssetUuid()) .orElseThrow(() -> new EntityNotFoundException("ERROR: [400] parentAssetUuid %s not found".formatted( resource.getParentAssetUuid())))); } }; @SuppressWarnings("unchecked") - final BiConsumer ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) + final BiConsumer ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> resource.setConfig(HostingAssetEntityValidatorRegistry.forType(entity.getType()) .revampProperties(em, entity, (Map) resource.getConfig())); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcher.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcher.java index c16c22e0..5296a955 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcher.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcher.java @@ -12,9 +12,9 @@ import java.util.Optional; public class HsHostingAssetEntityPatcher implements EntityPatcher { private final EntityManager em; - private final HsHostingAssetEntity entity; + private final HsHostingAssetRbacEntity entity; - public HsHostingAssetEntityPatcher(final EntityManager em, final HsHostingAssetEntity entity) { + public HsHostingAssetEntityPatcher(final EntityManager em, final HsHostingAssetRbacEntity entity) { this.em = em; this.entity = entity; } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacEntity.java similarity index 62% rename from src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java rename to src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacEntity.java index 2ae4ae70..18b68c62 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacEntity.java @@ -1,41 +1,17 @@ package net.hostsharing.hsadminng.hs.hosting.asset; -import io.hypersistence.utils.hibernate.type.json.JsonType; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.experimental.SuperBuilder; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity; import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; -import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView; import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL; -import org.hibernate.annotations.Type; -import jakarta.persistence.CascadeType; -import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; -import jakarta.persistence.PostLoad; import jakarta.persistence.Table; -import jakarta.persistence.Transient; -import jakarta.persistence.Version; import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.CaseDef.inCaseOf; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Column.dependsOnColumn; @@ -56,89 +32,16 @@ import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.Role.TENANT; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL.directlyFetchedByDependsOnColumn; import static net.hostsharing.hsadminng.rbac.rbacdef.RbacView.rbacViewFor; -@Builder @Entity @Table(name = "hs_hosting_asset_rv") +@SuperBuilder(toBuilder = true) @Getter @Setter @NoArgsConstructor -@AllArgsConstructor -public class HsHostingAssetEntity implements HsHostingAsset { - - @Id - @GeneratedValue - private UUID uuid; - - @Version - private int version; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "bookingitemuuid") - private HsBookingItemEntity bookingItem; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "parentassetuuid") - private HsHostingAssetEntity parentAsset; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "assignedtoassetuuid") - private HsHostingAssetEntity assignedToAsset; - - @Column(name = "type") - @Enumerated(EnumType.STRING) - private HsHostingAssetType type; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "alarmcontactuuid") - private HsOfficeContactRealEntity alarmContact; - - @OneToMany(cascade = CascadeType.REFRESH, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "parentassetuuid", referencedColumnName = "uuid") - private List subHostingAssets; - - @Column(name = "identifier") - private String identifier; // e.g. vm1234, xyz00, example.org, xyz00_abc - - @Column(name = "caption") - private String caption; - - @Builder.Default - @Setter(AccessLevel.NONE) - @Type(JsonType.class) - @Column(columnDefinition = "config") - private Map config = new HashMap<>(); - - @Transient - private PatchableMapWrapper configWrapper; - - @Transient - private boolean isLoaded; - - @PostLoad - public void markAsLoaded() { - this.isLoaded = true; - } - - public PatchableMapWrapper getConfig() { - return PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper;}, config); - } - - public void putConfig(Map newConfig) { - PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper;}, config).assign(newConfig); - } - - @Override - public PatchableMapWrapper directProps() { - return getConfig(); - } - - @Override - public String toString() { - return stringify.using(HsHostingAssetEntity.class).apply(this); - } +public class HsHostingAssetRbacEntity extends HsHostingAsset { public static RbacView rbac() { - return rbacViewFor("asset", HsHostingAssetEntity.class) + return rbacViewFor("asset", HsHostingAssetRbacEntity.class) .withIdentityView(SQL.projection("identifier")) .withRestrictedViewOrderBy(SQL.expression("identifier")) .withUpdatableColumns("version", "caption", "config", "assignedToAssetUuid", "alarmContactUuid") @@ -149,13 +52,13 @@ public class HsHostingAssetEntity implements HsHostingAsset { directlyFetchedByDependsOnColumn(), NULLABLE) - .importEntityAlias("parentAsset", HsHostingAssetEntity.class, usingDefaultCase(), + .importEntityAlias("parentAsset", HsHostingAssetRbacEntity.class, usingDefaultCase(), dependsOnColumn("parentAssetUuid"), directlyFetchedByDependsOnColumn(), NULLABLE) .toRole("parentAsset", ADMIN).grantPermission(INSERT) - .importEntityAlias("assignedToAsset", HsHostingAssetEntity.class, usingDefaultCase(), + .importEntityAlias("assignedToAsset", HsHostingAssetRbacEntity.class, usingDefaultCase(), dependsOnColumn("assignedToAssetUuid"), directlyFetchedByDependsOnColumn(), NULLABLE) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacRepository.java similarity index 70% rename from src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepository.java rename to src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacRepository.java index 2b2c4452..af9908cc 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacRepository.java @@ -8,11 +8,11 @@ import java.util.Optional; import java.util.UUID; -public interface HsHostingAssetRepository extends Repository { +public interface HsHostingAssetRbacRepository extends Repository { - Optional findByUuid(final UUID serverUuid); + Optional findByUuid(final UUID serverUuid); - List findByIdentifier(String assetIdentifier); + List findByIdentifier(String assetIdentifier); @Query(value = """ select ha.uuid, @@ -34,12 +34,12 @@ public interface HsHostingAssetRepository extends Repository findAllByCriteriaImpl(UUID projectUuid, UUID parentAssetUuid, String type); - default List findAllByCriteria(final UUID projectUuid, final UUID parentAssetUuid, final HsHostingAssetType type) { + List findAllByCriteriaImpl(UUID projectUuid, UUID parentAssetUuid, String type); + default List findAllByCriteria(final UUID projectUuid, final UUID parentAssetUuid, final HsHostingAssetType type) { return findAllByCriteriaImpl(projectUuid, parentAssetUuid, HsHostingAssetType.asString(type)); } - HsHostingAssetEntity save(HsHostingAsset current); + HsHostingAssetRbacEntity save(HsHostingAsset current); int deleteByUuid(final UUID uuid); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealEntity.java new file mode 100644 index 00000000..a586f245 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealEntity.java @@ -0,0 +1,24 @@ +package net.hostsharing.hsadminng.hs.hosting.asset; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.experimental.SuperBuilder; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; + +@Entity +@Table(name = "hs_hosting_asset") +@SuperBuilder(builderMethodName = "genericBuilder", toBuilder = true) +@Getter +@Setter +@NoArgsConstructor +public class HsHostingAssetRealEntity extends HsHostingAsset { + + // without this wrapper method, the builder returns a generic entity which cannot resolved in a generic context + public static HsHostingAssetRealEntityBuilder builder() { + //noinspection unchecked + return (HsHostingAssetRealEntityBuilder) genericBuilder(); + } +} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealRepository.java new file mode 100644 index 00000000..2b40c96a --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRealRepository.java @@ -0,0 +1,46 @@ +package net.hostsharing.hsadminng.hs.hosting.asset; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.Repository; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +public interface HsHostingAssetRealRepository extends Repository { + + Optional findByUuid(final UUID serverUuid); + + List findByIdentifier(String assetIdentifier); + + @Query(value = """ + select ha.uuid, + ha.alarmcontactuuid, + ha.assignedtoassetuuid, + ha.bookingitemuuid, + ha.caption, + ha.config, + ha.identifier, + ha.parentassetuuid, + ha.type, + ha.version + from hs_hosting_asset_rv ha + left join hs_booking_item bi on bi.uuid = ha.bookingitemuuid + left join hs_hosting_asset pha on pha.uuid = ha.parentassetuuid + where (:projectUuid is null or bi.projectuuid=:projectUuid) + and (:parentAssetUuid is null or pha.uuid=:parentAssetUuid) + and (:type is null or :type=cast(ha.type as text)) + """, nativeQuery = true) + // The JPQL query did not generate "left join" but just "join". + // I also optimized the query by not using the _rv for hs_booking_item and hs_hosting_asset, only for hs_hosting_asset_rv. + List findAllByCriteriaImpl(UUID projectUuid, UUID parentAssetUuid, String type); + default List findAllByCriteria(final UUID projectUuid, final UUID parentAssetUuid, final HsHostingAssetType type) { + return findAllByCriteriaImpl(projectUuid, parentAssetUuid, HsHostingAssetType.asString(type)); + } + + HsHostingAssetRealEntity save(HsHostingAsset current); + + int deleteByUuid(final UUID uuid); + + long count(); +} 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 e11b1430..9b8e1403 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 @@ -354,14 +354,14 @@ class EntityTypeRelation { final HsHostingAssetType.RelationPolicy relationPolicy; final HsHostingAssetType.RelationType relationType; - final Function getter; + final Function getter; private final List acceptedRelatedTypes; final String edge; private EntityTypeRelation( final HsHostingAssetType.RelationPolicy relationPolicy, final HsHostingAssetType.RelationType relationType, - final Function getter, + final Function getter, final T acceptedRelatedType, final String edge ) { @@ -380,7 +380,7 @@ class EntityTypeRelation { return new EntityTypeRelation<>( REQUIRED, BOOKING_ITEM, - HsHostingAssetEntity::getBookingItem, + HsHostingAssetRbacEntity::getBookingItem, bookingItemType, " *==> "); } diff --git a/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java b/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java index 49071496..8bc7aad0 100644 --- a/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java +++ b/src/test/java/net/hostsharing/hsadminng/arch/ArchitectureTest.java @@ -1,6 +1,9 @@ package net.hostsharing.hsadminng.arch; +import com.tngtech.archunit.base.DescribedPredicate; import com.tngtech.archunit.core.domain.JavaClass; +import com.tngtech.archunit.core.domain.JavaMethod; +import com.tngtech.archunit.core.domain.JavaModifier; import com.tngtech.archunit.junit.AnalyzeClasses; import com.tngtech.archunit.junit.ArchTest; import com.tngtech.archunit.lang.ArchCondition; @@ -9,10 +12,9 @@ import com.tngtech.archunit.lang.ConditionEvents; import com.tngtech.archunit.lang.SimpleConditionEvent; import net.hostsharing.hsadminng.HsadminNgApplication; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; import net.hostsharing.hsadminng.rbac.context.ContextBasedTest; import net.hostsharing.hsadminng.rbac.rbacgrant.RbacGrantsDiagramService; -import net.hostsharing.hsadminng.rbac.rbacobject.BaseEntity; import org.springframework.data.repository.Repository; import org.springframework.web.bind.annotation.RestController; @@ -329,7 +331,7 @@ public class ArchitectureTest { RbacGrantsDiagramService.class) .ignoreDependency( HsBookingItemEntity.class, - HsHostingAssetEntity.class); + HsHostingAssetRbacEntity.class); @ArchTest @@ -347,10 +349,21 @@ public class ArchitectureTest { static final ArchRule tableNamesOfRbacEntitiesShouldEndWith_rv = classes() .that().areAnnotatedWith(Table.class) - .and().areAssignableTo(BaseEntity.class) + .and().containAnyMethodsThat(hasStaticMethodNamed("rbac")) + // .and().haveNameNotMatching(".*RealEntity") TODO.test: check rules for RealEntity vs. RbacEntity .should(haveTableNameEndingWith_rv()) .because("it's required that the table names of RBAC entities end with '_rv'"); + + private static DescribedPredicate hasStaticMethodNamed(final String expectedName) { + return new DescribedPredicate<>("rbac entity") { + @Override + public boolean test(final JavaMethod method) { + return method.getModifiers().contains(JavaModifier.STATIC) && method.getName().equals(expectedName); + } + }; + } + static ArchCondition haveTableNameEndingWith_rv() { return new ArchCondition<>("RBAC table name end with _rv") { diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsManagedServerBookingItemValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsManagedServerBookingItemValidatorUnitTest.java index ab54f050..bef65f82 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsManagedServerBookingItemValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsManagedServerBookingItemValidatorUnitTest.java @@ -3,7 +3,8 @@ package net.hostsharing.hsadminng.hs.booking.item.validators; import net.hostsharing.hsadminng.hs.booking.debitor.HsBookingDebitorEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import org.junit.jupiter.api.Test; @@ -140,7 +141,7 @@ class HsManagedServerBookingItemValidatorUnitTest { entry("Traffic", 1000), entry("Multi", 1) )) - .relatedHostingAsset(HsHostingAssetEntity.builder() + .relatedHostingAsset(HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.MANAGED_WEBSPACE) .identifier("abc00") .subHostingAssets(concat( @@ -175,47 +176,48 @@ class HsManagedServerBookingItemValidatorUnitTest { } @SafeVarargs - private List concat(final List... hostingAssets) { + private List concat(final List... hostingAssets) { return stream(hostingAssets) .flatMap(Collection::stream) .collect(Collectors.toList()); } - private List generate(final int count, final HsHostingAssetType hostingAssetType, + private List generate(final int count, final HsHostingAssetType hostingAssetType, final String identifierPattern) { return IntStream.range(0, count) - .mapToObj(number -> HsHostingAssetEntity.builder() + .mapToObj(number -> (HsHostingAssetRealEntity) HsHostingAssetRealEntity.builder() .type(hostingAssetType) .identifier(identifierPattern.formatted((number/'a')+'a', (number%'a')+'a')) .build()) .toList(); } - private List generateDbUsersWithDatabases( + private List generateDbUsersWithDatabases( final int userCount, final HsHostingAssetType directAssetType, final String directAssetIdentifierFormat, final int dbCount, final HsHostingAssetType subAssetType) { - return IntStream.range(0, userCount) - .mapToObj(n -> HsHostingAssetEntity.builder() + final List list = IntStream.range(0, userCount) + .mapToObj(n -> HsHostingAssetRealEntity.builder() .type(directAssetType) - .identifier(directAssetIdentifierFormat.formatted((n/'a')+'a', (n%'a')+'a')) + .identifier(directAssetIdentifierFormat.formatted((n / 'a') + 'a', (n % 'a') + 'a')) .subHostingAssets( - generate(dbCount, subAssetType, "%c%c.example.com".formatted((n/'a')+'a', (n%'a')+'a')) + generate(dbCount, subAssetType, "%c%c.example.com" .formatted((n / 'a') + 'a', (n % 'a') + 'a')) ) .build()) .toList(); + return list; } - private List generateDomainEmailSetupsWithEMailAddresses( + private List generateDomainEmailSetupsWithEMailAddresses( final int domainCount, final HsHostingAssetType directAssetType, final String directAssetIdentifierFormat, final int emailAddressCount, final HsHostingAssetType subAssetType) { return IntStream.range(0, domainCount) - .mapToObj(n -> HsHostingAssetEntity.builder() + .mapToObj(n -> HsHostingAssetRealEntity.builder() .type(directAssetType) .identifier(directAssetIdentifierFormat.formatted((n/'a')+'a', (n%'a')+'a')) .subHostingAssets( 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 0fcb35b4..0b582272 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 @@ -8,8 +8,8 @@ import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRepository; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRepository; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacEntity; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRbacRepository; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity; +import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealRepository; import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorRepository; import net.hostsharing.hsadminng.rbac.test.ContextBasedTestWithCleanup; import net.hostsharing.hsadminng.rbac.test.JpaAttempt; @@ -50,7 +50,10 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup private Integer port; @Autowired - HsHostingAssetRepository assetRepo; + HsHostingAssetRealRepository realAssetRepo; + + @Autowired + HsHostingAssetRbacRepository rbacAssetRepo; @Autowired HsBookingItemRepository bookingItemRepo; @@ -62,7 +65,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup HsOfficeDebitorRepository debitorRepo; @Autowired - HsOfficeContactRbacRepository contactRepo; + HsOfficeContactRealRepository realContactRepo; @Autowired JpaAttempt jpaAttempt; @@ -189,13 +192,12 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup final var newWebspace = UUID.fromString( location.substring(location.lastIndexOf('/') + 1)); assertThat(newWebspace).isNotNull(); - toCleanup(HsHostingAssetEntity.class, newWebspace); + toCleanup(HsHostingAssetRbacEntity.class, newWebspace); } @Test void parentAssetAgent_canAddSubAsset() { - context.define("superuser-alex@hostsharing.net"); final var givenParentAsset = givenParentAsset(MANAGED_WEBSPACE, "fir01"); final var location = RestAssured // @formatter:off @@ -273,7 +275,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup final var newWebspace = UUID.fromString( location.substring(location.lastIndexOf('/') + 1)); assertThat(newWebspace).isNotNull(); - toCleanup(HsHostingAssetEntity.class, newWebspace); + toCleanup(HsHostingAssetRbacEntity.class, newWebspace); } @Test @@ -320,18 +322,18 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup void totalsLimitValidationsArePerformend_whenAddingAsset() { context.define("superuser-alex@hostsharing.net"); - final var givenHostingAsset = givenHostingAsset(MANAGED_WEBSPACE, "fir01"); + final var givenHostingAsset = givenRealHostingAsset(MANAGED_WEBSPACE, "fir01"); assertThat(givenHostingAsset.getBookingItem().getResources().get("Multi")) .as("precondition failed") .isEqualTo(1); - final var preExistingUnixUserCount = assetRepo.findAllByCriteria(null, givenHostingAsset.getUuid(), UNIX_USER).size(); + final var preExistingUnixUserCount = realAssetRepo.findAllByCriteria(null, givenHostingAsset.getUuid(), UNIX_USER).size(); final var UNIX_USER_PER_MULTI_OPTION = 25; jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net"); for (int n = 0; n < UNIX_USER_PER_MULTI_OPTION -preExistingUnixUserCount+1; ++n) { - toCleanup(assetRepo.save( - HsHostingAssetEntity.builder() + toCleanup(realAssetRepo.save( + HsHostingAssetRealEntity.builder() .type(UNIX_USER) .parentAsset(givenHostingAsset) .identifier("fir01-%2d".formatted(n)) @@ -375,7 +377,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup @Test void globalAdmin_canGetArbitraryAsset() { context.define("superuser-alex@hostsharing.net"); - final var givenAssetUuid = assetRepo.findByIdentifier("vm1011").stream() + final var givenAssetUuid = realAssetRepo.findByIdentifier("vm1011").stream() .filter(bi -> bi.getBookingItem().getProject().getCaption().equals("D-1000111 default project")) .findAny().orElseThrow().getUuid(); @@ -399,9 +401,9 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup @Test void normalUser_canNotGetUnrelatedAsset() { context.define("superuser-alex@hostsharing.net"); - final var givenAssetUuid = assetRepo.findByIdentifier("vm1012").stream() + final var givenAssetUuid = realAssetRepo.findByIdentifier("vm1012").stream() .filter(bi -> bi.getBookingItem().getProject().getCaption().equals("D-1000212 default project")) - .map(HsHostingAssetEntity::getUuid) + .map(HsHostingAssetRealEntity::getUuid) .findAny().orElseThrow(); RestAssured // @formatter:off @@ -417,7 +419,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup @Test void projectAgentUser_canGetRelatedAsset() { context.define("superuser-alex@hostsharing.net"); - final var givenAssetUuid = assetRepo.findByIdentifier("vm1013").stream() + final var givenAssetUuid = realAssetRepo.findByIdentifier("vm1013").stream() .filter(bi -> bi.getBookingItem().getProject().getCaption().equals("D-1000313 default project")) .findAny().orElseThrow().getUuid(); @@ -449,7 +451,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup void globalAdmin_canPatchAllUpdatablePropertiesOfAsset() { final var givenAsset = givenSomeTemporaryHostingAsset(() -> - HsHostingAssetEntity.builder() + HsHostingAssetRealEntity.builder() .uuid(UUID.randomUUID()) .bookingItem(givenSomeNewBookingItem( "D-1000111 default project", @@ -510,8 +512,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup // finally, the asset is actually updated em.clear(); - context.define("superuser-alex@hostsharing.net"); - assertThat(assetRepo.findByUuid(givenAsset.getUuid())).isPresent().get() + assertThat(realAssetRepo.findByUuid(givenAsset.getUuid())).isPresent().get() .matches(asset -> { assertThat(asset.getAlarmContact()).isNotNull() .extracting(c -> c.getEmailAddresses().get("main")) @@ -533,10 +534,10 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup void assetAdmin_canPatchAllUpdatablePropertiesOfAsset() { final var givenAsset = givenSomeTemporaryHostingAsset(() -> - HsHostingAssetEntity.builder() + HsHostingAssetRealEntity.builder() .uuid(UUID.randomUUID()) .type(UNIX_USER) - .parentAsset(givenHostingAsset(MANAGED_WEBSPACE, "fir01")) + .parentAsset(givenRealHostingAsset(MANAGED_WEBSPACE, "fir01")) .identifier("fir01-temp") .caption("some test-unix-user") .build()); @@ -586,8 +587,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup // finally, the asset is actually updated assertThat(jpaAttempt.transacted(() -> { - context.define("superuser-alex@hostsharing.net"); - return assetRepo.findByUuid(givenAsset.getUuid()); + return realAssetRepo.findByUuid(givenAsset.getUuid()); }).returnedValue()).isPresent().get() .matches(asset -> { assertThat(asset.getCaption()).isEqualTo("some patched test-unix-user"); @@ -611,7 +611,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup void globalAdmin_canDeleteArbitraryAsset() { context.define("superuser-alex@hostsharing.net"); final var givenAsset = givenSomeTemporaryHostingAsset(() -> - HsHostingAssetEntity.builder() + HsHostingAssetRealEntity.builder() .uuid(UUID.randomUUID()) .bookingItem(givenSomeNewBookingItem( "D-1000111 default project", @@ -637,14 +637,14 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup .statusCode(204); // @formatter:on // then the given assets is gone - assertThat(assetRepo.findByUuid(givenAsset.getUuid())).isEmpty(); + assertThat(realAssetRepo.findByUuid(givenAsset.getUuid())).isEmpty(); } @Test void normalUser_canNotDeleteUnrelatedAsset() { context.define("superuser-alex@hostsharing.net"); final var givenAsset = givenSomeTemporaryHostingAsset(() -> - HsHostingAssetEntity.builder() + HsHostingAssetRealEntity.builder() .uuid(UUID.randomUUID()) .bookingItem(givenSomeNewBookingItem( "D-1000111 default project", @@ -670,12 +670,12 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup .statusCode(404); // @formatter:on // then the given asset is still there - assertThat(assetRepo.findByUuid(givenAsset.getUuid())).isNotEmpty(); + assertThat(realAssetRepo.findByUuid(givenAsset.getUuid())).isNotEmpty(); } } - HsHostingAssetEntity givenHostingAsset(final HsHostingAssetType type, final String identifier) { - return assetRepo.findByIdentifier(identifier).stream() + HsHostingAssetRealEntity givenRealHostingAsset(final HsHostingAssetType type, final String identifier) { + return realAssetRepo.findByIdentifier(identifier).stream() .filter(ha -> ha.getType() == type) .findAny().orElseThrow(); } @@ -721,24 +721,24 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup }).assertSuccessful().returnedValue(); } - HsHostingAssetEntity givenParentAsset(final HsHostingAssetType assetType, final String assetIdentifier) { - final var givenAsset = assetRepo.findByIdentifier(assetIdentifier).stream() + HsHostingAssetRealEntity givenParentAsset(final HsHostingAssetType assetType, final String assetIdentifier) { + final var givenAsset = realAssetRepo.findByIdentifier(assetIdentifier).stream() .filter(a -> a.getType() == assetType) .findAny().orElseThrow(); return givenAsset; } - private HsHostingAssetEntity givenSomeTemporaryHostingAsset(final Supplier newAsset) { + private HsHostingAssetRealEntity givenSomeTemporaryHostingAsset(final Supplier newAsset) { return jpaAttempt.transacted(() -> { - context.define("superuser-alex@hostsharing.net"); - return toCleanup(assetRepo.save(newAsset.get())); + context.define("superuser-alex@hostsharing.net"); // needed to determine creator + return toCleanup(realAssetRepo.save(newAsset.get())); }).assertSuccessful().returnedValue(); } - private HsOfficeContactRbacEntity givenContact() { + private HsOfficeContactRealEntity givenContact() { return jpaAttempt.transacted(() -> { - context.define("superuser-alex@hostsharing.net"); - return contactRepo.findContactByOptionalCaptionLike("second").stream().findFirst().orElseThrow(); + context.define("superuser-alex@hostsharing.net"); // needed to determine creator + return realContactRepo.findContactByOptionalCaptionLike("second").stream().findFirst().orElseThrow(); }).returnedValue(); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java index 7a382edb..9bd6b123 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java @@ -30,8 +30,8 @@ import java.util.Map; import static java.util.Map.entry; import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_CLOUD_SERVER_BOOKING_ITEM; import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_SERVER_BOOKING_ITEM; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_WEBSPACE_HOSTING_ASSET; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY; import static net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealTestEntity.TEST_REAL_CONTACT; import static net.hostsharing.hsadminng.rbac.test.JsonMatcher.lenientlyEquals; import static org.assertj.core.api.Assertions.assertThat; @@ -65,12 +65,15 @@ public class HsHostingAssetControllerRestTest { private HsBookingItemRepository bookingItemRepo; @MockBean - private HsHostingAssetRepository hostingAssetRepo; + private HsHostingAssetRealRepository realAssetRepo; + + @MockBean + private HsHostingAssetRbacRepository rbacAssetRepo; enum ListTestCases { CLOUD_SERVER( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.CLOUD_SERVER) .bookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM) .identifier("vm1234") @@ -96,7 +99,7 @@ public class HsHostingAssetControllerRestTest { """), MANAGED_SERVER( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.MANAGED_SERVER) .bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM) .identifier("vm1234") @@ -131,9 +134,9 @@ public class HsHostingAssetControllerRestTest { """), UNIX_USER( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.UNIX_USER) - .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) + .parentAsset(MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("xyz00-office") .caption("some fake Unix-User") .config(Map.ofEntries( @@ -165,9 +168,9 @@ public class HsHostingAssetControllerRestTest { """), EMAIL_ALIAS( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.EMAIL_ALIAS) - .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) + .parentAsset(MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("xyz00-office") .caption("some fake EMail-Alias") .config(Map.ofEntries( @@ -189,7 +192,7 @@ public class HsHostingAssetControllerRestTest { """), DOMAIN_SETUP( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.DOMAIN_SETUP) .identifier("example.org") .caption("some fake Domain-Setup") @@ -207,7 +210,7 @@ public class HsHostingAssetControllerRestTest { """), DOMAIN_DNS_SETUP( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.DOMAIN_DNS_SETUP) .identifier("example.org") .caption("some fake Domain-DNS-Setup") @@ -250,7 +253,7 @@ public class HsHostingAssetControllerRestTest { """), DOMAIN_HTTP_SETUP( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.DOMAIN_HTTP_SETUP) .identifier("example.org|HTTP") .caption("some fake Domain-HTTP-Setup") @@ -303,7 +306,7 @@ public class HsHostingAssetControllerRestTest { """), DOMAIN_SMTP_SETUP( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.DOMAIN_SMTP_SETUP) .identifier("example.org|SMTP") .caption("some fake Domain-SMTP-Setup") @@ -321,7 +324,7 @@ public class HsHostingAssetControllerRestTest { """), DOMAIN_MBOX_SETUP( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.DOMAIN_MBOX_SETUP) .identifier("example.org|MBOX") .caption("some fake Domain-MBOX-Setup") @@ -339,9 +342,9 @@ public class HsHostingAssetControllerRestTest { """), EMAIL_ADDRESS( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.EMAIL_ADDRESS) - .parentAsset(HsHostingAssetEntity.builder() + .parentAsset(HsHostingAssetRealEntity.builder() .type(HsHostingAssetType.DOMAIN_MBOX_SETUP) .identifier("example.org|MBOX") .caption("some fake Domain-MBOX-Setup") @@ -367,9 +370,9 @@ public class HsHostingAssetControllerRestTest { """), MARIADB_INSTANCE( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.MARIADB_INSTANCE) - .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) + .parentAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("vm1234|MariaDB.default") .caption("some fake MariaDB instance") .build()), @@ -386,7 +389,7 @@ public class HsHostingAssetControllerRestTest { """), MARIADB_USER( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.MARIADB_USER) .identifier("xyz00_temp") .caption("some fake MariaDB user") @@ -404,7 +407,7 @@ public class HsHostingAssetControllerRestTest { """), MARIADB_DATABASE( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.MARIADB_DATABASE) .identifier("xyz00_temp") .caption("some fake MariaDB database") @@ -429,9 +432,9 @@ public class HsHostingAssetControllerRestTest { """), PGSQL_INSTANCE( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.PGSQL_INSTANCE) - .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) + .parentAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("vm1234|PgSql.default") .caption("some fake PgSql instance") .build()), @@ -448,7 +451,7 @@ public class HsHostingAssetControllerRestTest { """), PGSQL_USER( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.PGSQL_USER) .identifier("xyz00_temp") .caption("some fake PgSql user") @@ -466,7 +469,7 @@ public class HsHostingAssetControllerRestTest { """), PGSQL_DATABASE( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.PGSQL_DATABASE) .identifier("xyz00_temp") .caption("some fake PgSql database") @@ -491,9 +494,9 @@ public class HsHostingAssetControllerRestTest { """), IPV4_NUMBER( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.IPV4_NUMBER) - .assignedToAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) + .assignedToAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("11.12.13.14") .caption("some fake IPv4 number") .build()), @@ -510,9 +513,9 @@ public class HsHostingAssetControllerRestTest { """), IPV6_NUMBER( List.of( - HsHostingAssetEntity.builder() + HsHostingAssetRbacEntity.builder() .type(HsHostingAssetType.IPV6_NUMBER) - .assignedToAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) + .assignedToAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("2001:db8:3333:4444:5555:6666:7777:8888") .caption("some fake IPv6 number") .build()), @@ -529,13 +532,13 @@ public class HsHostingAssetControllerRestTest { """); final HsHostingAssetType assetType; - final List givenHostingAssetsOfType; + final List givenHostingAssetsOfType; final String expectedResponse; final JsonNode expectedResponseJson; @SneakyThrows ListTestCases( - final List givenHostingAssetsOfType, + final List givenHostingAssetsOfType, final String expectedResponse) { this.assetType = HsHostingAssetType.valueOf(name()); this.givenHostingAssetsOfType = givenHostingAssetsOfType; @@ -561,7 +564,7 @@ public class HsHostingAssetControllerRestTest { @EnumSource(HsHostingAssetControllerRestTest.ListTestCases.class) void shouldListAssets(final HsHostingAssetControllerRestTest.ListTestCases testCase) throws Exception { // given - when(hostingAssetRepo.findAllByCriteria(null, null, testCase.assetType)) + when(rbacAssetRepo.findAllByCriteria(null, null, testCase.assetType)) .thenReturn(testCase.givenHostingAssetsOfType); // when diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcherUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcherUnitTest.java index f9e4c568..2768cbbc 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcherUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetEntityPatcherUnitTest.java @@ -27,7 +27,7 @@ import static org.mockito.Mockito.lenient; @ExtendWith(MockitoExtension.class) class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase< HsHostingAssetPatchResource, - HsHostingAssetEntity + HsHostingAssetRbacEntity > { private static final UUID INITIAL_BOOKING_ITEM_UUID = UUID.randomUUID(); @@ -60,15 +60,15 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase< @BeforeEach void initMocks() { - lenient().when(em.getReference(eq(HsHostingAssetEntity.class), any())).thenAnswer(invocation -> - HsHostingAssetEntity.builder().uuid(invocation.getArgument(1)).build()); + lenient().when(em.getReference(eq(HsHostingAssetRbacEntity.class), any())).thenAnswer(invocation -> + HsHostingAssetRbacEntity.builder().uuid(invocation.getArgument(1)).build()); lenient().when(em.getReference(eq(HsOfficeContactRealEntity.class), any())).thenAnswer(invocation -> HsOfficeContactRealEntity.builder().uuid(invocation.getArgument(1)).build()); } @Override - protected HsHostingAssetEntity newInitialEntity() { - final var entity = new HsHostingAssetEntity(); + protected HsHostingAssetRbacEntity newInitialEntity() { + final var entity = new HsHostingAssetRbacEntity(); entity.setUuid(INITIAL_BOOKING_ITEM_UUID); entity.setBookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM); entity.getConfig().putAll(KeyValueMap.from(INITIAL_CONFIG)); @@ -83,7 +83,7 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase< } @Override - protected HsHostingAssetEntityPatcher createPatcher(final HsHostingAssetEntity server) { + protected HsHostingAssetEntityPatcher createPatcher(final HsHostingAssetRbacEntity server) { return new HsHostingAssetEntityPatcher(em, server); } @@ -94,19 +94,19 @@ class HsHostingAssetEntityPatcherUnitTest extends PatchUnitTestBase< "caption", HsHostingAssetPatchResource::setCaption, PATCHED_CAPTION, - HsHostingAssetEntity::setCaption), + HsHostingAssetRbacEntity::setCaption), new SimpleProperty<>( "config", HsHostingAssetPatchResource::setConfig, PATCH_CONFIG, - HsHostingAssetEntity::putConfig, + HsHostingAssetRbacEntity::putConfig, PATCHED_CONFIG) .notNullable(), new JsonNullableProperty<>( "alarmContact", HsHostingAssetPatchResource::setAlarmContactUuid, PATCHED_CONTACT_UUID, - HsHostingAssetEntity::setAlarmContact, + HsHostingAssetRbacEntity::setAlarmContact, newContact(PATCHED_CONTACT_UUID)) ); } 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 cbc5c67e..b5539292 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 @@ -10,7 +10,7 @@ import static org.assertj.core.api.Assertions.assertThat; class HsHostingAssetEntityUnitTest { - final HsHostingAssetEntity givenParentAsset = HsHostingAssetEntity.builder() + final HsHostingAssetRealEntity givenParentAsset = HsHostingAssetRealEntity.builder() .bookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM) .type(HsHostingAssetType.MANAGED_SERVER) .identifier("vm1234") @@ -20,7 +20,7 @@ class HsHostingAssetEntityUnitTest { entry("SSD-storage", 512), entry("HDD-storage", 2048))) .build(); - final HsHostingAssetEntity givenWebspace = HsHostingAssetEntity.builder() + final HsHostingAssetRealEntity givenWebspace = HsHostingAssetRealEntity.builder() .bookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM) .type(HsHostingAssetType.MANAGED_WEBSPACE) .parentAsset(givenParentAsset) @@ -31,7 +31,7 @@ class HsHostingAssetEntityUnitTest { entry("SSD-storage", 512), entry("HDD-storage", 2048))) .build(); - final HsHostingAssetEntity givenUnixUser = HsHostingAssetEntity.builder() + final HsHostingAssetRealEntity givenUnixUser = HsHostingAssetRealEntity.builder() .type(HsHostingAssetType.UNIX_USER) .parentAsset(givenWebspace) .identifier("xyz00-web") @@ -42,7 +42,7 @@ class HsHostingAssetEntityUnitTest { entry("HDD-soft-quota", 256), entry("HDD-hard-quota", 512))) .build(); - final HsHostingAssetEntity givenDomainHttpSetup = HsHostingAssetEntity.builder() + final HsHostingAssetRealEntity givenDomainHttpSetup = HsHostingAssetRealEntity.builder() .type(HsHostingAssetType.DOMAIN_HTTP_SETUP) .parentAsset(givenWebspace) .identifier("example.org") @@ -58,13 +58,13 @@ class HsHostingAssetEntityUnitTest { void toStringContainsAllPropertiesAndResourcesSortedByKey() { assertThat(givenWebspace.toString()).isEqualToIgnoringWhitespace( - "HsHostingAssetEntity(MANAGED_WEBSPACE, xyz00, some managed webspace, MANAGED_SERVER:vm1234, D-1234500:test project:test cloud server booking item, { \"CPU\": 2, \"HDD-storage\": 2048, \"SSD-storage\": 512 })"); + "HsHostingAsset(MANAGED_WEBSPACE, xyz00, some managed webspace, MANAGED_SERVER:vm1234, D-1234500:test project:test cloud server booking item, { \"CPU\": 2, \"HDD-storage\": 2048, \"SSD-storage\": 512 })"); assertThat(givenUnixUser.toString()).isEqualToIgnoringWhitespace( - "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 })"); + "HsHostingAsset(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()).isEqualToIgnoringWhitespace( - "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\": \"*\" })"); + "HsHostingAsset(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 diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacRepositoryIntegrationTest.java similarity index 77% rename from src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java rename to src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacRepositoryIntegrationTest.java index 682610de..fb963d55 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetRbacRepositoryIntegrationTest.java @@ -39,10 +39,13 @@ import static org.assertj.core.api.Assertions.assertThat; @DataJpaTest @Import({ Context.class, JpaAttempt.class }) -class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanup { +class HsHostingAssetRbacRepositoryIntegrationTest extends ContextBasedTestWithCleanup { @Autowired - HsHostingAssetRepository assetRepo; + HsHostingAssetRealRepository realAssetRepo; + + @Autowired + HsHostingAssetRbacRepository rbacAssetRepo; @Autowired HsBookingItemRepository bookingItemRepo; @@ -71,34 +74,35 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu @Test public void testHostsharingAdmin_withoutAssumedRole_canCreateNewAsset() { // given - context("superuser-alex@hostsharing.net"); - final var count = assetRepo.count(); + context("superuser-alex@hostsharing.net"); // TODO.test: remove context(...) once all entities have real entities + final var count = realAssetRepo.count(); final var givenManagedServer = givenHostingAsset("D-1000111 default project", MANAGED_SERVER); final var newWebspaceBookingItem = newBookingItem(givenManagedServer.getBookingItem(), HsBookingItemType.MANAGED_WEBSPACE, "fir01"); // when final var result = attempt(em, () -> { - final var newAsset = HsHostingAssetEntity.builder() + final var newAsset = HsHostingAssetRbacEntity.builder() .bookingItem(newWebspaceBookingItem) .parentAsset(givenManagedServer) .caption("some new managed webspace") .type(MANAGED_WEBSPACE) .identifier("xyz90") .build(); - return toCleanup(assetRepo.save(newAsset)); + return toCleanup(rbacAssetRepo.save(newAsset)); }); // then result.assertSuccessful(); - assertThat(result.returnedValue()).isNotNull().extracting(HsHostingAssetEntity::getUuid).isNotNull(); + assertThat(result.returnedValue()).isNotNull().extracting(HsHostingAssetRbacEntity::getUuid).isNotNull(); assertThatAssetIsPersisted(result.returnedValue()); assertThat(result.returnedValue().isLoaded()).isFalse(); - assertThat(assetRepo.count()).isEqualTo(count + 1); + assertThat(realAssetRepo.count()).isEqualTo(count + 1); } @Test public void createsAndGrantsRoles() { // given + // TODO.test: remove context(...) once all entities have real entities context("superuser-alex@hostsharing.net", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT"); final var givenManagedServer = givenHostingAsset("D-1000111 default project", MANAGED_SERVER); final var newWebspaceBookingItem = newBookingItem(givenManagedServer.getBookingItem(), HsBookingItemType.MANAGED_WEBSPACE, "fir01"); @@ -107,15 +111,16 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu final var initialGrantNames = distinctGrantDisplaysOf(rawGrantRepo.findAll()); // when + context("superuser-alex@hostsharing.net", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT"); final var result = attempt(em, () -> { - final var newAsset = HsHostingAssetEntity.builder() + final var newAsset = HsHostingAssetRbacEntity.builder() .bookingItem(newWebspaceBookingItem) .parentAsset(givenManagedServer) .type(HsHostingAssetType.MANAGED_WEBSPACE) .identifier("fir00") .caption("some new managed webspace") .build(); - return toCleanup(assetRepo.save(newAsset)); + return toCleanup(rbacAssetRepo.save(newAsset)); }); // then @@ -163,18 +168,18 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // when context("person-SmithPeter@example.com"); final var result = attempt(em, () -> { - final var newAsset = HsHostingAssetEntity.builder() + final var newAsset = HsHostingAssetRbacEntity.builder() .type(DOMAIN_SETUP) .identifier("example.net") .caption("some new domain setup") .build(); - return assetRepo.save(newAsset); + return rbacAssetRepo.save(newAsset); }); // then // ... the domain setup was created and returned result.assertSuccessful(); - assertThat(result.returnedValue()).isNotNull().extracting(HsHostingAssetEntity::getUuid).isNotNull(); + assertThat(result.returnedValue()).isNotNull().extracting(HsHostingAssetRbacEntity::getUuid).isNotNull(); assertThat(result.returnedValue().isLoaded()).isFalse(); // ... the creating user can read the new domain setup @@ -186,11 +191,11 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu assertThatAssetIsPersisted(result.returnedValue()); } - private void assertThatAssetIsPersisted(final HsHostingAssetEntity saved) { + private void assertThatAssetIsPersisted(final HsHostingAssetRbacEntity saved) { em.clear(); attempt(em, () -> { - final var found = assetRepo.findByUuid(saved.getUuid()); - assertThat(found).isNotEmpty().map(HsHostingAssetEntity::toString).contains(saved.toString()); + final var found = realAssetRepo.findByUuid(saved.getUuid()); + assertThat(found).isNotEmpty().map(HsHostingAsset::toString).contains(saved.toString()); }); } } @@ -204,14 +209,14 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu context("superuser-alex@hostsharing.net"); // when - final var result = assetRepo.findAllByCriteria(null, null, MANAGED_WEBSPACE); + final var result = rbacAssetRepo.findAllByCriteria(null, null, MANAGED_WEBSPACE); // then exactlyTheseAssetsAreReturned( result, - "HsHostingAssetEntity(MANAGED_WEBSPACE, sec01, some Webspace, MANAGED_SERVER:vm1012, D-1000212:D-1000212 default project:separate ManagedWebspace)", - "HsHostingAssetEntity(MANAGED_WEBSPACE, fir01, some Webspace, MANAGED_SERVER:vm1011, D-1000111:D-1000111 default project:separate ManagedWebspace)", - "HsHostingAssetEntity(MANAGED_WEBSPACE, thi01, some Webspace, MANAGED_SERVER:vm1013, D-1000313:D-1000313 default project:separate ManagedWebspace)"); + "HsHostingAsset(MANAGED_WEBSPACE, sec01, some Webspace, MANAGED_SERVER:vm1012, D-1000212:D-1000212 default project:separate ManagedWebspace)", + "HsHostingAsset(MANAGED_WEBSPACE, fir01, some Webspace, MANAGED_SERVER:vm1011, D-1000111:D-1000111 default project:separate ManagedWebspace)", + "HsHostingAsset(MANAGED_WEBSPACE, thi01, some Webspace, MANAGED_SERVER:vm1013, D-1000313:D-1000313 default project:separate ManagedWebspace)"); } @Test @@ -222,33 +227,32 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu .findAny().orElseThrow().getUuid(); // when: - final var result = assetRepo.findAllByCriteria(projectUuid, null, null); + final var result = rbacAssetRepo.findAllByCriteria(projectUuid, null, null); // then: exactlyTheseAssetsAreReturned( result, - "HsHostingAssetEntity(MANAGED_WEBSPACE, fir01, some Webspace, MANAGED_SERVER:vm1011, D-1000111:D-1000111 default project:separate ManagedWebspace)", - "HsHostingAssetEntity(MANAGED_SERVER, vm1011, some ManagedServer, D-1000111:D-1000111 default project:separate ManagedServer, { monit_max_cpu_usage : 90, monit_max_ram_usage : 80, monit_max_ssd_usage : 70 })"); + "HsHostingAsset(MANAGED_WEBSPACE, fir01, some Webspace, MANAGED_SERVER:vm1011, D-1000111:D-1000111 default project:separate ManagedWebspace)", + "HsHostingAsset(MANAGED_SERVER, vm1011, some ManagedServer, D-1000111:D-1000111 default project:separate ManagedServer, { monit_max_cpu_usage : 90, monit_max_ram_usage : 80, monit_max_ssd_usage : 70 })"); } @Test public void managedServerAgent_canFindAssetsRelatedToManagedServer() { // given - context("superuser-alex@hostsharing.net"); - final var parentAssetUuid = assetRepo.findByIdentifier("vm1012").stream() + final var parentAssetUuid = realAssetRepo.findByIdentifier("vm1012").stream() .filter(ha -> ha.getType() == MANAGED_SERVER) .findAny().orElseThrow().getUuid(); // when context("superuser-alex@hostsharing.net", "hs_hosting_asset#vm1012:AGENT"); - final var result = assetRepo.findAllByCriteria(null, parentAssetUuid, null); + final var result = rbacAssetRepo.findAllByCriteria(null, parentAssetUuid, null); // then exactlyTheseAssetsAreReturned( result, - "HsHostingAssetEntity(MANAGED_WEBSPACE, sec01, some Webspace, MANAGED_SERVER:vm1012, D-1000212:D-1000212 default project:separate ManagedWebspace)", - "HsHostingAssetEntity(MARIADB_INSTANCE, vm1012.MariaDB.default, some default MariaDB instance, MANAGED_SERVER:vm1012)", - "HsHostingAssetEntity(PGSQL_INSTANCE, vm1012.Postgresql.default, some default Postgresql instance, MANAGED_SERVER:vm1012)"); + "HsHostingAsset(MANAGED_WEBSPACE, sec01, some Webspace, MANAGED_SERVER:vm1012, D-1000212:D-1000212 default project:separate ManagedWebspace)", + "HsHostingAsset(MARIADB_INSTANCE, vm1012.MariaDB.default, some default MariaDB instance, MANAGED_SERVER:vm1012)", + "HsHostingAsset(PGSQL_INSTANCE, vm1012.Postgresql.default, some default Postgresql instance, MANAGED_SERVER:vm1012)"); } @Test @@ -258,12 +262,12 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // when context("superuser-alex@hostsharing.net", "hs_hosting_asset#sec01:AGENT"); - final var result = assetRepo.findAllByCriteria(null, null, EMAIL_ADDRESS); + final var result = rbacAssetRepo.findAllByCriteria(null, null, EMAIL_ADDRESS); // then exactlyTheseAssetsAreReturned( result, - "HsHostingAssetEntity(EMAIL_ADDRESS, test@sec.example.org, some E-Mail-Address, DOMAIN_MBOX_SETUP:sec.example.org|MBOX)"); + "HsHostingAsset(EMAIL_ADDRESS, test@sec.example.org, some E-Mail-Address, DOMAIN_MBOX_SETUP:sec.example.org|MBOX)"); } } @@ -278,25 +282,24 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // when final var result = jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); - final var foundAsset = em.find(HsHostingAssetEntity.class, givenAssetUuid); + final var foundAsset = em.find(HsHostingAssetRbacEntity.class, givenAssetUuid); foundAsset.getConfig().put("CPU", 2); foundAsset.getConfig().remove("SSD-storage"); foundAsset.getConfig().put("HSD-storage", 2048); - return toCleanup(assetRepo.save(foundAsset)); + return toCleanup(rbacAssetRepo.save(foundAsset)); }); // then result.assertSuccessful(); jpaAttempt.transacted(() -> { - context("superuser-alex@hostsharing.net"); assertThatAssetActuallyInDatabase(result.returnedValue()); }).assertSuccessful(); } - private void assertThatAssetActuallyInDatabase(final HsHostingAssetEntity saved) { - final var found = assetRepo.findByUuid(saved.getUuid()); + private void assertThatAssetActuallyInDatabase(final HsHostingAssetRbacEntity saved) { + final var found = realAssetRepo.findByUuid(saved.getUuid()); assertThat(found).isNotEmpty().get().isNotSameAs(saved) - .extracting(HsHostingAssetEntity::getVersion).isEqualTo(saved.getVersion()); + .extracting(HsHostingAsset::getVersion).isEqualTo(saved.getVersion()); } } @@ -312,51 +315,47 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // when final var result = jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); - assetRepo.deleteByUuid(givenAsset.getUuid()); + rbacAssetRepo.deleteByUuid(givenAsset.getUuid()); }); // then result.assertSuccessful(); assertThat(jpaAttempt.transacted(() -> { - context("superuser-fran@hostsharing.net", null); - return assetRepo.findByUuid(givenAsset.getUuid()); + return realAssetRepo.findByUuid(givenAsset.getUuid()); }).assertSuccessful().returnedValue()).isEmpty(); } @Test public void relatedOwner_canDeleteTheirRelatedAsset() { // given - context("superuser-alex@hostsharing.net", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT"); final var givenAsset = givenSomeTemporaryAsset("D-1000111 default project", "vm1000"); // when final var result = jpaAttempt.transacted(() -> { context("person-FirbySusan@example.com", "hs_booking_project#D-1000111-D-1000111defaultproject:AGENT"); - assertThat(assetRepo.findByUuid(givenAsset.getUuid())).isPresent(); + assertThat(rbacAssetRepo.findByUuid(givenAsset.getUuid())).isPresent(); - assetRepo.deleteByUuid(givenAsset.getUuid()); + rbacAssetRepo.deleteByUuid(givenAsset.getUuid()); }); // then result.assertSuccessful(); assertThat(jpaAttempt.transacted(() -> { - context("superuser-fran@hostsharing.net", null); - return assetRepo.findByUuid(givenAsset.getUuid()); + return realAssetRepo.findByUuid(givenAsset.getUuid()); }).assertSuccessful().returnedValue()).isEmpty(); } @Test public void relatedAdmin_canNotDeleteTheirRelatedAsset() { // given - context("superuser-alex@hostsharing.net", null); final var givenAsset = givenSomeTemporaryAsset("D-1000111 default project", "vm1000"); // when final var result = jpaAttempt.transacted(() -> { context("person-FirbySusan@example.com", "hs_hosting_asset#vm1000:ADMIN"); - assertThat(assetRepo.findByUuid(givenAsset.getUuid())).isPresent(); + assertThat(rbacAssetRepo.findByUuid(givenAsset.getUuid())).isPresent(); - assetRepo.deleteByUuid(givenAsset.getUuid()); + rbacAssetRepo.deleteByUuid(givenAsset.getUuid()); }); // then @@ -364,15 +363,13 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu JpaSystemException.class, "[403] Subject ", " is not allowed to delete hs_hosting_asset"); assertThat(jpaAttempt.transacted(() -> { - context("superuser-alex@hostsharing.net"); - return assetRepo.findByUuid(givenAsset.getUuid()); + return realAssetRepo.findByUuid(givenAsset.getUuid()); }).assertSuccessful().returnedValue()).isPresent(); // still there } @Test public void deletingAnAssetAlsoDeletesRelatedRolesAndGrants() { // given - context("superuser-alex@hostsharing.net"); final var initialRoleNames = Array.from(distinctRoleNamesOf(rawRoleRepo.findAll())); final var initialGrantNames = Array.from(distinctGrantDisplaysOf(rawGrantRepo.findAll())); final var givenAsset = givenSomeTemporaryAsset("D-1000111 default project", "vm1000"); @@ -380,7 +377,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu // when final var result = jpaAttempt.transacted(() -> { context("superuser-alex@hostsharing.net"); - return assetRepo.deleteByUuid(givenAsset.getUuid()); + return rbacAssetRepo.deleteByUuid(givenAsset.getUuid()); }); // then @@ -398,7 +395,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu select currentTask, targetTable, targetOp from tx_journal_v where targettable = 'hs_hosting_asset'; - """); + """); // when @SuppressWarnings("unchecked") final List customerLogEntries = query.getResultList(); @@ -410,21 +407,21 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu "[creating hosting-asset test-data D-1000313 default project, hs_hosting_asset, INSERT]"); } - private HsHostingAssetEntity givenSomeTemporaryAsset(final String projectCaption, final String identifier) { + private HsHostingAssetRealEntity givenSomeTemporaryAsset(final String projectCaption, final String identifier) { return jpaAttempt.transacted(() -> { - context("superuser-alex@hostsharing.net"); + context("superuser-alex@hostsharing.net"); // needed to determine creator final var givenBookingItem = givenBookingItem("D-1000111 default project", "test CloudServer"); - final var newAsset = HsHostingAssetEntity.builder() + final var newAsset = HsHostingAssetRealEntity.builder() .bookingItem(givenBookingItem) .type(CLOUD_SERVER) .identifier(identifier) - .caption("some temp cloud asset") + .caption(projectCaption) .config(Map.ofEntries( entry("CPU", 1), entry("SSD-storage", 256))) .build(); - return toCleanup(assetRepo.save(newAsset)); + return toCleanup(realAssetRepo.save(newAsset)); }).assertSuccessful().returnedValue(); } @@ -434,10 +431,10 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu .findAny().orElseThrow(); } - HsHostingAssetEntity givenHostingAsset(final String projectCaption, final HsHostingAssetType type) { + HsHostingAssetRealEntity givenHostingAsset(final String projectCaption, final HsHostingAssetType type) { final var givenProject = projectRepo.findByCaption(projectCaption).stream() .findAny().orElseThrow(); - return assetRepo.findAllByCriteria(givenProject.getUuid(), null, type).stream() + return realAssetRepo.findAllByCriteria(givenProject.getUuid(), null, type).stream() .findAny().orElseThrow(); } @@ -454,10 +451,10 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu } void exactlyTheseAssetsAreReturned( - final List actualResult, + final List actualResult, final String... serverNames) { assertThat(actualResult) - .extracting(HsHostingAssetEntity::toString) + .extracting(HsHostingAssetRbacEntity::toString) .extracting(input -> input.replaceAll("\\s+", " ")) .extracting(input -> input.replaceAll("\"", "")) .extracting(input -> input.replaceAll("\" : ", "\": ")) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTestEntities.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTestEntities.java new file mode 100644 index 00000000..f85fbcb6 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTestEntities.java @@ -0,0 +1,36 @@ +package net.hostsharing.hsadminng.hs.hosting.asset; + +import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_SERVER_BOOKING_ITEM; +import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_WEBSPACE_BOOKING_ITEM; + +public class HsHostingAssetTestEntities { + + public static final HsHostingAssetRbacEntity MANAGED_SERVER_HOSTING_ASSET_RBAC_TEST_ENTITY = HsHostingAssetRbacEntity.builder() + .type(HsHostingAssetType.MANAGED_SERVER) + .identifier("vm1234") + .caption("some managed server") + .bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM) + .build(); + + public static final HsHostingAssetRealEntity MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY = HsHostingAssetRealEntity.builder() + .type(HsHostingAssetType.MANAGED_SERVER) + .identifier("vm1234") + .caption("some managed server") + .bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM) + .build(); + + public static final HsHostingAssetRbacEntity MANAGED_WEBSPACE_HOSTING_ASSET_RBAC_TEST_ENTITY = HsHostingAssetRbacEntity.builder() + .type(HsHostingAssetType.MANAGED_WEBSPACE) + .identifier("xyz00") + .caption("some managed webspace") + .bookingItem(TEST_MANAGED_WEBSPACE_BOOKING_ITEM) + .build(); + + public static final HsHostingAssetRealEntity MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY = HsHostingAssetRealEntity.builder() + .type(HsHostingAssetType.MANAGED_WEBSPACE) + .identifier("xyz00") + .caption("some managed webspace") + .bookingItem(TEST_MANAGED_WEBSPACE_BOOKING_ITEM) + .build(); + +} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/TestHsHostingAssetEntities.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/TestHsHostingAssetEntities.java deleted file mode 100644 index e409306b..00000000 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/TestHsHostingAssetEntities.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.hostsharing.hsadminng.hs.hosting.asset; - -import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_SERVER_BOOKING_ITEM; -import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_WEBSPACE_BOOKING_ITEM; - -public class TestHsHostingAssetEntities { - - public static final HsHostingAssetEntity TEST_MANAGED_SERVER_HOSTING_ASSET = HsHostingAssetEntity.builder() - .type(HsHostingAssetType.MANAGED_SERVER) - .identifier("vm1234") - .caption("some managed server") - .bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM) - .build(); - - public static final HsHostingAssetEntity TEST_MANAGED_WEBSPACE_HOSTING_ASSET = HsHostingAssetEntity.builder() - .type(HsHostingAssetType.MANAGED_WEBSPACE) - .identifier("xyz00") - .caption("some managed webspace") - .bookingItem(TEST_MANAGED_WEBSPACE_BOOKING_ITEM) - .build(); - -} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidatorUnitTest.java index b7e3516a..6dd21fb8 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidatorUnitTest.java @@ -2,7 +2,8 @@ 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.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import org.junit.jupiter.api.Test; import java.util.Map; @@ -18,7 +19,7 @@ class HsCloudServerHostingAssetValidatorUnitTest { @Test void validatesProperties() { // given - final var cloudServerHostingAssetEntity = HsHostingAssetEntity.builder() + final var cloudServerHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(CLOUD_SERVER) .identifier("vm1234") .config(Map.ofEntries( @@ -40,7 +41,7 @@ class HsCloudServerHostingAssetValidatorUnitTest { @Test void validatesInvalidIdentifier() { // given - final var cloudServerHostingAssetEntity = HsHostingAssetEntity.builder() + final var cloudServerHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(CLOUD_SERVER) .identifier("xyz99") .bookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM) @@ -68,7 +69,7 @@ class HsCloudServerHostingAssetValidatorUnitTest { @Test void validatesBookingItemType() { // given - final var mangedServerHostingAssetEntity = HsHostingAssetEntity.builder() + final var mangedServerHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(MANAGED_SERVER) .identifier("xyz00") .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) @@ -86,12 +87,12 @@ class HsCloudServerHostingAssetValidatorUnitTest { @Test void rejectsInvalidReferencedEntities() { // given - final var mangedServerHostingAssetEntity = HsHostingAssetEntity.builder() + final var mangedServerHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(CLOUD_SERVER) .identifier("vm1234") .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) - .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build()) - .assignedToAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build()) + .parentAsset(HsHostingAssetRealEntity.builder().type(MANAGED_SERVER).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(CLOUD_SERVER).build()) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java index a907dc60..3be5fbe4 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java @@ -2,8 +2,8 @@ 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.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import net.hostsharing.hsadminng.mapper.Array; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -12,9 +12,9 @@ import java.util.ArrayList; import java.util.Map; import static java.util.Map.entry; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_DNS_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_WEBSPACE_HOSTING_ASSET; import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_COMMENT; import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_RECORD_DATA; import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_RECORD_TYPE; @@ -25,16 +25,16 @@ import static org.assertj.core.api.Assertions.assertThat; class HsDomainDnsSetupHostingAssetValidatorUnitTest { - static final HsHostingAssetEntity validDomainSetupEntity = HsHostingAssetEntity.builder() + static final HsHostingAssetRealEntity validDomainSetupEntity = HsHostingAssetRealEntity.builder() .type(DOMAIN_SETUP) .identifier("example.org") .build(); - static HsHostingAssetEntityBuilder validEntityBuilder() { - return HsHostingAssetEntity.builder() + static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder validEntityBuilder() { + return HsHostingAssetRbacEntity.builder() .type(DOMAIN_DNS_SETUP) .parentAsset(validDomainSetupEntity) - .assignedToAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) + .assignedToAsset(MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("example.org|DNS") .config(Map.ofEntries( entry("TTL", 21600), @@ -141,7 +141,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { final var mangedServerHostingAssetEntity = validEntityBuilder() .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) .parentAsset(null) - .assignedToAsset(HsHostingAssetEntity.builder().type(DOMAIN_SETUP).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(DOMAIN_SETUP).build()) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java index d15f81a5..6bd5e536 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java @@ -2,8 +2,8 @@ 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.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import net.hostsharing.hsadminng.mapper.Array; import org.junit.jupiter.api.Test; @@ -18,16 +18,16 @@ import static org.assertj.core.api.Assertions.assertThat; class HsDomainHttpSetupHostingAssetValidatorUnitTest { - static final HsHostingAssetEntity validDomainSetupEntity = HsHostingAssetEntity.builder() + static final HsHostingAssetRealEntity validDomainSetupEntity = HsHostingAssetRealEntity.builder() .type(DOMAIN_SETUP) .identifier("example.org") .build(); - static HsHostingAssetEntityBuilder validEntityBuilder() { - return HsHostingAssetEntity.builder() + static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder validEntityBuilder() { + return HsHostingAssetRbacEntity.builder() .type(DOMAIN_HTTP_SETUP) .parentAsset(validDomainSetupEntity) - .assignedToAsset(HsHostingAssetEntity.builder().type(UNIX_USER).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(UNIX_USER).build()) .identifier("example.org|HTTP") .config(Map.ofEntries( entry("passenger-errorpage", true), @@ -110,7 +110,7 @@ class HsDomainHttpSetupHostingAssetValidatorUnitTest { // given final var mangedServerHostingAssetEntity = validEntityBuilder() .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) - .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) + .parentAsset(HsHostingAssetRealEntity.builder().type(MANAGED_WEBSPACE).build()) .assignedToAsset(null) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainMboxHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainMboxHostingAssetValidatorUnitTest.java index 2c08d16f..e8940f13 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainMboxHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainMboxHostingAssetValidatorUnitTest.java @@ -2,8 +2,8 @@ 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.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import org.junit.jupiter.api.Test; import java.util.Map; @@ -16,16 +16,16 @@ import static org.assertj.core.api.Assertions.assertThat; class HsDomainMboxHostingAssetValidatorUnitTest { - static final HsHostingAssetEntity validDomainSetupEntity = HsHostingAssetEntity.builder() + static final HsHostingAssetRealEntity validDomainSetupEntity = HsHostingAssetRealEntity.builder() .type(DOMAIN_SETUP) .identifier("example.org") .build(); - static HsHostingAssetEntityBuilder validEntityBuilder() { - return HsHostingAssetEntity.builder() + static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder validEntityBuilder() { + return HsHostingAssetRbacEntity.builder() .type(DOMAIN_MBOX_SETUP) .parentAsset(validDomainSetupEntity) - .assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(MANAGED_WEBSPACE).build()) .identifier("example.org|MBOX"); } @@ -85,7 +85,7 @@ class HsDomainMboxHostingAssetValidatorUnitTest { // given final var mangedServerHostingAssetEntity = validEntityBuilder() .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) - .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) + .parentAsset(HsHostingAssetRealEntity.builder().type(MANAGED_WEBSPACE).build()) .assignedToAsset(null) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidatorUnitTest.java index f7f88eb5..42e2ce66 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidatorUnitTest.java @@ -2,8 +2,8 @@ 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.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; @@ -17,8 +17,8 @@ import static org.assertj.core.api.Assertions.assertThat; class HsDomainSetupHostingAssetValidatorUnitTest { - static HsHostingAssetEntityBuilder validEntityBuilder() { - return HsHostingAssetEntity.builder() + static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder validEntityBuilder() { + return HsHostingAssetRbacEntity.builder() .type(DOMAIN_SETUP) .identifier("example.org"); } @@ -94,8 +94,8 @@ class HsDomainSetupHostingAssetValidatorUnitTest { void validatesReferencedEntities() { // given final var mangedServerHostingAssetEntity = validEntityBuilder() - .parentAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build()) - .assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build()) + .parentAsset(HsHostingAssetRealEntity.builder().type(CLOUD_SERVER).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(MANAGED_SERVER).build()) .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSmtpSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSmtpSetupHostingAssetValidatorUnitTest.java index 014fb9ef..8d87298e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSmtpSetupHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSmtpSetupHostingAssetValidatorUnitTest.java @@ -2,8 +2,9 @@ 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.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import org.junit.jupiter.api.Test; import java.util.Map; @@ -16,16 +17,16 @@ import static org.assertj.core.api.Assertions.assertThat; class HsDomainSmtpSetupHostingAssetValidatorUnitTest { - static final HsHostingAssetEntity validDomainSetupEntity = HsHostingAssetEntity.builder() + static final HsHostingAssetRealEntity validDomainSetupEntity = HsHostingAssetRealEntity.builder() .type(DOMAIN_SETUP) .identifier("example.org") .build(); - static HsHostingAssetEntityBuilder validEntityBuilder() { - return HsHostingAssetEntity.builder() + static HsHostingAssetRbacEntityBuilder validEntityBuilder() { + return HsHostingAssetRbacEntity.builder() .type(DOMAIN_SMTP_SETUP) .parentAsset(validDomainSetupEntity) - .assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(MANAGED_WEBSPACE).build()) .identifier("example.org|SMTP"); } @@ -85,7 +86,7 @@ class HsDomainSmtpSetupHostingAssetValidatorUnitTest { // given final var mangedServerHostingAssetEntity = validEntityBuilder() .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) - .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) + .parentAsset(HsHostingAssetRealEntity.builder().type(MANAGED_WEBSPACE).build()) .assignedToAsset(null) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java index 386ba632..8d27b9df 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java @@ -1,6 +1,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import net.hostsharing.hsadminng.mapper.Array; import org.junit.jupiter.api.Test; @@ -9,25 +10,25 @@ import java.util.Map; import static java.util.Map.ofEntries; import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_SERVER_BOOKING_ITEM; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_MBOX_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.EMAIL_ADDRESS; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET; import static net.hostsharing.hsadminng.mapper.PatchableMapWrapper.entry; import static org.assertj.core.api.Assertions.assertThat; class HsEMailAddressHostingAssetValidatorUnitTest { - final static HsHostingAssetEntity domainSetup = HsHostingAssetEntity.builder() + final static HsHostingAssetRealEntity domainSetup = HsHostingAssetRealEntity.builder() .type(DOMAIN_MBOX_SETUP) .identifier("example.org") .build(); - final static HsHostingAssetEntity domainMboxSetup = HsHostingAssetEntity.builder() + final static HsHostingAssetRealEntity domainMboxSetup = HsHostingAssetRealEntity.builder() .type(DOMAIN_MBOX_SETUP) .identifier("example.org|MBOX") .parentAsset(domainSetup) .build(); - static HsHostingAssetEntity.HsHostingAssetEntityBuilder validEntityBuilder() { - return HsHostingAssetEntity.builder() + static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder validEntityBuilder() { + return HsHostingAssetRbacEntity.builder() .type(EMAIL_ADDRESS) .parentAsset(domainMboxSetup) .identifier("old-local-part@example.org") @@ -174,8 +175,8 @@ class HsEMailAddressHostingAssetValidatorUnitTest { // given final var emailAddressHostingAssetEntity = validEntityBuilder() .bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM) - .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) - .assignedToAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) + .parentAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) + .assignedToAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(emailAddressHostingAssetEntity.getType()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAliasHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAliasHostingAssetValidatorUnitTest.java index 87e7cc2e..6c197d07 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAliasHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAliasHostingAssetValidatorUnitTest.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; import net.hostsharing.hsadminng.mapper.Array; import org.junit.jupiter.api.Test; @@ -8,9 +8,9 @@ import java.util.Map; import static java.util.Map.entry; import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_SERVER_BOOKING_ITEM; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.EMAIL_ALIAS; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_WEBSPACE_HOSTING_ASSET; import static org.assertj.core.api.Assertions.assertThat; class HsEMailAliasHostingAssetValidatorUnitTest { @@ -28,9 +28,9 @@ class HsEMailAliasHostingAssetValidatorUnitTest { @Test void acceptsValidEntity() { // given - final var emailAliasHostingAssetEntity = HsHostingAssetEntity.builder() + final var emailAliasHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(EMAIL_ALIAS) - .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) + .parentAsset(MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("xyz00-office") .config(Map.ofEntries( entry("target", Array.of( @@ -54,9 +54,9 @@ class HsEMailAliasHostingAssetValidatorUnitTest { @Test void rejectsInvalidConfig() { // given - final var emailAliasHostingAssetEntity = HsHostingAssetEntity.builder() + final var emailAliasHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(EMAIL_ALIAS) - .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) + .parentAsset(MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("xyz00-office") .config(Map.ofEntries( entry("target", Array.of( @@ -83,9 +83,9 @@ class HsEMailAliasHostingAssetValidatorUnitTest { @Test void rejectsEmptyTargetArray() { // given - final var emailAliasHostingAssetEntity = HsHostingAssetEntity.builder() + final var emailAliasHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(EMAIL_ALIAS) - .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) + .parentAsset(MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("xyz00-office") .config(Map.ofEntries( entry("target", new String[0]) @@ -104,9 +104,9 @@ class HsEMailAliasHostingAssetValidatorUnitTest { @Test void rejectsInvalidIndentifier() { // given - final var emailAliasHostingAssetEntity = HsHostingAssetEntity.builder() + final var emailAliasHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(EMAIL_ALIAS) - .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) + .parentAsset(MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("abc00-office") .config(Map.ofEntries( entry("target", Array.of("office@example.com")) @@ -125,11 +125,11 @@ class HsEMailAliasHostingAssetValidatorUnitTest { @Test void validatesInvalidReferences() { // given - final var emailAliasHostingAssetEntity = HsHostingAssetEntity.builder() + final var emailAliasHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(EMAIL_ALIAS) .bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM) - .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) - .assignedToAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) + .parentAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) + .assignedToAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("abc00-office") .config(Map.ofEntries( entry("target", Array.of("office@example.com")) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv4NumberHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv4NumberHostingAssetValidatorUnitTest.java index 0d219ad2..6361dfb2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv4NumberHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv4NumberHostingAssetValidatorUnitTest.java @@ -2,8 +2,8 @@ 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.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -20,8 +20,8 @@ import static org.assertj.core.api.Assertions.assertThat; class HsIPv4NumberHostingAssetValidatorUnitTest { - static HsHostingAssetEntityBuilder validEntityBuilder() { - return HsHostingAssetEntity.builder() + static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder validEntityBuilder() { + return HsHostingAssetRbacEntity.builder() .type(IPV4_NUMBER) .identifier("83.223.95.145"); } @@ -69,7 +69,7 @@ class HsIPv4NumberHostingAssetValidatorUnitTest { void acceptsValidReferencedEntity(final HsHostingAssetType givenAssignedToAssetType) { // given final var ipNumberHostingAssetEntity = validEntityBuilder() - .assignedToAsset(HsHostingAssetEntity.builder().type(givenAssignedToAssetType).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(givenAssignedToAssetType).build()) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(ipNumberHostingAssetEntity.getType()); @@ -85,8 +85,8 @@ class HsIPv4NumberHostingAssetValidatorUnitTest { // given final var ipNumberHostingAssetEntity = validEntityBuilder() .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) - .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) - .assignedToAsset(HsHostingAssetEntity.builder().type(UNIX_USER).build()) + .parentAsset(HsHostingAssetRealEntity.builder().type(MANAGED_WEBSPACE).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(UNIX_USER).build()) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(ipNumberHostingAssetEntity.getType()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv6NumberHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv6NumberHostingAssetValidatorUnitTest.java index 51d86986..28220641 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv6NumberHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsIPv6NumberHostingAssetValidatorUnitTest.java @@ -2,8 +2,8 @@ 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.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -20,8 +20,8 @@ import static org.assertj.core.api.Assertions.assertThat; class HsIPv6NumberHostingAssetValidatorUnitTest { - static HsHostingAssetEntityBuilder validEntityBuilder() { - return HsHostingAssetEntity.builder() + static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder validEntityBuilder() { + return HsHostingAssetRbacEntity.builder() .type(IPV6_NUMBER) .identifier("2001:db8:3333:4444:5555:6666:7777:8888"); } @@ -69,7 +69,7 @@ class HsIPv6NumberHostingAssetValidatorUnitTest { void acceptsValidReferencedEntity(final HsHostingAssetType givenAssignedToAssetType) { // given final var ipNumberHostingAssetEntity = validEntityBuilder() - .assignedToAsset(HsHostingAssetEntity.builder().type(givenAssignedToAssetType).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(givenAssignedToAssetType).build()) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(ipNumberHostingAssetEntity.getType()); @@ -85,8 +85,8 @@ class HsIPv6NumberHostingAssetValidatorUnitTest { // given final var ipNumberHostingAssetEntity = validEntityBuilder() .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) - .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) - .assignedToAsset(HsHostingAssetEntity.builder().type(UNIX_USER).build()) + .parentAsset(HsHostingAssetRealEntity.builder().type(MANAGED_WEBSPACE).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(UNIX_USER).build()) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(ipNumberHostingAssetEntity.getType()); 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 67ff4db5..22d9aa54 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 @@ -2,7 +2,8 @@ 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.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import org.junit.jupiter.api.Test; import java.util.Map; @@ -19,12 +20,12 @@ class HsManagedServerHostingAssetValidatorUnitTest { @Test void validatesProperties() { // given - final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder() + final var mangedWebspaceHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(MANAGED_SERVER) .identifier("vm1234") .bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM) - .parentAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build()) - .assignedToAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build()) + .parentAsset(HsHostingAssetRealEntity.builder().type(CLOUD_SERVER).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(CLOUD_SERVER).build()) .config(Map.ofEntries( entry("monit_max_hdd_usage", "90"), entry("monit_max_cpu_usage", 2), @@ -48,7 +49,7 @@ class HsManagedServerHostingAssetValidatorUnitTest { @Test void validatesInvalidIdentifier() { // given - final var mangedServerHostingAssetEntity = HsHostingAssetEntity.builder() + final var mangedServerHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(MANAGED_SERVER) .identifier("xyz00") .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.MANAGED_SERVER).build()) @@ -66,12 +67,12 @@ class HsManagedServerHostingAssetValidatorUnitTest { @Test void rejectsInvalidReferencedEntities() { // given - final var mangedServerHostingAssetEntity = HsHostingAssetEntity.builder() + final var mangedServerHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(MANAGED_SERVER) .identifier("xyz00") .bookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM) - .parentAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build()) - .assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build()) + .parentAsset(HsHostingAssetRealEntity.builder().type(CLOUD_SERVER).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(MANAGED_SERVER).build()) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); 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 02384389..3047d7ab 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 @@ -2,7 +2,8 @@ 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.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import org.junit.jupiter.api.Test; @@ -35,7 +36,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { .caption("Test Cloud-Server") .build(); - final HsHostingAssetEntity mangedServerAssetEntity = HsHostingAssetEntity.builder() + final HsHostingAssetRealEntity mangedServerAssetEntity = HsHostingAssetRealEntity.builder() .type(HsHostingAssetType.MANAGED_SERVER) .bookingItem(managedServerBookingItem) .identifier("vm1234") @@ -45,7 +46,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { entry("monit_max_ram_usage", 90) )) .build(); - final HsHostingAssetEntity cloudServerAssetEntity = HsHostingAssetEntity.builder() + final HsHostingAssetRealEntity cloudServerAssetEntity = HsHostingAssetRealEntity.builder() .type(HsHostingAssetType.CLOUD_SERVER) .bookingItem(cloudServerBookingItem) .identifier("vm1234") @@ -60,7 +61,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { void acceptsAlienIdentifierPrefixForPreExistingEntity() { // given final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); - final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder() + final var mangedWebspaceHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(MANAGED_WEBSPACE) .bookingItem(HsBookingItemEntity.builder() .type(HsBookingItemType.MANAGED_WEBSPACE) @@ -82,7 +83,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { void validatesIdentifierAndReferencedEntities() { // given final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); - final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder() + final var mangedWebspaceHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(MANAGED_WEBSPACE) .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.MANAGED_WEBSPACE).build()) .parentAsset(mangedServerAssetEntity) @@ -100,7 +101,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { void validatesUnknownProperties() { // given final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); - final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder() + final var mangedWebspaceHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(MANAGED_WEBSPACE) .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.MANAGED_WEBSPACE).build()) .parentAsset(mangedServerAssetEntity) @@ -121,7 +122,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { void validatesValidEntity() { // given final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); - final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder() + final var mangedWebspaceHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(MANAGED_WEBSPACE) .bookingItem(HsBookingItemEntity.builder() .type(HsBookingItemType.MANAGED_WEBSPACE) @@ -147,7 +148,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { void rejectsInvalidEntityReferences() { // given final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); - final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder() + final var mangedWebspaceHostingAssetEntity = HsHostingAssetRbacEntity.builder() .type(MANAGED_WEBSPACE) .bookingItem(HsBookingItemEntity.builder() .type(HsBookingItemType.MANAGED_SERVER) @@ -155,7 +156,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { .resources(Map.ofEntries(entry("SSD", 25), entry("Traffic", 250))) .build()) .parentAsset(cloudServerAssetEntity) - .assignedToAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(CLOUD_SERVER).build()) .identifier("abc00") .build(); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbDatabaseHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbDatabaseHostingAssetValidatorUnitTest.java index 7e7c8b5b..33982abc 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbDatabaseHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbDatabaseHostingAssetValidatorUnitTest.java @@ -1,33 +1,33 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.stream.Stream; import static java.util.Map.ofEntries; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_DATABASE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_INSTANCE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_USER; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_WEBSPACE_HOSTING_ASSET; import static net.hostsharing.hsadminng.mapper.PatchMap.entry; import static org.assertj.core.api.Assertions.assertThat; class HsMariaDbDatabaseHostingAssetValidatorUnitTest { - private static final HsHostingAssetEntity GIVEN_MARIADB_INSTANCE = HsHostingAssetEntity.builder() + private static final HsHostingAssetRealEntity GIVEN_MARIADB_INSTANCE = HsHostingAssetRealEntity.builder() .type(MARIADB_INSTANCE) - .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) + .parentAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("vm1234|MariaDB.default") .caption("some valid test MariaDB-Instance") .build(); - private static final HsHostingAssetEntity GIVEN_MARIADB_USER = HsHostingAssetEntity.builder() + private static final HsHostingAssetRealEntity GIVEN_MARIADB_USER = HsHostingAssetRealEntity.builder() .type(MARIADB_USER) - .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) + .parentAsset(MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY) .assignedToAsset(GIVEN_MARIADB_INSTANCE) .identifier("xyz00_temp") .caption("some valid test MariaDB-User") @@ -36,8 +36,8 @@ class HsMariaDbDatabaseHostingAssetValidatorUnitTest { ))) .build(); - private static HsHostingAssetEntityBuilder givenValidMariaDbDatabaseBuilder() { - return HsHostingAssetEntity.builder() + private static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder givenValidMariaDbDatabaseBuilder() { + return HsHostingAssetRbacEntity.builder() .type(MARIADB_DATABASE) .parentAsset(GIVEN_MARIADB_USER) .identifier("MAD|xyz00_temp") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbInstanceHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbInstanceHostingAssetValidatorUnitTest.java index 24d8b4d1..212bb7a7 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbInstanceHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbInstanceHostingAssetValidatorUnitTest.java @@ -2,27 +2,27 @@ 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.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import org.junit.jupiter.api.Test; import java.util.Map; import static java.util.Map.entry; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SMTP_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_INSTANCE; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET; import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsMariaDbInstanceHostingAssetValidator.DEFAULT_INSTANCE_IDENTIFIER_SUFFIX; import static org.assertj.core.api.Assertions.assertThat; class HsMariaDbInstanceHostingAssetValidatorUnitTest { - static HsHostingAssetEntityBuilder validEntityBuilder() { - return HsHostingAssetEntity.builder() + static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder validEntityBuilder() { + return HsHostingAssetRbacEntity.builder() .type(MARIADB_INSTANCE) - .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) - .identifier(TEST_MANAGED_SERVER_HOSTING_ASSET.getIdentifier() + DEFAULT_INSTANCE_IDENTIFIER_SUFFIX); + .parentAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) + .identifier(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY.getIdentifier() + DEFAULT_INSTANCE_IDENTIFIER_SUFFIX); } @Test @@ -81,8 +81,8 @@ class HsMariaDbInstanceHostingAssetValidatorUnitTest { // given final var mangedServerHostingAssetEntity = validEntityBuilder() .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) - .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) - .assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) + .parentAsset(HsHostingAssetRealEntity.builder().type(MANAGED_WEBSPACE).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(MANAGED_WEBSPACE).build()) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbUserHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbUserHostingAssetValidatorUnitTest.java index 70b823c8..e675dc90 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbUserHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsMariaDbUserHostingAssetValidatorUnitTest.java @@ -1,7 +1,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import org.junit.jupiter.api.Test; import jakarta.persistence.EntityManager; @@ -9,28 +9,28 @@ import java.util.HashMap; import java.util.stream.Stream; import static java.util.Map.ofEntries; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_INSTANCE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_USER; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_WEBSPACE_HOSTING_ASSET; import static net.hostsharing.hsadminng.mapper.PatchMap.entry; import static org.assertj.core.api.Assertions.assertThat; class HsMariaDbUserHostingAssetValidatorUnitTest { - private static final HsHostingAssetEntity GIVEN_MARIADB_INSTANCE = HsHostingAssetEntity.builder() + private static final HsHostingAssetRealEntity GIVEN_MARIADB_INSTANCE = HsHostingAssetRealEntity.builder() .type(MARIADB_INSTANCE) - .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) + .parentAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("vm1234|MariaDB.default") .caption("some valid test MariaDB-Instance") .build(); private EntityManager em = null; // not actually needed in these test cases - private static HsHostingAssetEntityBuilder givenValidMariaDbUserBuilder() { - return HsHostingAssetEntity.builder() + private static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder givenValidMariaDbUserBuilder() { + return HsHostingAssetRbacEntity.builder() .type(MARIADB_USER) - .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) + .parentAsset(MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY) .assignedToAsset(GIVEN_MARIADB_INSTANCE) .identifier("MAU|xyz00_temp") .caption("some valid test MariaDB-User") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlDatabaseHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlDatabaseHostingAssetValidatorUnitTest.java index 78a59288..5abefdee 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlDatabaseHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlDatabaseHostingAssetValidatorUnitTest.java @@ -2,34 +2,34 @@ 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.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.stream.Stream; import static java.util.Map.ofEntries; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.PGSQL_DATABASE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.PGSQL_INSTANCE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.PGSQL_USER; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_WEBSPACE_HOSTING_ASSET; import static net.hostsharing.hsadminng.mapper.PatchMap.entry; import static org.assertj.core.api.Assertions.assertThat; class HsPostgreSqlDatabaseHostingAssetValidatorUnitTest { - private static final HsHostingAssetEntity GIVEN_PGSQL_INSTANCE = HsHostingAssetEntity.builder() + private static final HsHostingAssetRealEntity GIVEN_PGSQL_INSTANCE = HsHostingAssetRealEntity.builder() .type(PGSQL_INSTANCE) - .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) + .parentAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("vm1234|PgSql.default") .caption("some valid test PgSql-Instance") .build(); - private static final HsHostingAssetEntity GIVEN_PGSQL_USER = HsHostingAssetEntity.builder() + private static final HsHostingAssetRealEntity GIVEN_PGSQL_USER = HsHostingAssetRealEntity.builder() .type(PGSQL_USER) - .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) + .parentAsset(MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY) .assignedToAsset(GIVEN_PGSQL_INSTANCE) .identifier("xyz00_user") .caption("some valid test PgSql-User") @@ -38,8 +38,8 @@ class HsPostgreSqlDatabaseHostingAssetValidatorUnitTest { ))) .build(); - private static HsHostingAssetEntityBuilder givenValidPgSqlDatabaseBuilder() { - return HsHostingAssetEntity.builder() + private static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder givenValidPgSqlDatabaseBuilder() { + return HsHostingAssetRbacEntity.builder() .type(PGSQL_DATABASE) .parentAsset(GIVEN_PGSQL_USER) .identifier("PGD|xyz00_db") @@ -84,8 +84,8 @@ class HsPostgreSqlDatabaseHostingAssetValidatorUnitTest { // given final var givenPgSqlUserHostingAsset = givenValidPgSqlDatabaseBuilder() .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) - .parentAsset(HsHostingAssetEntity.builder().type(PGSQL_INSTANCE).build()) - .assignedToAsset(HsHostingAssetEntity.builder().type(PGSQL_INSTANCE).build()) + .parentAsset(HsHostingAssetRealEntity.builder().type(PGSQL_INSTANCE).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(PGSQL_INSTANCE).build()) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(givenPgSqlUserHostingAsset.getType()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlInstanceHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlInstanceHostingAssetValidatorUnitTest.java index 231bb773..5a1424fe 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlInstanceHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlInstanceHostingAssetValidatorUnitTest.java @@ -2,8 +2,8 @@ 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.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import org.junit.jupiter.api.Test; import java.util.Map; @@ -12,17 +12,17 @@ import static java.util.Map.entry; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SMTP_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_INSTANCE; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY; import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsMariaDbInstanceHostingAssetValidator.DEFAULT_INSTANCE_IDENTIFIER_SUFFIX; import static org.assertj.core.api.Assertions.assertThat; class HsPostgreSqlInstanceHostingAssetValidatorUnitTest { - static HsHostingAssetEntityBuilder validEntityBuilder() { - return HsHostingAssetEntity.builder() + static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder validEntityBuilder() { + return HsHostingAssetRbacEntity.builder() .type(MARIADB_INSTANCE) - .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) - .identifier(TEST_MANAGED_SERVER_HOSTING_ASSET.getIdentifier() + DEFAULT_INSTANCE_IDENTIFIER_SUFFIX); + .parentAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) + .identifier(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY.getIdentifier() + DEFAULT_INSTANCE_IDENTIFIER_SUFFIX); } @Test @@ -81,8 +81,8 @@ class HsPostgreSqlInstanceHostingAssetValidatorUnitTest { // given final var mangedServerHostingAssetEntity = validEntityBuilder() .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) - .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) - .assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) + .parentAsset(HsHostingAssetRealEntity.builder().type(MANAGED_WEBSPACE).build()) + .assignedToAsset(HsHostingAssetRealEntity.builder().type(MANAGED_WEBSPACE).build()) .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlUserHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlUserHostingAssetValidatorUnitTest.java index bb589a7b..89091fd3 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlUserHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsPostgreSqlUserHostingAssetValidatorUnitTest.java @@ -1,8 +1,8 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; import net.hostsharing.hsadminng.hash.HashGenerator; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import org.junit.jupiter.api.Test; import jakarta.persistence.EntityManager; @@ -12,28 +12,28 @@ import java.util.HashMap; import java.util.stream.Stream; import static java.util.Map.ofEntries; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetTestEntities.MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.PGSQL_INSTANCE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.PGSQL_USER; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET; -import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_WEBSPACE_HOSTING_ASSET; import static net.hostsharing.hsadminng.mapper.PatchMap.entry; import static org.assertj.core.api.Assertions.assertThat; class HsPostgreSqlUserHostingAssetValidatorUnitTest { - private static final HsHostingAssetEntity GIVEN_PGSQL_INSTANCE = HsHostingAssetEntity.builder() + private static final HsHostingAssetRealEntity GIVEN_PGSQL_INSTANCE = HsHostingAssetRealEntity.builder() .type(PGSQL_INSTANCE) - .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) + .parentAsset(MANAGED_SERVER_HOSTING_ASSET_REAL_TEST_ENTITY) .identifier("vm1234|PgSql.default") .caption("some valid test PgSql-Instance") .build(); private EntityManager em = null; // not actually needed in these test cases - private static HsHostingAssetEntityBuilder givenValidMariaDbUserBuilder() { - return HsHostingAssetEntity.builder() + private static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder givenValidMariaDbUserBuilder() { + return HsHostingAssetRbacEntity.builder() .type(PGSQL_USER) - .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) + .parentAsset(MANAGED_WEBSPACE_HOSTING_ASSET_REAL_TEST_ENTITY) .assignedToAsset(GIVEN_PGSQL_INSTANCE) .identifier("PGU|xyz00_temp") .caption("some valid test PgSql-User") 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 e24eaf51..d776038d 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 @@ -1,7 +1,8 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators; import net.hostsharing.hsadminng.hash.HashGenerator; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -27,21 +28,27 @@ import static org.mockito.Mockito.mock; @ExtendWith(MockitoExtension.class) class HsUnixUserHostingAssetValidatorUnitTest { - private final HsHostingAssetEntity TEST_MANAGED_SERVER_HOSTING_ASSET = HsHostingAssetEntity.builder() + private final HsHostingAssetRealEntity TEST_MANAGED_SERVER_HOSTING_ASSET_REAL_ENTITY = HsHostingAssetRealEntity.builder() .type(HsHostingAssetType.MANAGED_SERVER) .identifier("vm1234") .caption("some managed server") .bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM) .build(); - private final HsHostingAssetEntity TEST_MANAGED_WEBSPACE_HOSTING_ASSET = HsHostingAssetEntity.builder() + private final HsHostingAssetRealEntity TEST_MANAGED_WEBSPACE_HOSTING_ASSET_REAL_ENTITY = HsHostingAssetRealEntity.builder() .type(MANAGED_WEBSPACE) .bookingItem(TEST_MANAGED_WEBSPACE_BOOKING_ITEM) - .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) + .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET_REAL_ENTITY) .identifier("abc00") .build(); - private final HsHostingAssetEntity GIVEN_VALID_UNIX_USER_HOSTING_ASSET = HsHostingAssetEntity.builder() + private final HsHostingAssetRbacEntity TEST_MANAGED_WEBSPACE_HOSTING_ASSET_RBAC_ENTITY = HsHostingAssetRbacEntity.builder() + .type(MANAGED_WEBSPACE) + .bookingItem(TEST_MANAGED_WEBSPACE_BOOKING_ITEM) + .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET_REAL_ENTITY) + .identifier("abc00") + .build(); + private final HsHostingAssetRbacEntity GIVEN_VALID_UNIX_USER_HOSTING_ASSET = HsHostingAssetRbacEntity.builder() .type(UNIX_USER) - .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) + .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET_REAL_ENTITY) .identifier("abc00-temp") .caption("some valid test UnixUser") .config(new HashMap<>(ofEntries( @@ -103,9 +110,9 @@ class HsUnixUserHostingAssetValidatorUnitTest { @Test void validatesUnixUserProperties() { // given - final var unixUserHostingAsset = HsHostingAssetEntity.builder() + final var unixUserHostingAsset = HsHostingAssetRbacEntity.builder() .type(UNIX_USER) - .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) + .parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET_REAL_ENTITY) .identifier("abc00-temp") .caption("some test UnixUser with invalid properties") .config(ofEntries( @@ -140,9 +147,9 @@ class HsUnixUserHostingAssetValidatorUnitTest { @Test void validatesInvalidIdentifier() { // given - final var unixUserHostingAsset = HsHostingAssetEntity.builder() + final var unixUserHostingAsset = HsHostingAssetRbacEntity.builder() .type(UNIX_USER) - .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).identifier("abc00").build()) + .parentAsset(HsHostingAssetRealEntity.builder().type(MANAGED_WEBSPACE).identifier("abc00").build()) .identifier("xyz99-temp") .build(); final var validator = HostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType()); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetRealEntity.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetRealEntity.java deleted file mode 100644 index b83f97ee..00000000 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/HsHostingAssetRealEntity.java +++ /dev/null @@ -1,114 +0,0 @@ -package net.hostsharing.hsadminng.hs.migration; - -import io.hypersistence.utils.hibernate.type.json.JsonType; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAsset; -import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; -import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRealEntity; -import net.hostsharing.hsadminng.mapper.PatchableMapWrapper; -import org.hibernate.annotations.Type; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; -import jakarta.persistence.PostLoad; -import jakarta.persistence.Table; -import jakarta.persistence.Transient; -import jakarta.persistence.Version; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -@Builder -@Entity -@Table(name = "hs_hosting_asset") -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -public class HsHostingAssetRealEntity implements HsHostingAsset { - - @Id - @GeneratedValue - private UUID uuid; - - @Version - private int version; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "bookingitemuuid") - private HsBookingItemEntity bookingItem; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "parentassetuuid") - private HsHostingAssetRealEntity parentAsset; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "assignedtoassetuuid") - private HsHostingAssetRealEntity assignedToAsset; - - @Column(name = "type") - @Enumerated(EnumType.STRING) - private HsHostingAssetType type; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "alarmcontactuuid") - private HsOfficeContactRealEntity alarmContact; - - @OneToMany(cascade = CascadeType.REFRESH, orphanRemoval = true, fetch = FetchType.LAZY) - @JoinColumn(name = "parentassetuuid", referencedColumnName = "uuid") - private List subHostingAssets; - - @Column(name = "identifier") - private String identifier; // e.g. vm1234, xyz00, example.org, xyz00_abc - - @Column(name = "caption") - private String caption; - - @Builder.Default - @Setter(AccessLevel.NONE) - @Type(JsonType.class) - @Column(columnDefinition = "config") - private Map config = new HashMap<>(); - - @Transient - private PatchableMapWrapper configWrapper; - - @Transient - private boolean isLoaded; - - @PostLoad - public void markAsLoaded() { - this.isLoaded = true; - } - - public PatchableMapWrapper getConfig() { - return PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper;}, config); - } - - @Override - public PatchableMapWrapper directProps() { - return getConfig(); - } - - @Override - public String toString() { - return stringify.using(HsHostingAssetRealEntity.class).apply(this); - } -} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java index 410485eb..c3db5298 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/ImportHostingAssets.java @@ -10,6 +10,7 @@ import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; import net.hostsharing.hsadminng.hs.booking.item.validators.HsBookingItemEntityValidatorRegistry; import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity; import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntitySaveProcessor; import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntityValidatorRegistry;