From 5992df3735ce9a9a44432789bb9a516378c1bdcc Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 9 Jul 2024 14:39:32 +0200 Subject: [PATCH 1/3] renaming of general+base-classes to improve order in explorer --- .../asset/HsHostingAssetController.java | 10 +++++----- .../asset/HsHostingAssetPropsController.java | 6 +++--- ...va => HostingAssetEntitySaveProcessor.java} | 18 +++++++++--------- ...r.java => HostingAssetEntityValidator.java} | 8 ++++---- ...> HostingAssetEntityValidatorRegistry.java} | 2 +- .../HsCloudServerHostingAssetValidator.java | 2 +- .../HsDomainDnsSetupHostingAssetValidator.java | 2 +- .../HsDomainSetupHostingAssetValidator.java | 2 +- .../HsEMailAliasHostingAssetValidator.java | 2 +- .../HsManagedServerHostingAssetValidator.java | 2 +- ...HsManagedWebspaceHostingAssetValidator.java | 2 +- .../HsUnixUserHostingAssetValidator.java | 2 +- ...gAssetEntityValidatorRegistryUnitTest.java} | 6 +++--- ...oudServerHostingAssetValidatorUnitTest.java | 10 +++++----- ...nDnsSetupHostingAssetValidatorUnitTest.java | 18 +++++++++--------- ...mainSetupHostingAssetValidatorUnitTest.java | 8 ++++---- ...MailAliasHostingAssetValidatorUnitTest.java | 10 +++++----- ...gedServerHostingAssetValidatorUnitTest.java | 6 +++--- ...dWebspaceHostingAssetValidatorUnitTest.java | 10 +++++----- ...sUnixUserHostingAssetValidatorUnitTest.java | 12 ++++++------ 20 files changed, 69 insertions(+), 69 deletions(-) rename src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/{HsHostingAssetEntityProcessor.java => HostingAssetEntitySaveProcessor.java} (81%) rename src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/{HsHostingAssetEntityValidator.java => HostingAssetEntityValidator.java} (96%) rename src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/{HsHostingAssetEntityValidatorRegistry.java => HostingAssetEntityValidatorRegistry.java} (97%) rename src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/{HsHostingAssetEntityValidatorRegistryUnitTest.java => HostingAssetEntityValidatorRegistryUnitTest.java} (86%) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetController.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetController.java index 6e082c05..3ca7efff 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetController.java @@ -1,8 +1,8 @@ package net.hostsharing.hsadminng.hs.hosting.asset; import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRepository; -import net.hostsharing.hsadminng.hs.hosting.asset.validators.HsHostingAssetEntityProcessor; -import net.hostsharing.hsadminng.hs.hosting.asset.validators.HsHostingAssetEntityValidatorRegistry; +import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntitySaveProcessor; +import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntityValidatorRegistry; import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.api.HsHostingAssetsApi; import net.hostsharing.hsadminng.context.Context; @@ -72,7 +72,7 @@ public class HsHostingAssetController implements HsHostingAssetsApi { final var entity = mapper.map(body, HsHostingAssetEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER); - final var mapped = new HsHostingAssetEntityProcessor(entity) + final var mapped = new HostingAssetEntitySaveProcessor(entity) .preprocessEntity() .validateEntity() .prepareForSave() @@ -133,7 +133,7 @@ public class HsHostingAssetController implements HsHostingAssetsApi { new HsHostingAssetEntityPatcher(em, entity).apply(body); - final var mapped = new HsHostingAssetEntityProcessor(entity) + final var mapped = new HostingAssetEntitySaveProcessor(entity) .preprocessEntity() .validateEntity() .prepareForSave() @@ -161,6 +161,6 @@ public class HsHostingAssetController implements HsHostingAssetsApi { @SuppressWarnings("unchecked") final BiConsumer ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) - -> resource.setConfig(HsHostingAssetEntityValidatorRegistry.forType(entity.getType()) + -> resource.setConfig(HostingAssetEntityValidatorRegistry.forType(entity.getType()) .revampProperties(entity, (Map) resource.getConfig())); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsController.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsController.java index 0da530bd..ca8bbb08 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsController.java @@ -1,6 +1,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset; -import net.hostsharing.hsadminng.hs.hosting.asset.validators.HsHostingAssetEntityValidatorRegistry; +import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntityValidatorRegistry; import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.api.HsHostingAssetPropsApi; import net.hostsharing.hsadminng.hs.hosting.generated.api.v1.model.HsHostingAssetTypeResource; import org.springframework.http.ResponseEntity; @@ -15,7 +15,7 @@ public class HsHostingAssetPropsController implements HsHostingAssetPropsApi { @Override public ResponseEntity> listAssetTypes() { - final var resource = HsHostingAssetEntityValidatorRegistry.types().stream() + final var resource = HostingAssetEntityValidatorRegistry.types().stream() .map(Enum::name) .toList(); return ResponseEntity.ok(resource); @@ -26,7 +26,7 @@ public class HsHostingAssetPropsController implements HsHostingAssetPropsApi { final HsHostingAssetTypeResource assetType) { final Enum type = HsHostingAssetType.of(assetType); - final var propValidators = HsHostingAssetEntityValidatorRegistry.forType(type); + final var propValidators = HostingAssetEntityValidatorRegistry.forType(type); final List> resource = propValidators.properties(); return ResponseEntity.ok(toListOfObjects(resource)); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityProcessor.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntitySaveProcessor.java similarity index 81% rename from src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityProcessor.java rename to src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntitySaveProcessor.java index cc192bc7..189b3314 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityProcessor.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntitySaveProcessor.java @@ -11,27 +11,27 @@ import java.util.function.Function; /** * Wraps the steps of the pararation, validation, mapping and revamp around saving of a HsHostingAssetEntity into a readable API. */ -public class HsHostingAssetEntityProcessor { +public class HostingAssetEntitySaveProcessor { private final HsEntityValidator validator; private String expectedStep = "preprocessEntity"; private HsHostingAssetEntity entity; private HsHostingAssetResource resource; - public HsHostingAssetEntityProcessor(final HsHostingAssetEntity entity) { + public HostingAssetEntitySaveProcessor(final HsHostingAssetEntity entity) { this.entity = entity; - this.validator = HsHostingAssetEntityValidatorRegistry.forType(entity.getType()); + this.validator = HostingAssetEntityValidatorRegistry.forType(entity.getType()); } /// initial step allowing to set default values before any validations - public HsHostingAssetEntityProcessor preprocessEntity() { + public HostingAssetEntitySaveProcessor preprocessEntity() { step("preprocessEntity", "validateEntity"); validator.preprocessEntity(entity); return this; } /// validates the entity itself including its properties - public HsHostingAssetEntityProcessor validateEntity() { + public HostingAssetEntitySaveProcessor validateEntity() { step("validateEntity", "prepareForSave"); MultiValidationException.throwIfNotEmpty(validator.validateEntity(entity)); return this; @@ -39,27 +39,27 @@ public class HsHostingAssetEntityProcessor { /// hashing passwords etc. @SuppressWarnings("unchecked") - public HsHostingAssetEntityProcessor prepareForSave() { + public HostingAssetEntitySaveProcessor prepareForSave() { step("prepareForSave", "saveUsing"); validator.prepareProperties(entity); return this; } - public HsHostingAssetEntityProcessor saveUsing(final Function saveFunction) { + public HostingAssetEntitySaveProcessor saveUsing(final Function saveFunction) { step("saveUsing", "validateContext"); entity = saveFunction.apply(entity); return this; } /// validates the entity within it's parent and child hierarchy (e.g. totals validators and other limits) - public HsHostingAssetEntityProcessor validateContext() { + public HostingAssetEntitySaveProcessor validateContext() { step("validateContext", "mapUsing"); MultiValidationException.throwIfNotEmpty(validator.validateContext(entity)); return this; } /// maps entity to JSON resource representation - public HsHostingAssetEntityProcessor mapUsing( + public HostingAssetEntitySaveProcessor mapUsing( final Function mapFunction) { step("mapUsing", "revampProperties"); resource = mapFunction.apply(entity); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java similarity index 96% rename from src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidator.java rename to src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java index 187630fb..0c0282e0 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsHostingAssetEntityValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidator.java @@ -21,16 +21,16 @@ import static java.util.Arrays.stream; import static java.util.Collections.emptyList; import static java.util.Optional.ofNullable; -public abstract class HsHostingAssetEntityValidator extends HsEntityValidator { +public abstract class HostingAssetEntityValidator extends HsEntityValidator { static final ValidatableProperty[] NO_EXTRA_PROPERTIES = new ValidatableProperty[0]; private final ReferenceValidator bookingItemReferenceValidation; private final ReferenceValidator parentAssetReferenceValidation; private final ReferenceValidator assignedToAssetReferenceValidation; - private final HsHostingAssetEntityValidator.AlarmContact alarmContactValidation; + private final HostingAssetEntityValidator.AlarmContact alarmContactValidation; - HsHostingAssetEntityValidator( + HostingAssetEntityValidator( final HsHostingAssetType assetType, final AlarmContact alarmContactValidation, final ValidatableProperty... properties) { @@ -98,7 +98,7 @@ public abstract class HsHostingAssetEntityValidator extends HsEntityValidator, HsEntityValidator> validators = new HashMap<>(); static { diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidator.java index 9413dcf2..840e5841 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsCloudServerHostingAssetValidator.java @@ -6,7 +6,7 @@ import java.util.regex.Pattern; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.CLOUD_SERVER; -class HsCloudServerHostingAssetValidator extends HsHostingAssetEntityValidator { +class HsCloudServerHostingAssetValidator extends HostingAssetEntityValidator { HsCloudServerHostingAssetValidator() { super( diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidator.java index c263be60..06e8b72a 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidator.java @@ -15,7 +15,7 @@ import static net.hostsharing.hsadminng.hs.validation.BooleanProperty.booleanPro import static net.hostsharing.hsadminng.hs.validation.IntegerProperty.integerProperty; import static net.hostsharing.hsadminng.hs.validation.StringProperty.stringProperty; -class HsDomainDnsSetupHostingAssetValidator extends HsHostingAssetEntityValidator { +class HsDomainDnsSetupHostingAssetValidator extends HostingAssetEntityValidator { // according to RFC 1035 (section 5) and RFC 1034 static final String RR_REGEX_NAME = "([a-z0-9\\.-]+|@)\\s+"; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java index e16b1356..60ad9283 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java @@ -7,7 +7,7 @@ import java.util.regex.Pattern; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP; -class HsDomainSetupHostingAssetValidator extends HsHostingAssetEntityValidator { +class HsDomainSetupHostingAssetValidator extends HostingAssetEntityValidator { public static final String DOMAIN_NAME_REGEX = "^((?!-)[A-Za-z0-9-]{1,63}(? { - HsHostingAssetEntityValidatorRegistry.forType(null); + HostingAssetEntityValidatorRegistry.forType(null); }); // then @@ -22,7 +22,7 @@ class HsHostingAssetEntityValidatorRegistryUnitTest { @Test void typesReturnsAllImplementedTypes() { // when - final var types = HsHostingAssetEntityValidatorRegistry.types(); + final var types = HostingAssetEntityValidatorRegistry.types(); // then // TODO.test: when all types are implemented, replace with set of all types: 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 8361c5f4..b7e3516a 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 @@ -25,7 +25,7 @@ class HsCloudServerHostingAssetValidatorUnitTest { entry("RAM", 2000) )) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(cloudServerHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(cloudServerHostingAssetEntity.getType()); // when @@ -45,7 +45,7 @@ class HsCloudServerHostingAssetValidatorUnitTest { .identifier("xyz99") .bookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(cloudServerHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(cloudServerHostingAssetEntity.getType()); // when @@ -59,7 +59,7 @@ class HsCloudServerHostingAssetValidatorUnitTest { @Test void containsAllValidations() { // when - final var validator = HsHostingAssetEntityValidatorRegistry.forType(CLOUD_SERVER); + final var validator = HostingAssetEntityValidatorRegistry.forType(CLOUD_SERVER); // then assertThat(validator.properties()).map(Map::toString).isEmpty(); @@ -73,7 +73,7 @@ class HsCloudServerHostingAssetValidatorUnitTest { .identifier("xyz00") .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); // when final var result = validator.validateEntity(mangedServerHostingAssetEntity); @@ -93,7 +93,7 @@ class HsCloudServerHostingAssetValidatorUnitTest { .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build()) .assignedToAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build()) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); // when final var result = validator.validateEntity(mangedServerHostingAssetEntity); 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 681196ae..c858a2f6 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 @@ -46,7 +46,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { @Test void containsExpectedProperties() { // when - final var validator = HsHostingAssetEntityValidatorRegistry.forType(DOMAIN_DNS_SETUP); + final var validator = HostingAssetEntityValidatorRegistry.forType(DOMAIN_DNS_SETUP); // then assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder( @@ -75,7 +75,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { // given final var givenEntity = validEntityBuilder().build(); assertThat(givenEntity.getParentAsset().getIdentifier()).as("preconditon failed").isEqualTo("example.org"); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); // when validator.preprocessEntity(givenEntity); @@ -88,7 +88,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { void rejectsInvalidIdentifier() { // given final var givenEntity = validEntityBuilder().identifier("example.org").build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); // when final var result = validator.validateEntity(givenEntity); @@ -103,7 +103,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { void acceptsValidIdentifier() { // given final var givenEntity = validEntityBuilder().identifier(validDomainSetupEntity.getIdentifier()+"|DNS").build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); // when final var result = validator.validateEntity(givenEntity); @@ -120,7 +120,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { .parentAsset(null) .assignedToAsset(HsHostingAssetEntity.builder().type(DOMAIN_SETUP).build()) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); // when final var result = validator.validateEntity(mangedServerHostingAssetEntity); @@ -136,7 +136,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { void acceptsValidEntity() { // given final var givenEntity = validEntityBuilder().build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); // when final var errors = validator.validateEntity(givenEntity); @@ -156,7 +156,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { "www BAD1 Record-Class missing / not enough columns")) )) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); // when final var result = validator.validateEntity(mangedServerHostingAssetEntity); @@ -200,7 +200,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { void generatesZonefile() { // given final var givenEntity = validEntityBuilder().build(); - final var validator = (HsDomainDnsSetupHostingAssetValidator) HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + final var validator = (HsDomainDnsSetupHostingAssetValidator) HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); // when final var zonefile = validator.toZonefileString(givenEntity); @@ -231,7 +231,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { )) )) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); // when final var errors = validator.validateContext(givenEntity); 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 c9b99784..f312fae9 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 @@ -42,7 +42,7 @@ class HsDomainSetupHostingAssetValidatorUnitTest { void rejectsInvalidIdentifier(final InvalidDomainNameIdentifier testCase) { // given final var givenEntity = validEntityBuilder().identifier(testCase.domainName).build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); // when final var result = validator.validateEntity(givenEntity); @@ -72,7 +72,7 @@ class HsDomainSetupHostingAssetValidatorUnitTest { void acceptsValidIdentifier(final ValidDomainNameIdentifier testCase) { // given final var givenEntity = validEntityBuilder().identifier(testCase.domainName).build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); // when final var result = validator.validateEntity(givenEntity); @@ -84,7 +84,7 @@ class HsDomainSetupHostingAssetValidatorUnitTest { @Test void containsNoProperties() { // when - final var validator = HsHostingAssetEntityValidatorRegistry.forType(CLOUD_SERVER); + final var validator = HostingAssetEntityValidatorRegistry.forType(CLOUD_SERVER); // then assertThat(validator.properties()).map(Map::toString).isEmpty(); @@ -98,7 +98,7 @@ class HsDomainSetupHostingAssetValidatorUnitTest { .assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build()) .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); // when final var result = validator.validateEntity(mangedServerHostingAssetEntity); 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 38e7564e..a992d858 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 @@ -18,7 +18,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest { @Test void containsAllValidations() { // when - final var validator = HsHostingAssetEntityValidatorRegistry.forType(EMAIL_ALIAS); + final var validator = HostingAssetEntityValidatorRegistry.forType(EMAIL_ALIAS); // then assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder( @@ -36,7 +36,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest { entry("target", Array.of("xyz00", "xyz00-abc", "office@example.com")) )) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType()); // when final var result = validator.validateEntity(emailAliasHostingAssetEntity); @@ -56,7 +56,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest { entry("target", Array.of("xyz00", "xyz00-abc", "garbage", "office@example.com")) )) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType()); // when final var result = validator.validateEntity(emailAliasHostingAssetEntity); @@ -77,7 +77,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest { entry("target", Array.of("office@example.com")) )) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType()); // when final var result = validator.validateEntity(emailAliasHostingAssetEntity); @@ -100,7 +100,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest { entry("target", Array.of("office@example.com")) )) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(emailAliasHostingAssetEntity.getType()); // when final var result = validator.validateEntity(emailAliasHostingAssetEntity); 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 15b2ca97..4efcde64 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 @@ -31,7 +31,7 @@ class HsManagedServerHostingAssetValidatorUnitTest { entry("monit_max_ram_usage", 101) )) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedWebspaceHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(mangedWebspaceHostingAssetEntity.getType()); // when final var result = validator.validateEntity(mangedWebspaceHostingAssetEntity); @@ -53,7 +53,7 @@ class HsManagedServerHostingAssetValidatorUnitTest { .identifier("xyz00") .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.MANAGED_SERVER).build()) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); // when final var result = validator.validateEntity(mangedServerHostingAssetEntity); @@ -73,7 +73,7 @@ class HsManagedServerHostingAssetValidatorUnitTest { .parentAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build()) .assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build()) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); // when final var result = validator.validateEntity(mangedServerHostingAssetEntity); 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 7e353147..d7efcda4 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 @@ -59,7 +59,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { @Test void acceptsAlienIdentifierPrefixForPreExistingEntity() { // given - final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); + final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder() .type(MANAGED_WEBSPACE) .bookingItem(HsBookingItemEntity.builder() @@ -81,7 +81,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { @Test void validatesIdentifierAndReferencedEntities() { // given - final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); + final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder() .type(MANAGED_WEBSPACE) .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.MANAGED_WEBSPACE).build()) @@ -99,7 +99,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { @Test void validatesUnknownProperties() { // given - final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); + final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder() .type(MANAGED_WEBSPACE) .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.MANAGED_WEBSPACE).build()) @@ -120,7 +120,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { @Test void validatesValidEntity() { // given - final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); + final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder() .type(MANAGED_WEBSPACE) .bookingItem(HsBookingItemEntity.builder() @@ -145,7 +145,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest { @Test void rejectsInvalidEntityReferences() { // given - final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); + final var validator = HostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE); final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder() .type(MANAGED_WEBSPACE) .bookingItem(HsBookingItemEntity.builder() 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 ce1b5a1d..de6af2fa 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 @@ -47,7 +47,7 @@ class HsUnixUserHostingAssetValidatorUnitTest { void preparesUnixUser() { // given final var unixUserHostingAsset = GIVEN_VALID_UNIX_USER_HOSTING_ASSET; - final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType()); // when LinuxEtcShadowHashGenerator.nextSalt("Ly3LbsArtL5u4EVt"); @@ -66,7 +66,7 @@ class HsUnixUserHostingAssetValidatorUnitTest { void validatesValidUnixUser() { // given final var unixUserHostingAsset = GIVEN_VALID_UNIX_USER_HOSTING_ASSET; - final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType()); // when final var result = Stream.concat( @@ -97,7 +97,7 @@ class HsUnixUserHostingAssetValidatorUnitTest { entry("password", "short") )) .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType()); // when final var result = validator.validateEntity(unixUserHostingAsset); @@ -124,7 +124,7 @@ class HsUnixUserHostingAssetValidatorUnitTest { .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).identifier("abc00").build()) .identifier("xyz99-temp") .build(); - final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType()); // when final var result = validator.validateEntity(unixUserHostingAsset); @@ -138,7 +138,7 @@ class HsUnixUserHostingAssetValidatorUnitTest { void revampsUnixUser() { // given final var unixUserHostingAsset = GIVEN_VALID_UNIX_USER_HOSTING_ASSET; - final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType()); + final var validator = HostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType()); // when LinuxEtcShadowHashGenerator.nextSalt("Ly3LbsArtL5u4EVt"); @@ -155,7 +155,7 @@ class HsUnixUserHostingAssetValidatorUnitTest { @Test void describesItsProperties() { // given - final var validator = HsHostingAssetEntityValidatorRegistry.forType(UNIX_USER); + final var validator = HostingAssetEntityValidatorRegistry.forType(UNIX_USER); // when final var props = validator.properties(); -- 2.39.5 From 65e01b12a142c197936b3f3836349c14adb85e86 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 9 Jul 2024 15:53:03 +0200 Subject: [PATCH 2/3] add HsDomainSetupHostingAssetValidator --- .../HostingAssetEntityValidatorRegistry.java | 1 + ...sDomainHttpSetupHostingAssetValidator.java | 56 +++++ .../HsDomainSetupHostingAssetValidator.java | 4 +- .../hs/validation/StringProperty.java | 11 +- .../hs/validation/ValidatableProperty.java | 4 +- .../HsHostingAssetControllerRestTest.java | 53 +++++ ...ingAssetPropsControllerAcceptanceTest.java | 3 +- ...gAssetEntityValidatorRegistryUnitTest.java | 3 +- ...DnsSetupHostingAssetValidatorUnitTest.java | 4 +- ...ttpSetupHostingAssetValidatorUnitTest.java | 197 ++++++++++++++++++ ...edServerHostingAssetValidatorUnitTest.java | 2 +- ...UnixUserHostingAssetValidatorUnitTest.java | 2 +- 12 files changed, 328 insertions(+), 12 deletions(-) create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidator.java create mode 100644 src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java index 437f5c9a..62e47dec 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java @@ -22,6 +22,7 @@ public class HostingAssetEntityValidatorRegistry { register(EMAIL_ALIAS, new HsEMailAliasHostingAssetValidator()); register(DOMAIN_SETUP, new HsDomainSetupHostingAssetValidator()); register(DOMAIN_DNS_SETUP, new HsDomainDnsSetupHostingAssetValidator()); + register(DOMAIN_HTTP_SETUP, new HsDomainHttpSetupHostingAssetValidator()); } private static void register(final Enum type, final HsEntityValidator validator) { diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidator.java new file mode 100644 index 00000000..9065f7d9 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidator.java @@ -0,0 +1,56 @@ +package net.hostsharing.hsadminng.hs.hosting.asset.validators; + +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; + +import java.util.regex.Pattern; + +import static java.util.Optional.ofNullable; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_HTTP_SETUP; +import static net.hostsharing.hsadminng.hs.validation.ArrayProperty.arrayOf; +import static net.hostsharing.hsadminng.hs.validation.BooleanProperty.booleanProperty; +import static net.hostsharing.hsadminng.hs.validation.StringProperty.stringProperty; + +class HsDomainHttpSetupHostingAssetValidator extends HostingAssetEntityValidator { + + public static final String IDENTIFIER_SUFFIX = "|HTTP"; + public static final String FILESYSTEM_PATH = "^/"; + public static final String PARTIAL_DOMAIN_NAME_REGEX = "(?!-)[A-Za-z0-9-]{1,63}(? entity.setIdentifier(pa.getIdentifier() + IDENTIFIER_SUFFIX)); + } + } +} diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java index 60ad9283..483472a7 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java @@ -9,7 +9,7 @@ import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMA class HsDomainSetupHostingAssetValidator extends HostingAssetEntityValidator { - public static final String DOMAIN_NAME_REGEX = "^((?!-)[A-Za-z0-9-]{1,63}(?> extends ValidatableProp protected static final String[] KEY_ORDER = Array.join( ValidatableProperty.KEY_ORDER_HEAD, - Array.of("matchesRegEx", "minLength", "maxLength"), + Array.of("matchesRegEx", "minLength", "maxLength", "provided"), ValidatableProperty.KEY_ORDER_TAIL, Array.of("undisclosed")); + private String[] provided; private Pattern[] matchesRegEx; private Integer minLength; private Integer maxLength; @@ -50,6 +51,12 @@ public class StringProperty

> extends ValidatableProp return self(); } + /// predifined values, similar to fixed values in a combobox + public P provided(final String... provided) { + this.provided = provided; + return self(); + } + /** * The property value is not disclosed in error messages. * @@ -70,7 +77,7 @@ public class StringProperty

> extends ValidatableProp } if (matchesRegEx != null && stream(matchesRegEx).map(p -> p.matcher(propValue)).noneMatch(Matcher::matches)) { - result.add(propertyName + "' is expected to match any of " + Arrays.toString(matchesRegEx) + " but " + display(propValue) + " does not match any"); + result.add(propertyName + "' is expected to match any of " + Arrays.toString(matchesRegEx) + " but " + display(propValue) + " does not match" + (matchesRegEx.length>1?" any":"")); } if (isReadOnly() && propValue != null) { result.add(propertyName + "' is readonly but given as " + display(propValue)); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/validation/ValidatableProperty.java b/src/main/java/net/hostsharing/hsadminng/hs/validation/ValidatableProperty.java index 346ee08b..01daf6aa 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/validation/ValidatableProperty.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/validation/ValidatableProperty.java @@ -182,8 +182,8 @@ protected void setDeferredInit(final Function[], T[]> //noinspection unchecked validate(result, (T) propValue, propsProvider); } else { - result.add(propertyName + "' is expected to be of type " + type + ", " + - "but is of type '" + propValue.getClass().getSimpleName() + "'"); + result.add(propertyName + "' is expected to be of type " + type.getSimpleName() + ", " + + "but is of type " + propValue.getClass().getSimpleName() + ""); } } return result; 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 eed85585..bdaacf04 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 @@ -246,6 +246,59 @@ public class HsHostingAssetControllerRestTest { } } ] + """), + DOMAIN_HTTP_SETUP( + List.of( + HsHostingAssetEntity.builder() + .type(HsHostingAssetType.DOMAIN_HTTP_SETUP) + .identifier("example.org") + .caption("some fake Domain-HTTP-Setup") + .config(Map.ofEntries( + entry("htdocsfallback", false), + entry("indexes", false), + entry("cgi", false), + entry("passenger", false), + entry("passenger-errorpage", true), + entry("fastcgi", false), + entry("autoconfig", false), + entry("greylisting", false), + entry("includes", false), + entry("letsencrypt", false), + entry("multiviews", false), + entry("fcgi-php-bin", "/usr/lib/cgi-bin/php8"), + entry("passenger-nodejs", "/usr/bin/node-js7"), + entry("passenger-python", "/usr/bin/python6"), + entry("passenger-ruby", "/usr/bin/ruby5"), + entry("subdomains", Array.of("www", "test1", "test2")) + )) + .build()), + """ + [ + { + "type": "DOMAIN_HTTP_SETUP", + "identifier": "example.org", + "caption": "some fake Domain-HTTP-Setup", + "alarmContact": null, + "config": { + "autoconfig": false, + "cgi": false, + "fastcgi": false, + "greylisting": false, + "htdocsfallback": false, + "includes": false, + "indexes": false, + "letsencrypt": false, + "multiviews": false, + "passenger": false, + "passenger-errorpage": true, + "passenger-nodejs": "/usr/bin/node-js7", + "passenger-python": "/usr/bin/python6", + "passenger-ruby": "/usr/bin/ruby5", + "fcgi-php-bin": "/usr/lib/cgi-bin/php8", + "subdomains": ["www","test1","test2"] + } + } + ] """); final HsHostingAssetType assetType; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java index bd571075..dd4afc09 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java @@ -37,7 +37,8 @@ class HsHostingAssetPropsControllerAcceptanceTest { "UNIX_USER", "EMAIL_ALIAS", "DOMAIN_SETUP", - "DOMAIN_DNS_SETUP" + "DOMAIN_DNS_SETUP", + "DOMAIN_HTTP_SETUP" ] """)); // @formatter:on diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java index a3ac41f3..daf0704f 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java @@ -35,7 +35,8 @@ class HostingAssetEntityValidatorRegistryUnitTest { HsHostingAssetType.UNIX_USER, HsHostingAssetType.EMAIL_ALIAS, HsHostingAssetType.DOMAIN_SETUP, - HsHostingAssetType.DOMAIN_DNS_SETUP + HsHostingAssetType.DOMAIN_DNS_SETUP, + HsHostingAssetType.DOMAIN_HTTP_SETUP ); } } 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 c858a2f6..715138ec 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 @@ -146,7 +146,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { } @Test - void recectsInvalidProperties() { + void rejectsInvalidProperties() { // given final var mangedServerHostingAssetEntity = validEntityBuilder() .config(Map.ofEntries( @@ -163,7 +163,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( - "'DOMAIN_DNS_SETUP:example.org|DNS.config.TTL' is expected to be of type class java.lang.Integer, but is of type 'String'", + "'DOMAIN_DNS_SETUP:example.org|DNS.config.TTL' is expected to be of type Integer, but is of type String", "'DOMAIN_DNS_SETUP:example.org|DNS.config.user-RR' is expected to match any of [([a-z0-9\\.-]+|@)\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*IN\\s+[A-Z]+\\s+[^;].*(;.*)*, ([a-z0-9\\.-]+|@)\\s+IN\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*[A-Z]+\\s+[^;].*(;.*)*] but '@ 1814400 IN 1814400 BAD1 TTL only allowed once' does not match any", "'DOMAIN_DNS_SETUP:example.org|DNS.config.user-RR' is expected to match any of [([a-z0-9\\.-]+|@)\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*IN\\s+[A-Z]+\\s+[^;].*(;.*)*, ([a-z0-9\\.-]+|@)\\s+IN\\s+(([1-9][0-9]*[mMhHdDwW]{0,1})+\\s+)*[A-Z]+\\s+[^;].*(;.*)*] but 'www BAD1 Record-Class missing / not enough columns' does not match any"); } 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 new file mode 100644 index 00000000..fa75cded --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java @@ -0,0 +1,197 @@ +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.mapper.Array; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static java.util.Map.entry; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_HTTP_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.UNIX_USER; +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; +import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_REGEX_IN; +import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_REGEX_NAME; +import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_REGEX_TTL; +import static org.assertj.core.api.Assertions.assertThat; + +class HsDomainHttpSetupHostingAssetValidatorUnitTest { + + static final HsHostingAssetEntity validDomainSetupEntity = HsHostingAssetEntity.builder() + .type(DOMAIN_SETUP) + .identifier("example.org") + .build(); + + static HsHostingAssetEntityBuilder validEntityBuilder() { + return HsHostingAssetEntity.builder() + .type(DOMAIN_HTTP_SETUP) + .parentAsset(validDomainSetupEntity) + .assignedToAsset(HsHostingAssetEntity.builder().type(UNIX_USER).build()) + .identifier("example.org|HTTP") + .config(Map.ofEntries( + entry("passenger-errorpage", true), + entry("subdomains", Array.of("www", "test") + ) + )); + } + + @Test + void containsExpectedProperties() { + // when + final var validator = HostingAssetEntityValidatorRegistry.forType(DOMAIN_HTTP_SETUP); + + // then + assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder( + "{type=boolean, propertyName=htdocsfallback, defaultValue=true}", + "{type=boolean, propertyName=indexes, defaultValue=true}", + "{type=boolean, propertyName=cgi, defaultValue=true}", + "{type=boolean, propertyName=passenger, defaultValue=true}", + "{type=boolean, propertyName=passenger-errorpage}", + "{type=boolean, propertyName=fastcgi, defaultValue=true}", + "{type=boolean, propertyName=autoconfig, defaultValue=true}", + "{type=boolean, propertyName=greylisting, defaultValue=true}", + "{type=boolean, propertyName=includes, defaultValue=true}", + "{type=boolean, propertyName=letsencrypt, defaultValue=true}", + "{type=boolean, propertyName=multiviews, defaultValue=true}", + "{type=string, propertyName=fcgi-php-bin, matchesRegEx=[^/], provided=[/usr/lib/cgi-bin/php], defaultValue=/usr/lib/cgi-bin/php}", + "{type=string, propertyName=passenger-nodejs, matchesRegEx=[^/], provided=[/usr/bin/node], defaultValue=/usr/bin/node}", + "{type=string, propertyName=passenger-python, matchesRegEx=[^/], provided=[/usr/bin/python3], defaultValue=/usr/bin/python3}", + "{type=string, propertyName=passenger-ruby, matchesRegEx=[^/], provided=[/usr/bin/ruby], defaultValue=/usr/bin/ruby}", + "{type=string[], propertyName=subdomains, elementsOf={type=string, propertyName=subdomains, matchesRegEx=[(?!-)[A-Za-z0-9-]{1,63}(? Date: Wed, 10 Jul 2024 10:12:09 +0200 Subject: [PATCH 3/3] amendmends after code-review --- ...ttpSetupHostingAssetValidatorUnitTest.java | 34 ------------------- 1 file changed, 34 deletions(-) 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 fa75cded..c84dd2b1 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 @@ -14,12 +14,6 @@ import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMA import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.UNIX_USER; -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; -import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_REGEX_IN; -import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_REGEX_NAME; -import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_REGEX_TTL; import static org.assertj.core.api.Assertions.assertThat; class HsDomainHttpSetupHostingAssetValidatorUnitTest { @@ -166,32 +160,4 @@ class HsDomainHttpSetupHostingAssetValidatorUnitTest { "'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match any of [(?!-)[A-Za-z0-9-]{1,63}(?