HostingAsset-Hierarchie spec in enum HsHostingAssetType and generates PlantUML (#72)
Co-authored-by: Michael Hoennig <michael@hoennig.de> Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/72 Reviewed-by: Timotheus Pokorra <timotheus.pokorra@hostsharing.net>
This commit is contained in:
@@ -40,8 +40,10 @@ public class ArchitectureTest {
|
||||
"..test.pac",
|
||||
"..test.dom",
|
||||
"..context",
|
||||
"..hash",
|
||||
"..generated..",
|
||||
"..persistence..",
|
||||
"..system..",
|
||||
"..validation..",
|
||||
"..hs.office.bankaccount",
|
||||
"..hs.office.contact",
|
||||
@@ -110,6 +112,13 @@ public class ArchitectureTest {
|
||||
.should().onlyDependOnClassesThat()
|
||||
.resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG);
|
||||
|
||||
@ArchTest
|
||||
@SuppressWarnings("unused")
|
||||
public static final ArchRule hashPackageRule = classes()
|
||||
.that().resideInAPackage("..hash..")
|
||||
.should().onlyDependOnClassesThat()
|
||||
.resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG);
|
||||
|
||||
@ArchTest
|
||||
@SuppressWarnings("unused")
|
||||
public static final ArchRule errorsPackageRule = classes()
|
||||
@@ -117,6 +126,13 @@ public class ArchitectureTest {
|
||||
.should().onlyDependOnClassesThat()
|
||||
.resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG);
|
||||
|
||||
@ArchTest
|
||||
@SuppressWarnings("unused")
|
||||
public static final ArchRule systemPackageRule = classes()
|
||||
.that().resideInAPackage("..system..")
|
||||
.should().onlyDependOnClassesThat()
|
||||
.resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG);
|
||||
|
||||
@ArchTest
|
||||
@SuppressWarnings("unused")
|
||||
public static final ArchRule testPackagesRule = classes()
|
||||
|
@@ -152,7 +152,7 @@ class HsManagedServerBookingItemValidatorUnitTest {
|
||||
"xyz00_%c%c",
|
||||
2, HsHostingAssetType.MARIADB_DATABASE
|
||||
),
|
||||
generateDomainEmailSetupsWithEMailAddresses(26, HsHostingAssetType.DOMAIN_EMAIL_SETUP,
|
||||
generateDomainEmailSetupsWithEMailAddresses(26, HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP,
|
||||
"%c%c.example.com",
|
||||
10, HsHostingAssetType.EMAIL_ADDRESS
|
||||
)
|
||||
|
@@ -235,6 +235,47 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
assertThat(newUserUuid).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void globalAdmin_canAddTopLevelAsset() {
|
||||
|
||||
context.define("superuser-alex@hostsharing.net");
|
||||
|
||||
final var location = RestAssured // @formatter:off
|
||||
.given()
|
||||
.header("current-user", "superuser-alex@hostsharing.net")
|
||||
.contentType(ContentType.JSON)
|
||||
.body("""
|
||||
{
|
||||
"type": "DOMAIN_SETUP",
|
||||
"identifier": "example.com",
|
||||
"caption": "some unrelated domain-setup",
|
||||
"config": {}
|
||||
}
|
||||
""")
|
||||
.port(port)
|
||||
.when()
|
||||
.post("http://localhost/api/hs/hosting/assets")
|
||||
.then().log().all().assertThat()
|
||||
.statusCode(201)
|
||||
.contentType(ContentType.JSON)
|
||||
.body("", lenientlyEquals("""
|
||||
{
|
||||
"type": "DOMAIN_SETUP",
|
||||
"identifier": "example.com",
|
||||
"caption": "some unrelated domain-setup",
|
||||
"config": {}
|
||||
}
|
||||
"""))
|
||||
.header("Location", matchesRegex("http://localhost:[1-9][0-9]*/api/hs/hosting/assets/[^/]*"))
|
||||
.extract().header("Location"); // @formatter:on
|
||||
|
||||
// finally, the new asset can be accessed under the generated UUID
|
||||
final var newWebspace = UUID.fromString(
|
||||
location.substring(location.lastIndexOf('/') + 1));
|
||||
assertThat(newWebspace).isNotNull();
|
||||
toCleanup(HsHostingAssetEntity.class, newWebspace);
|
||||
}
|
||||
|
||||
@Test
|
||||
void propertyValidationsArePerformend_whenAddingAsset() {
|
||||
|
||||
|
@@ -131,9 +131,10 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
initialGrantNames,
|
||||
|
||||
// global-admin
|
||||
"{ grant perm:hs_hosting_asset#fir00:SELECT to role:global#global:ADMIN by system and assume }", // workaround
|
||||
"{ grant role:hs_hosting_asset#fir00:OWNER to role:global#global:ADMIN by system }", // workaround
|
||||
|
||||
// owner
|
||||
"{ grant role:hs_hosting_asset#fir00:OWNER to user:superuser-alex@hostsharing.net by hs_hosting_asset#fir00:OWNER and assume }",
|
||||
"{ grant role:hs_hosting_asset#fir00:OWNER to role:hs_booking_item#fir01:ADMIN by system and assume }",
|
||||
"{ grant role:hs_hosting_asset#fir00:OWNER to role:hs_hosting_asset#vm1011:ADMIN by system and assume }",
|
||||
"{ grant perm:hs_hosting_asset#fir00:DELETE to role:hs_hosting_asset#fir00:OWNER by system and assume }",
|
||||
@@ -158,37 +159,38 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
|
||||
|
||||
@Test
|
||||
public void anyUser_canCreateNewDomainSetupAsset() {
|
||||
// given
|
||||
context("superuser-alex@hostsharing.net");
|
||||
final var assetCount = assetRepo.count();
|
||||
|
||||
// when
|
||||
context("person-SmithPeter@example.com");
|
||||
final var result = attempt(em, () -> {
|
||||
final var newAsset = HsHostingAssetEntity.builder()
|
||||
.caption("some new domain setup")
|
||||
.type(DOMAIN_SETUP)
|
||||
.identifier("example.org")
|
||||
.identifier("example.net")
|
||||
.caption("some new domain setup")
|
||||
.build();
|
||||
return toCleanup(assetRepo.save(newAsset));
|
||||
return assetRepo.save(newAsset);
|
||||
});
|
||||
|
||||
// then
|
||||
// ... the domain setup was created and returned
|
||||
result.assertSuccessful();
|
||||
assertThat(result.returnedValue()).isNotNull().extracting(HsHostingAssetEntity::getUuid).isNotNull();
|
||||
assertThat(result.returnedValue().isLoaded()).isFalse();
|
||||
context("superuser-alex@hostsharing.net");
|
||||
|
||||
// ... the creating user can read the new domain setup
|
||||
context("person-SmithPeter@example.com");
|
||||
assertThatAssetIsPersisted(result.returnedValue());
|
||||
|
||||
// ... a global admin can see the new domain setup as well if the domain OWNER role is assumed
|
||||
context("superuser-alex@hostsharing.net", "hs_hosting_asset#example.net:OWNER"); // only works with the assumed role
|
||||
assertThatAssetIsPersisted(result.returnedValue());
|
||||
assertThat(assetRepo.count()).isEqualTo(assetCount + 1);
|
||||
}
|
||||
|
||||
private void assertThatAssetIsPersisted(final HsHostingAssetEntity saved) {
|
||||
final var context =
|
||||
em.clear();
|
||||
attempt(em, () -> {
|
||||
final var found = assetRepo.findByUuid(saved.getUuid());
|
||||
assertThat(found).isNotEmpty().map(HsHostingAssetEntity::toString).get().isEqualTo(saved.toString());
|
||||
assertThat(found).isNotEmpty().map(HsHostingAssetEntity::toString).contains(saved.toString());
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,219 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class HsHostingAssetTypeUnitTest {
|
||||
|
||||
@Test
|
||||
void generatedPlantUML() {
|
||||
final var result = HsHostingAssetType.renderAsEmbeddedPlantUml();
|
||||
|
||||
assertThat(result).isEqualTo("""
|
||||
## HostingAsset Type Structure
|
||||
|
||||
|
||||
### Domain
|
||||
|
||||
```plantuml
|
||||
@startuml
|
||||
left to right direction
|
||||
|
||||
package Booking #feb28c {
|
||||
entity BI_PRIVATE_CLOUD
|
||||
entity BI_CLOUD_SERVER
|
||||
entity BI_MANAGED_SERVER
|
||||
entity BI_MANAGED_WEBSPACE
|
||||
entity BI_DOMAIN_DNS_SETUP
|
||||
entity BI_DOMAIN_EMAIL_SUBMISSION_SETUP
|
||||
}
|
||||
|
||||
package Hosting #feb28c{
|
||||
package Domain #99bcdb {
|
||||
entity HA_DOMAIN_SETUP
|
||||
entity HA_DOMAIN_DNS_SETUP
|
||||
entity HA_DOMAIN_HTTP_SETUP
|
||||
entity HA_DOMAIN_EMAIL_SUBMISSION_SETUP
|
||||
entity HA_DOMAIN_EMAIL_MAILBOX_SETUP
|
||||
entity HA_EMAIL_ADDRESS
|
||||
}
|
||||
|
||||
package Server #99bcdb {
|
||||
entity HA_CLOUD_SERVER
|
||||
entity HA_MANAGED_SERVER
|
||||
entity HA_IP_NUMBER
|
||||
}
|
||||
|
||||
package Webspace #99bcdb {
|
||||
entity HA_MANAGED_WEBSPACE
|
||||
entity HA_UNIX_USER
|
||||
entity HA_EMAIL_ALIAS
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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_SETUP o..> HA_DOMAIN_SETUP
|
||||
HA_DOMAIN_DNS_SETUP *==> HA_DOMAIN_SETUP
|
||||
HA_DOMAIN_HTTP_SETUP *==> HA_DOMAIN_SETUP
|
||||
HA_DOMAIN_HTTP_SETUP o..> HA_UNIX_USER
|
||||
HA_DOMAIN_EMAIL_SUBMISSION_SETUP *==> HA_DOMAIN_SETUP
|
||||
HA_DOMAIN_EMAIL_SUBMISSION_SETUP o..> HA_MANAGED_WEBSPACE
|
||||
HA_DOMAIN_EMAIL_MAILBOX_SETUP *==> HA_DOMAIN_SETUP
|
||||
HA_DOMAIN_EMAIL_MAILBOX_SETUP o..> HA_MANAGED_WEBSPACE
|
||||
HA_EMAIL_ALIAS *==> HA_MANAGED_WEBSPACE
|
||||
HA_EMAIL_ADDRESS *==> HA_DOMAIN_EMAIL_MAILBOX_SETUP
|
||||
HA_IP_NUMBER o..> HA_CLOUD_SERVER
|
||||
HA_IP_NUMBER o..> HA_MANAGED_SERVER
|
||||
HA_IP_NUMBER o..> HA_MANAGED_WEBSPACE
|
||||
|
||||
package Legend #white {
|
||||
SUB_ENTITY1 *--> REQUIRED_PARENT_ENTITY
|
||||
SUB_ENTITY2 *..> OPTIONAL_PARENT_ENTITY
|
||||
ASSIGNED_ENTITY1 o--> REQUIRED_ASSIGNED_TO_ENTITY1
|
||||
ASSIGNED_ENTITY2 o..> OPTIONAL_ASSIGNED_TO_ENTITY2
|
||||
}
|
||||
Booking -down[hidden]->Legend
|
||||
```
|
||||
|
||||
### MariaDB
|
||||
|
||||
```plantuml
|
||||
@startuml
|
||||
left to right direction
|
||||
|
||||
package Booking #feb28c {
|
||||
entity BI_PRIVATE_CLOUD
|
||||
entity BI_CLOUD_SERVER
|
||||
entity BI_MANAGED_SERVER
|
||||
entity BI_MANAGED_WEBSPACE
|
||||
entity BI_DOMAIN_DNS_SETUP
|
||||
entity BI_DOMAIN_EMAIL_SUBMISSION_SETUP
|
||||
}
|
||||
|
||||
package Hosting #feb28c{
|
||||
package MariaDB #99bcdb {
|
||||
entity HA_MARIADB_INSTANCE
|
||||
entity HA_MARIADB_USER
|
||||
entity HA_MARIADB_DATABASE
|
||||
}
|
||||
|
||||
package Server #99bcdb {
|
||||
entity HA_CLOUD_SERVER
|
||||
entity HA_MANAGED_SERVER
|
||||
entity HA_IP_NUMBER
|
||||
}
|
||||
|
||||
package Webspace #99bcdb {
|
||||
entity HA_MANAGED_WEBSPACE
|
||||
entity HA_UNIX_USER
|
||||
entity HA_EMAIL_ALIAS
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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_EMAIL_ALIAS *==> HA_MANAGED_WEBSPACE
|
||||
HA_MARIADB_INSTANCE *==> HA_MANAGED_SERVER
|
||||
HA_MARIADB_USER *==> HA_MARIADB_INSTANCE
|
||||
HA_MARIADB_USER o..> HA_MANAGED_WEBSPACE
|
||||
HA_MARIADB_DATABASE *==> HA_MANAGED_WEBSPACE
|
||||
HA_MARIADB_DATABASE o..> HA_MARIADB_INSTANCE
|
||||
HA_IP_NUMBER o..> HA_CLOUD_SERVER
|
||||
HA_IP_NUMBER o..> HA_MANAGED_SERVER
|
||||
HA_IP_NUMBER o..> HA_MANAGED_WEBSPACE
|
||||
|
||||
package Legend #white {
|
||||
SUB_ENTITY1 *--> REQUIRED_PARENT_ENTITY
|
||||
SUB_ENTITY2 *..> OPTIONAL_PARENT_ENTITY
|
||||
ASSIGNED_ENTITY1 o--> REQUIRED_ASSIGNED_TO_ENTITY1
|
||||
ASSIGNED_ENTITY2 o..> OPTIONAL_ASSIGNED_TO_ENTITY2
|
||||
}
|
||||
Booking -down[hidden]->Legend
|
||||
```
|
||||
|
||||
### PostgreSQL
|
||||
|
||||
```plantuml
|
||||
@startuml
|
||||
left to right direction
|
||||
|
||||
package Booking #feb28c {
|
||||
entity BI_PRIVATE_CLOUD
|
||||
entity BI_CLOUD_SERVER
|
||||
entity BI_MANAGED_SERVER
|
||||
entity BI_MANAGED_WEBSPACE
|
||||
entity BI_DOMAIN_DNS_SETUP
|
||||
entity BI_DOMAIN_EMAIL_SUBMISSION_SETUP
|
||||
}
|
||||
|
||||
package Hosting #feb28c{
|
||||
package PostgreSQL #99bcdb {
|
||||
entity HA_PGSQL_INSTANCE
|
||||
entity HA_PGSQL_USER
|
||||
entity HA_PGSQL_DATABASE
|
||||
}
|
||||
|
||||
package Server #99bcdb {
|
||||
entity HA_CLOUD_SERVER
|
||||
entity HA_MANAGED_SERVER
|
||||
entity HA_IP_NUMBER
|
||||
}
|
||||
|
||||
package Webspace #99bcdb {
|
||||
entity HA_MANAGED_WEBSPACE
|
||||
entity HA_UNIX_USER
|
||||
entity HA_EMAIL_ALIAS
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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_EMAIL_ALIAS *==> HA_MANAGED_WEBSPACE
|
||||
HA_PGSQL_INSTANCE *==> HA_MANAGED_SERVER
|
||||
HA_PGSQL_USER *==> HA_PGSQL_INSTANCE
|
||||
HA_PGSQL_USER o..> HA_MANAGED_WEBSPACE
|
||||
HA_PGSQL_DATABASE *==> HA_MANAGED_WEBSPACE
|
||||
HA_PGSQL_DATABASE o..> HA_PGSQL_INSTANCE
|
||||
HA_IP_NUMBER o..> HA_CLOUD_SERVER
|
||||
HA_IP_NUMBER o..> HA_MANAGED_SERVER
|
||||
HA_IP_NUMBER o..> HA_MANAGED_WEBSPACE
|
||||
|
||||
package Legend #white {
|
||||
SUB_ENTITY1 *--> REQUIRED_PARENT_ENTITY
|
||||
SUB_ENTITY2 *..> OPTIONAL_PARENT_ENTITY
|
||||
ASSIGNED_ENTITY1 o--> REQUIRED_ASSIGNED_TO_ENTITY1
|
||||
ASSIGNED_ENTITY2 o..> OPTIONAL_ASSIGNED_TO_ENTITY2
|
||||
}
|
||||
Booking -down[hidden]->Legend
|
||||
```
|
||||
|
||||
This code generated was by HsHostingAssetType.main, do not amend manually.
|
||||
""");
|
||||
}
|
||||
}
|
@@ -33,7 +33,7 @@ class HsCloudServerHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'CLOUD_SERVER:vm1234.bookingItem' must not be null but is null",
|
||||
"'CLOUD_SERVER:vm1234.bookingItem' must be of type CLOUD_SERVER but is null",
|
||||
"'CLOUD_SERVER:vm1234.config.RAM' is not expected but is set to '2000'");
|
||||
}
|
||||
|
||||
@@ -84,14 +84,14 @@ class HsCloudServerHostingAssetValidatorUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void validatesParentAndAssignedToAssetMustNotBeSet() {
|
||||
void rejectsInvalidReferencedEntities() {
|
||||
// given
|
||||
final var mangedServerHostingAssetEntity = HsHostingAssetEntity.builder()
|
||||
.type(CLOUD_SERVER)
|
||||
.identifier("xyz00")
|
||||
.parentAsset(HsHostingAssetEntity.builder().build())
|
||||
.assignedToAsset(HsHostingAssetEntity.builder().build())
|
||||
.identifier("vm1234")
|
||||
.bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build())
|
||||
.parentAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build())
|
||||
.assignedToAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build())
|
||||
.build();
|
||||
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
|
||||
|
||||
@@ -100,7 +100,7 @@ class HsCloudServerHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'CLOUD_SERVER:xyz00.parentAsset' must be null but is set to D-???????-?:null",
|
||||
"'CLOUD_SERVER:xyz00.assignedToAsset' must be null but is set to D-???????-?:null");
|
||||
"'CLOUD_SERVER:vm1234.parentAsset' must be null but is of type MANAGED_SERVER",
|
||||
"'CLOUD_SERVER:vm1234.assignedToAsset' must be null but is of type CLOUD_SERVER");
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
|
||||
return HsHostingAssetEntity.builder()
|
||||
.type(DOMAIN_DNS_SETUP)
|
||||
.parentAsset(validDomainSetupEntity)
|
||||
.identifier("example.org")
|
||||
.identifier("example.org|DNS")
|
||||
.config(Map.ofEntries(
|
||||
entry("user-RR", Array.of(
|
||||
"@ 1814400 IN XXX example.org. root.example.org ( 1234 10800 900 604800 86400 )",
|
||||
@@ -74,19 +74,20 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
|
||||
void preprocessesTakesIdentifierFromParent() {
|
||||
// given
|
||||
final var givenEntity = validEntityBuilder().build();
|
||||
assertThat(givenEntity.getParentAsset().getIdentifier()).as("preconditon failed").isEqualTo("example.org");
|
||||
final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
|
||||
|
||||
// when
|
||||
validator.preprocessEntity(givenEntity);
|
||||
|
||||
// then
|
||||
assertThat(givenEntity.getIdentifier()).isEqualTo(givenEntity.getParentAsset().getIdentifier());
|
||||
assertThat(givenEntity.getIdentifier()).isEqualTo("example.org|DNS");
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsInvalidIdentifier() {
|
||||
// given
|
||||
final var givenEntity = validEntityBuilder().identifier("wrong.org").build();
|
||||
final var givenEntity = validEntityBuilder().identifier("example.org").build();
|
||||
final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
|
||||
|
||||
// when
|
||||
@@ -94,14 +95,14 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'identifier' expected to match '^example.org$', but is 'wrong.org'"
|
||||
"'identifier' expected to match '^example.org\\Q|DNS\\E$', but is 'example.org'"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptsValidIdentifier() {
|
||||
// given
|
||||
final var givenEntity = validEntityBuilder().identifier(validDomainSetupEntity.getIdentifier()).build();
|
||||
final var givenEntity = validEntityBuilder().identifier(validDomainSetupEntity.getIdentifier()+"|DNS").build();
|
||||
final var validator = HsHostingAssetEntityValidatorRegistry.forType(givenEntity.getType());
|
||||
|
||||
// when
|
||||
@@ -112,12 +113,12 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void validatesReferencedEntities() {
|
||||
void rejectsInvalidReferencedEntities() {
|
||||
// given
|
||||
final var mangedServerHostingAssetEntity = validEntityBuilder()
|
||||
.parentAsset(HsHostingAssetEntity.builder().build())
|
||||
.assignedToAsset(HsHostingAssetEntity.builder().build())
|
||||
.bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build())
|
||||
.parentAsset(null)
|
||||
.assignedToAsset(HsHostingAssetEntity.builder().type(DOMAIN_SETUP).build())
|
||||
.build();
|
||||
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
|
||||
|
||||
@@ -126,9 +127,9 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'DOMAIN_DNS_SETUP:example.org.bookingItem' must be null but is set to D-???????-?:null",
|
||||
"'DOMAIN_DNS_SETUP:example.org.parentAsset' must be of type DOMAIN_SETUP but is of type null",
|
||||
"'DOMAIN_DNS_SETUP:example.org.assignedToAsset' must be null but is set to D-???????-?:null");
|
||||
"'DOMAIN_DNS_SETUP:example.org|DNS.bookingItem' must be null but is of type CLOUD_SERVER",
|
||||
"'DOMAIN_DNS_SETUP:example.org|DNS.parentAsset' must be of type DOMAIN_SETUP but is null",
|
||||
"'DOMAIN_DNS_SETUP:example.org|DNS.assignedToAsset' must be null but is of type DOMAIN_SETUP");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,9 +163,9 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'DOMAIN_DNS_SETUP:example.org.config.TTL' is expected to be of type class java.lang.Integer, but is of type 'String'",
|
||||
"'DOMAIN_DNS_SETUP:example.org.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.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");
|
||||
"'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.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");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -12,6 +12,7 @@ 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 net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_SERVER;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
@@ -93,8 +94,8 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
void validatesReferencedEntities() {
|
||||
// given
|
||||
final var mangedServerHostingAssetEntity = validEntityBuilder()
|
||||
.parentAsset(HsHostingAssetEntity.builder().build())
|
||||
.assignedToAsset(HsHostingAssetEntity.builder().build())
|
||||
.parentAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build())
|
||||
.assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build())
|
||||
.bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build())
|
||||
.build();
|
||||
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
|
||||
@@ -104,8 +105,8 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
// 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");
|
||||
"'DOMAIN_SETUP:example.org.bookingItem' must be null but is of type CLOUD_SERVER",
|
||||
"'DOMAIN_SETUP:example.org.parentAsset' must be null or of type DOMAIN_SETUP but is of type CLOUD_SERVER",
|
||||
"'DOMAIN_SETUP:example.org.assignedToAsset' must be null but is of type MANAGED_SERVER");
|
||||
}
|
||||
}
|
||||
|
@@ -107,8 +107,8 @@ class HsEMailAliasHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'EMAIL_ALIAS:abc00-office.bookingItem' must be null but is set to D-1234500:test project:test project booking item",
|
||||
"'EMAIL_ALIAS:abc00-office.bookingItem' must be null but is of type MANAGED_SERVER",
|
||||
"'EMAIL_ALIAS:abc00-office.parentAsset' must be of type MANAGED_WEBSPACE but is of type MANAGED_SERVER",
|
||||
"'EMAIL_ALIAS:abc00-office.assignedToAsset' must be null but is set to D-1234500:test project:test project booking item");
|
||||
"'EMAIL_ALIAS:abc00-office.assignedToAsset' must be null but is of type MANAGED_SERVER");
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ 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.HsHostingAssetType.CLOUD_SERVER;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_SERVER;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -22,8 +23,8 @@ class HsManagedServerHostingAssetValidatorUnitTest {
|
||||
.type(MANAGED_SERVER)
|
||||
.identifier("vm1234")
|
||||
.bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM)
|
||||
.parentAsset(HsHostingAssetEntity.builder().build())
|
||||
.assignedToAsset(HsHostingAssetEntity.builder().build())
|
||||
.parentAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build())
|
||||
.assignedToAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build())
|
||||
.config(Map.ofEntries(
|
||||
entry("monit_max_hdd_usage", "90"),
|
||||
entry("monit_max_cpu_usage", 2),
|
||||
@@ -37,8 +38,8 @@ class HsManagedServerHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'MANAGED_SERVER:vm1234.parentAsset' must be null but is set to D-1234500:test project:test project booking item",
|
||||
"'MANAGED_SERVER:vm1234.assignedToAsset' must be null but is set to D-1234500:test project:test project booking item",
|
||||
"'MANAGED_SERVER:vm1234.parentAsset' must be null but is of type CLOUD_SERVER",
|
||||
"'MANAGED_SERVER:vm1234.assignedToAsset' must be null but is of type CLOUD_SERVER",
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_cpu_usage' is expected to be at least 10 but is 2",
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_ram_usage' is expected to be at most 100 but is 101",
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_hdd_usage' is expected to be of type class java.lang.Integer, but is of type 'String'");
|
||||
@@ -63,14 +64,14 @@ class HsManagedServerHostingAssetValidatorUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void validatesParentAndAssignedToAssetMustNotBeSet() {
|
||||
void rejectsInvalidReferencedEntities() {
|
||||
// given
|
||||
final var mangedServerHostingAssetEntity = HsHostingAssetEntity.builder()
|
||||
.type(MANAGED_SERVER)
|
||||
.identifier("xyz00")
|
||||
.parentAsset(HsHostingAssetEntity.builder().build())
|
||||
.assignedToAsset(HsHostingAssetEntity.builder().build())
|
||||
.bookingItem(TEST_CLOUD_SERVER_BOOKING_ITEM)
|
||||
.parentAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build())
|
||||
.assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_SERVER).build())
|
||||
.build();
|
||||
final var validator = HsHostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType());
|
||||
|
||||
@@ -80,7 +81,7 @@ class HsManagedServerHostingAssetValidatorUnitTest {
|
||||
// then
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'MANAGED_SERVER:xyz00.bookingItem' must be of type MANAGED_SERVER but is of type CLOUD_SERVER",
|
||||
"'MANAGED_SERVER:xyz00.parentAsset' must be null but is set to D-1234500:test project:test cloud server booking item",
|
||||
"'MANAGED_SERVER:xyz00.assignedToAsset' must be null but is set to D-1234500:test project:test cloud server booking item");
|
||||
"'MANAGED_SERVER:xyz00.parentAsset' must be null but is of type CLOUD_SERVER",
|
||||
"'MANAGED_SERVER:xyz00.assignedToAsset' must be null but is of type MANAGED_SERVER");
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
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.MANAGED_WEBSPACE;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.TEST_PROJECT;
|
||||
@@ -142,7 +143,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void validatesEntityReferences() {
|
||||
void rejectsInvalidEntityReferences() {
|
||||
// given
|
||||
final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE);
|
||||
final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder()
|
||||
@@ -153,7 +154,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
|
||||
.resources(Map.ofEntries(entry("SSD", 25), entry("Traffic", 250)))
|
||||
.build())
|
||||
.parentAsset(cloudServerAssetEntity)
|
||||
.assignedToAsset(HsHostingAssetEntity.builder().build())
|
||||
.assignedToAsset(HsHostingAssetEntity.builder().type(CLOUD_SERVER).build())
|
||||
.identifier("abc00")
|
||||
.build();
|
||||
|
||||
@@ -163,7 +164,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
|
||||
// then
|
||||
assertThat(result).containsExactly(
|
||||
"'MANAGED_WEBSPACE:abc00.bookingItem' must be of type MANAGED_WEBSPACE but is of type MANAGED_SERVER",
|
||||
"'MANAGED_WEBSPACE:abc00.parentAsset' must be of type MANAGED_SERVER but is of type CLOUD_SERVER",
|
||||
"'MANAGED_WEBSPACE:abc00.assignedToAsset' must be null but is set to D-???????-?:some ManagedServer");
|
||||
"'MANAGED_WEBSPACE:abc00.parentAsset' must be null or of type MANAGED_SERVER but is of type CLOUD_SERVER",
|
||||
"'MANAGED_WEBSPACE:abc00.assignedToAsset' must be null but is of type CLOUD_SERVER");
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.catchThrowable;
|
||||
import static org.junit.jupiter.api.condition.OS.LINUX;
|
||||
|
||||
class SystemProcessTest {
|
||||
class SystemProcessUnitTest {
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(LINUX)
|
Reference in New Issue
Block a user