add Mermaid graph generator for HostingAssetType structure (WIP)

This commit is contained in:
Michael Hoennig 2024-07-05 16:57:30 +02:00
parent f6d66d5712
commit de4870621a
13 changed files with 346 additions and 163 deletions

View File

@ -0,0 +1,77 @@
### HostingAsset Type Structure
```mermaid
%%{init:{'flowchart':{'htmlLabels':false}}}%%
flowchart RL
subgraph Booking
style Booking fill:white,stroke:white,stroke-width:0px
BI:PRIVATE_CLOUD
BI:CLOUD_SERVER
BI:MANAGED_SERVER
BI:MANAGED_WEBSPACE
BI:DOMAIN_DNS_SETUP
BI:DOMAIN_EMAIL_SUBMISSION_SETUP
end
%% subgraph Hosting
subgraph Server[ ]
style Server fill:white,stroke:white,stroke-width:0px
HA:CLOUD_SERVER
HA:MANAGED_SERVER
HA:IP_NUMBER
end
subgraph Domain[ ]
style Domain fill:white,stroke:white,stroke-width:0px
HA:DOMAIN_DNS_SETUP
HA:DOMAIN_HTTP_SETUP
HA:DOMAIN_EMAIL_SUBMISSION_SETUP
HA:DOMAIN_EMAIL_MAILBOX_SETUP
HA:EMAIL_ADDRESS
end
subgraph Webspace[ ]
style Webspace fill:white,stroke:white,stroke-width:0px
HA:MANAGED_WEBSPACE
HA:UNIX_USER
HA:EMAIL_ALIAS
end
%% end
style HA:CLOUD_SERVER fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:MANAGED_SERVER fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:MANAGED_WEBSPACE fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:UNIX_USER fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:DOMAIN_DNS_SETUP fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:DOMAIN_HTTP_SETUP fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:DOMAIN_EMAIL_SUBMISSION_SETUP fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:DOMAIN_EMAIL_MAILBOX_SETUP fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:EMAIL_ALIAS fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:EMAIL_ADDRESS fill:#99bcdb,stroke:#274d6e,stroke-width:4px
style HA:IP_NUMBER fill:#99bcdb,stroke:#274d6e,stroke-width:4px
BI:CLOUD_SERVER --> BI:PRIVATE_CLOUD
BI:MANAGED_SERVER --> BI:PRIVATE_CLOUD
BI:MANAGED_WEBSPACE --> BI:MANAGED_SERVER
HA:CLOUD_SERVER ==> BI:CLOUD_SERVER
HA:MANAGED_SERVER ==> BI:MANAGED_SERVER
HA:MANAGED_WEBSPACE ==> BI:MANAGED_WEBSPACE
HA:MANAGED_WEBSPACE ==o HA:MANAGED_SERVER
HA:UNIX_USER ==> HA:MANAGED_WEBSPACE
HA:DOMAIN_DNS_SETUP ==> BI:DOMAIN_DNS_SETUP
HA:DOMAIN_HTTP_SETUP ==> HA:MANAGED_WEBSPACE
HA:DOMAIN_HTTP_SETUP -.-> HA:UNIX_USER
HA:DOMAIN_EMAIL_SUBMISSION_SETUP ==> BI:DOMAIN_EMAIL_SUBMISSION_SETUP
HA:DOMAIN_EMAIL_SUBMISSION_SETUP -.-o HA:MANAGED_WEBSPACE
HA:DOMAIN_EMAIL_MAILBOX_SETUP ==> HA:MANAGED_WEBSPACE
HA:EMAIL_ALIAS ==> HA:MANAGED_WEBSPACE
HA:EMAIL_ADDRESS ==> HA:DOMAIN_EMAIL_MAILBOX_SETUP
HA:IP_NUMBER -.-> HA:CLOUD_SERVER
HA:IP_NUMBER -.-> HA:MANAGED_SERVER
HA:IP_NUMBER -.-> HA:MANAGED_WEBSPACE
```
This code generated was by HsHostingAssetType.main, do not amend manually.

View File

@ -1,8 +1,37 @@
package net.hostsharing.hsadminng.hs.booking.item; package net.hostsharing.hsadminng.hs.booking.item;
public enum HsBookingItemType { import java.util.List;
import static java.util.Optional.ofNullable;
public enum HsBookingItemType implements Node {
PRIVATE_CLOUD, PRIVATE_CLOUD,
CLOUD_SERVER, CLOUD_SERVER(PRIVATE_CLOUD),
MANAGED_SERVER, MANAGED_SERVER(PRIVATE_CLOUD),
MANAGED_WEBSPACE MANAGED_WEBSPACE(MANAGED_SERVER),
DOMAIN_DNS_SETUP, // TODO.spec: experimental
DOMAIN_EMAIL_SUBMISSION_SETUP; // TODO.spec: experimental
private final HsBookingItemType parentItemType;
HsBookingItemType() {
this.parentItemType = null;
}
HsBookingItemType(final HsBookingItemType parentItemType) {
this.parentItemType = parentItemType;
}
@Override
public List<String> edges() {
return ofNullable(parentItemType)
.map(p -> (nodeName() + " --> " + p.nodeName()))
.stream().toList();
}
@Override
public String nodeName() {
return "BI:" + name();
}
} }

View File

@ -0,0 +1,9 @@
package net.hostsharing.hsadminng.hs.booking.item;
import java.util.List;
public interface Node {
String nodeName();
List<String> edges();
}

View File

@ -8,7 +8,7 @@ import java.util.List;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static java.util.Optional.ofNullable; import static java.util.Optional.ofNullable;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.EMAIL_ADDRESS; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.EMAIL_ADDRESS;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_DATABASE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_DATABASE;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_USER; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_USER;
@ -88,7 +88,7 @@ class HsManagedWebspaceBookingItemValidator extends HsBookingItemEntityValidator
return (final HsBookingItemEntity entity, final IntegerProperty prop, final Integer factor) -> { return (final HsBookingItemEntity entity, final IntegerProperty prop, final Integer factor) -> {
final var unixUserCount = ofNullable(entity.getRelatedHostingAsset()) final var unixUserCount = ofNullable(entity.getRelatedHostingAsset())
.map(ha -> ha.getSubHostingAssets().stream() .map(ha -> ha.getSubHostingAssets().stream()
.filter(bi -> bi.getType() == DOMAIN_EMAIL_SETUP) .filter(bi -> bi.getType() == DOMAIN_EMAIL_MAILBOX_SETUP)
.flatMap(domainEMailSetup -> domainEMailSetup.getSubHostingAssets().stream() .flatMap(domainEMailSetup -> domainEMailSetup.getSubHostingAssets().stream()
.filter(subAsset -> subAsset.getType()==EMAIL_ADDRESS)) .filter(subAsset -> subAsset.getType()==EMAIL_ADDRESS))
.count()) .count())

View File

@ -1,33 +1,131 @@
package net.hostsharing.hsadminng.hs.hosting.asset; package net.hostsharing.hsadminng.hs.hosting.asset;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType;
import net.hostsharing.hsadminng.hs.booking.item.Node;
public enum HsHostingAssetType { import java.io.IOException;
CLOUD_SERVER, // named e.g. vm1234 import java.nio.file.Files;
MANAGED_SERVER, // named e.g. vm1234 import java.nio.file.Path;
MANAGED_WEBSPACE(MANAGED_SERVER), // named eg. xyz00 import java.nio.file.StandardOpenOption;
UNIX_USER(MANAGED_WEBSPACE), // named e.g. xyz00-abc import java.util.Collection;
DOMAIN_SETUP, // named e.g. example.org import java.util.List;
DOMAIN_DNS_SETUP(DOMAIN_SETUP), // named e.g. example.org import java.util.Set;
DOMAIN_HTTP_SETUP(DOMAIN_SETUP), // named e.g. example.org
DOMAIN_EMAIL_SETUP(DOMAIN_SETUP), // named e.g. example.org import static java.util.Arrays.stream;
import static java.util.stream.Collectors.joining;
import static net.hostsharing.hsadminng.hs.hosting.asset.EntityTypeRelation.*;
public enum HsHostingAssetType implements Node {
CLOUD_SERVER( // named e.g. vm1234
inGroup("Server"),
requires(HsBookingItemType.CLOUD_SERVER)),
MANAGED_SERVER( // named e.g. vm1234
inGroup("Server"),
requires(HsBookingItemType.MANAGED_SERVER)),
MANAGED_WEBSPACE( // named eg. xyz00
inGroup("Webspace"),
requires(HsBookingItemType.MANAGED_WEBSPACE),
optionalParent(MANAGED_SERVER)),
UNIX_USER( // named e.g. xyz00-abc
inGroup("Webspace"),
requiredParent(MANAGED_WEBSPACE)),
// DOMAIN_SETUP( // named e.g. example.org
// inGroup("Domain")
// ),
DOMAIN_DNS_SETUP( // named e.g. example.org
inGroup("Domain"),
requires(HsBookingItemType.DOMAIN_DNS_SETUP)),
DOMAIN_HTTP_SETUP( // named e.g. example.org
inGroup("Domain"),
requiredParent(MANAGED_WEBSPACE),
assignedTo(UNIX_USER)),
DOMAIN_EMAIL_SUBMISSION_SETUP( // named e.g. example.org
inGroup("Domain"),
requires(HsBookingItemType.DOMAIN_EMAIL_SUBMISSION_SETUP),
optionallyAssignedTo(MANAGED_WEBSPACE)),
DOMAIN_EMAIL_MAILBOX_SETUP( // named e.g. example.org
inGroup("Domain"),
requiredParent(MANAGED_WEBSPACE)),
// TODO.spec: SECURE_MX // TODO.spec: SECURE_MX
EMAIL_ALIAS(MANAGED_WEBSPACE), // named e.g. xyz00-abc
EMAIL_ADDRESS(DOMAIN_EMAIL_SETUP), // named e.g. sample@example.org
PGSQL_USER(MANAGED_WEBSPACE), // named e.g. xyz00_abc
PGSQL_DATABASE(MANAGED_WEBSPACE), // named e.g. xyz00_abc, TODO.spec: or PGSQL_USER?
MARIADB_USER(MANAGED_WEBSPACE), // named e.g. xyz00_abc
MARIADB_DATABASE(MANAGED_WEBSPACE); // named e.g. xyz00_abc, TODO.spec: or MARIADB_USER?
EMAIL_ALIAS( // named e.g. xyz00-abc
inGroup("Webspace"),
requiredParent(MANAGED_WEBSPACE)),
public final HsHostingAssetType parentAssetType; EMAIL_ADDRESS( // named e.g. sample@example.org
inGroup("Domain"),
requiredParent(DOMAIN_EMAIL_MAILBOX_SETUP)),
HsHostingAssetType(final HsHostingAssetType parentAssetType) { PGSQL_INSTANCE( // TODO.spec: identifier to be specified
this.parentAssetType = parentAssetType; inGroup("PostgreSQL"),
requiredParent(MANAGED_SERVER)),
PGSQL_USER( // named e.g. xyz00_abc
inGroup("PostgreSQL"),
requiredParent(PGSQL_INSTANCE),
assignedTo(MANAGED_WEBSPACE)),
PGSQL_DATABASE( // named e.g. xyz00_abc
inGroup("PostgreSQL"),
requiredParent(MANAGED_WEBSPACE), // TODO.spec: or PGSQL_USER?
assignedTo(PGSQL_INSTANCE)), // TODO.spec: or swapping parent+assignedTo?
MARIADB_INSTANCE( // TODO.spec: identifier to be specified
inGroup("MariaDB"),
requiredParent(MANAGED_SERVER)), // TODO.spec: or MANAGED_WEBSPACE?
MARIADB_USER( // named e.g. xyz00_abc
inGroup("MariaDB"),
requiredParent(MARIADB_INSTANCE),
assignedTo(MANAGED_WEBSPACE)),
MARIADB_DATABASE( // named e.g. xyz00_abc
inGroup("MariaDB"),
requiredParent(MANAGED_WEBSPACE), // TODO.spec: or MARIADB_USER?
assignedTo(MARIADB_INSTANCE)), // TODO.spec: or swapping parent+assignedTo?
IP_NUMBER(
inGroup("Server"),
assignedTo(CLOUD_SERVER),
assignedTo(MANAGED_SERVER),
assignedTo(MANAGED_WEBSPACE)
);
private final String groupName;
private final EntityTypeRelation<?>[] relations;
HsHostingAssetType(
final String groupName,
final EntityTypeRelation<?>... relations
) {
this.groupName = groupName;
this.relations = relations;
} }
HsHostingAssetType() { /// just syntactic sugar
this(null); private static String inGroup(final String groupName) {
return groupName;
}
@Override
public List<String> edges() {
return stream(relations)
.map(r -> nodeName() + r.edge + r.relatedType.nodeName())
.toList();
}
@Override
public String nodeName() {
return "HA:" + name();
} }
public static <T extends Enum<?>> HsHostingAssetType of(final T value) { public static <T extends Enum<?>> HsHostingAssetType of(final T value) {
@ -37,4 +135,109 @@ public enum HsHostingAssetType {
static String asString(final HsHostingAssetType type) { static String asString(final HsHostingAssetType type) {
return type == null ? null : type.name(); return type == null ? null : type.name();
} }
public static void main(final String[] args) throws IOException {
final var includedHostingGroups = Set.of("Domain", "Server", "Webspace");
final String bookingNodes = stream(HsBookingItemType.values())
.map(t -> " " + t.nodeName())
.collect(joining("\n"));
final String hostingGroups = includedHostingGroups.stream()
.map(HsHostingAssetType::generateGroup)
.collect(joining("\n"));
final String hostingAssetNodeStyles = stream(HsHostingAssetType.values())
.filter(t -> includedHostingGroups.contains(t.groupName))
.map(n -> "style HA:"+n.name()+" fill:#99bcdb,stroke:#274d6e,stroke-width:4px")
.collect(joining("\n"));
final String bookingItemEdges = stream(HsBookingItemType.values())
.map(HsBookingItemType::edges)
.flatMap(Collection::stream)
.collect(joining("\n"));
final String hostingAssetEdges = stream(HsHostingAssetType.values())
.filter(t -> includedHostingGroups.contains(t.groupName))
.map(HsHostingAssetType::edges)
.flatMap(Collection::stream)
.collect(joining("\n"));
Files.writeString(
Path.of("doc/hs-hosting-asset-type-structure.md"),
"""
### HostingAsset Type Structure
```mermaid
%%{init:{'flowchart':{'htmlLabels':false}}}%%
flowchart RL
subgraph Booking
style Booking fill:white,stroke:white,stroke-width:0px
%{bookingNodes}
end
%% subgraph Hosting
%{hostingGroups}
%% end
%{hostingAssetNodeStyles}
%{bookingItemEdges}
%{hostingAssetEdges}
```
This code generated was by %{this}.main, do not amend manually.
"""
.replace("%{this}", HsHostingAssetType.class.getSimpleName())
.replace("%{bookingNodes}", bookingNodes)
.replace("%{hostingGroups}", hostingGroups)
.replace("%{hostingAssetNodeStyles}", hostingAssetNodeStyles)
.replace("%{bookingItemEdges}", bookingItemEdges)
.replace("%{hostingAssetEdges}", hostingAssetEdges),
StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
}
private static String generateGroup(final String group) {
return "subgraph " + group + "[ ]\n"
+ " style " + group + " fill:white,stroke:white,stroke-width:0px\n"
+ stream(HsHostingAssetType.values())
.filter(t -> t.groupName.equals(group))
.map(HsHostingAssetType::nodeName)
.collect(joining(" \n"))
+ "\nend\n";
}
}
enum TypeRelationType {
OPTIONAL, REQUIRED
}
class EntityTypeRelation<T extends Node> {
final String edge;
final TypeRelationType relationType;
final T relatedType;
EntityTypeRelation(final String edge, final TypeRelationType required, final T relatedType) {
this.edge = edge;
this.relationType = required;
this.relatedType = relatedType;
}
static EntityTypeRelation<HsBookingItemType> requires(final HsBookingItemType bookingItemType) {
return new EntityTypeRelation<>(" ==> ", TypeRelationType.REQUIRED, bookingItemType);
}
static EntityTypeRelation<HsHostingAssetType> optionalParent(final HsHostingAssetType hostingAssetType) {
return new EntityTypeRelation<>(" ==o ", TypeRelationType.OPTIONAL, hostingAssetType);
}
static EntityTypeRelation<HsHostingAssetType> requiredParent(final HsHostingAssetType hostingAssetType) {
return new EntityTypeRelation<>(" ==> ", TypeRelationType.REQUIRED, hostingAssetType);
}
static EntityTypeRelation<HsHostingAssetType> assignedTo(final HsHostingAssetType hostingAssetType) {
return new EntityTypeRelation<>(" -.-> ", TypeRelationType.REQUIRED, hostingAssetType);
}
static EntityTypeRelation<HsHostingAssetType> optionallyAssignedTo(final HsHostingAssetType hostingAssetType) {
return new EntityTypeRelation<>(" -.-o ", TypeRelationType.OPTIONAL, hostingAssetType);
}
} }

View File

@ -33,7 +33,7 @@ class HsDomainDnsSetupHostingAssetValidator extends HsHostingAssetEntityValidato
HsDomainDnsSetupHostingAssetValidator() { HsDomainDnsSetupHostingAssetValidator() {
super( BookingItem.mustBeNull(), super( BookingItem.mustBeNull(),
ParentAsset.mustBeOfType(HsHostingAssetType.DOMAIN_SETUP), ParentAsset.mustBeNull(),
AssignedToAsset.mustBeNull(), AssignedToAsset.mustBeNull(),
AlarmContact.isOptional(), AlarmContact.isOptional(),

View File

@ -20,7 +20,6 @@ public class HsHostingAssetEntityValidatorRegistry {
register(MANAGED_WEBSPACE, new HsManagedWebspaceHostingAssetValidator()); register(MANAGED_WEBSPACE, new HsManagedWebspaceHostingAssetValidator());
register(UNIX_USER, new HsUnixUserHostingAssetValidator()); register(UNIX_USER, new HsUnixUserHostingAssetValidator());
register(EMAIL_ALIAS, new HsEMailAliasHostingAssetValidator()); register(EMAIL_ALIAS, new HsEMailAliasHostingAssetValidator());
register(DOMAIN_SETUP, new HsDomainSetupHostingAssetValidator());
register(DOMAIN_DNS_SETUP, new HsDomainDnsSetupHostingAssetValidator()); register(DOMAIN_DNS_SETUP, new HsDomainDnsSetupHostingAssetValidator());
} }

View File

@ -152,7 +152,7 @@ class HsManagedServerBookingItemValidatorUnitTest {
"xyz00_%c%c", "xyz00_%c%c",
2, HsHostingAssetType.MARIADB_DATABASE 2, HsHostingAssetType.MARIADB_DATABASE
), ),
generateDomainEmailSetupsWithEMailAddresses(26, HsHostingAssetType.DOMAIN_EMAIL_SETUP, generateDomainEmailSetupsWithEMailAddresses(26, HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP,
"%c%c.example.com", "%c%c.example.com",
10, HsHostingAssetType.EMAIL_ADDRESS 10, HsHostingAssetType.EMAIL_ADDRESS
) )

View File

@ -186,24 +186,6 @@ public class HsHostingAssetControllerRestTest {
} }
] ]
"""), """),
DOMAIN_SETUP(
List.of(
HsHostingAssetEntity.builder()
.type(HsHostingAssetType.DOMAIN_SETUP)
.identifier("example.org")
.caption("some fake Domain-Setup")
.build()),
"""
[
{
"type": "DOMAIN_SETUP",
"identifier": "example.org",
"caption": "some fake Domain-Setup",
"alarmContact": null,
"config": {}
}
]
"""),
DOMAIN_DNS_SETUP( DOMAIN_DNS_SETUP(
List.of( List.of(
HsHostingAssetEntity.builder() HsHostingAssetEntity.builder()

View File

@ -27,7 +27,6 @@ import java.util.Map;
import static java.util.Map.entry; import static java.util.Map.entry;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.CLOUD_SERVER; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.CLOUD_SERVER;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_SERVER; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_SERVER;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE;
import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.distinctGrantDisplaysOf; import static net.hostsharing.hsadminng.rbac.rbacgrant.RawRbacGrantEntity.distinctGrantDisplaysOf;
@ -167,7 +166,6 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
final var result = attempt(em, () -> { final var result = attempt(em, () -> {
final var newAsset = HsHostingAssetEntity.builder() final var newAsset = HsHostingAssetEntity.builder()
.caption("some new domain setup") .caption("some new domain setup")
.type(DOMAIN_SETUP)
.identifier("example.org") .identifier("example.org")
.build(); .build();
return toCleanup(assetRepo.save(newAsset)); return toCleanup(assetRepo.save(newAsset));

View File

@ -11,7 +11,6 @@ import java.util.Map;
import static java.util.Map.entry; import static java.util.Map.entry;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_DNS_SETUP; 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.validators.HsDomainDnsSetupHostingAssetValidator.RR_COMMENT; 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_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_RECORD_TYPE;
@ -23,7 +22,6 @@ import static org.assertj.core.api.Assertions.assertThat;
class HsDomainDnsSetupHostingAssetValidatorUnitTest { class HsDomainDnsSetupHostingAssetValidatorUnitTest {
static final HsHostingAssetEntity validDomainSetupEntity = HsHostingAssetEntity.builder() static final HsHostingAssetEntity validDomainSetupEntity = HsHostingAssetEntity.builder()
.type(DOMAIN_SETUP)
.identifier("example.org") .identifier("example.org")
.build(); .build();

View File

@ -1,111 +0,0 @@
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 org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import java.util.Map;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.CLOUD_SERVER;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP;
import static org.assertj.core.api.Assertions.assertThat;
class HsDomainSetupHostingAssetValidatorUnitTest {
static HsHostingAssetEntityBuilder validEntityBuilder() {
return HsHostingAssetEntity.builder()
.type(DOMAIN_SETUP)
.identifier("example.org");
}
enum InvalidDomainNameIdentifier {
EMPTY(""),
TOO_LONG("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456890123456789.de"),
DASH_AT_BEGINNING("-example.com"),
DOT_AT_BEGINNING(".example.com"),
DOT_AT_END("example.com.");
final String domainName;
InvalidDomainNameIdentifier(final String domainName) {
this.domainName = domainName;
}
}
@ParameterizedTest
@EnumSource(InvalidDomainNameIdentifier.class)
void rejectsInvalidIdentifier(final InvalidDomainNameIdentifier testCase) {
// given
final var givenEntity = validEntityBuilder().identifier(testCase.domainName).build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
final var result = validator.validateEntity(givenEntity);
// then
assertThat(result).containsExactly(
"'identifier' expected to match '^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}', but is '"+testCase.domainName+"'"
);
}
enum ValidDomainNameIdentifier {
SIMPLE("exampe.org"),
MAX_LENGTH("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz01234568901.de"),
WITH_DASH("example-test.com"),
SUBDOMAIN("test.example.com");
final String domainName;
ValidDomainNameIdentifier(final String domainName) {
this.domainName = domainName;
}
}
@ParameterizedTest
@EnumSource(ValidDomainNameIdentifier.class)
void acceptsValidIdentifier(final ValidDomainNameIdentifier testCase) {
// given
final var givenEntity = validEntityBuilder().identifier(testCase.domainName).build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
// when
final var result = validator.validateEntity(givenEntity);
// then
assertThat(result).isEmpty();
}
@Test
void containsNoProperties() {
// when
final var validator = HsHostingAssetEntityValidatorRegistry.forType(CLOUD_SERVER);
// then
assertThat(validator.properties()).map(Map::toString).isEmpty();
}
@Test
void validatesReferencedEntities() {
// given
final var mangedServerHostingAssetEntity = validEntityBuilder()
.parentAsset(HsHostingAssetEntity.builder().build())
.assignedToAsset(HsHostingAssetEntity.builder().build())
.bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build())
.build();
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
// when
final var result = validator.validateEntity(mangedServerHostingAssetEntity);
// then
assertThat(result).containsExactlyInAnyOrder(
"'DOMAIN_SETUP:example.org.bookingItem' must be null but is set to D-???????-?:null",
"'DOMAIN_SETUP:example.org.parentAsset' must be null but is set to D-???????-?:null",
"'DOMAIN_SETUP:example.org.assignedToAsset' must be null but is set to D-???????-?:null");
}
}

View File

@ -34,7 +34,6 @@ class HsHostingAssetEntityValidatorRegistryUnitTest {
HsHostingAssetType.MANAGED_WEBSPACE, HsHostingAssetType.MANAGED_WEBSPACE,
HsHostingAssetType.UNIX_USER, HsHostingAssetType.UNIX_USER,
HsHostingAssetType.EMAIL_ALIAS, HsHostingAssetType.EMAIL_ALIAS,
HsHostingAssetType.DOMAIN_SETUP,
HsHostingAssetType.DOMAIN_DNS_SETUP HsHostingAssetType.DOMAIN_DNS_SETUP
); );
} }