hosting-asset-validation-beyond-property-validators #65

Merged
hsh-michaelhoennig merged 6 commits from hosting-asset-validation-beyond-property-validators into master 2024-06-24 12:33:15 +02:00
4 changed files with 40 additions and 3 deletions
Showing only changes of commit fda72afd18 - Show all commits

View File

@ -29,6 +29,7 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.PostLoad;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import jakarta.persistence.Version;
@ -120,12 +121,20 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject {
@Transient
private PatchableMapWrapper<Object> configWrapper;
@Transient
private boolean isLoaded = false;
@PostLoad
public void markAsLoaded() {
this.isLoaded = true;
}
public PatchableMapWrapper<Object> getConfig() {
return PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper; }, config );
}
public void putConfig(Map<String, Object> newConfg) {
PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper; }, config).assign(newConfg);
public void putConfig(Map<String, Object> newConfig) {
PatchableMapWrapper.of(configWrapper, (newWrapper) -> {configWrapper = newWrapper; }, config).assign(newConfig);
}
@Override

View File

@ -17,6 +17,10 @@ class HsManagedWebspaceHostingAssetValidator extends HsHostingAssetEntityValidat
@Override
protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) {
hsh-michaelhoennig marked this conversation as resolved

nur bei neu angelegten Objekten prüfen

nur bei neu angelegten Objekten prüfen
return Pattern.compile("^" + assetEntity.getParentAsset().getBookingItem().getProject().getDebitor().getDefaultPrefix() + "[0-9][0-9]$");
final var prefixPattern =
!assetEntity.isLoaded()
? assetEntity.getParentAsset().getBookingItem().getProject().getDebitor().getDefaultPrefix()
: "[a-z][a-z0-9][a-z0-9]";
return Pattern.compile("^" + prefixPattern + "[0-9][0-9]$");
}
}

View File

@ -90,6 +90,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
result.assertSuccessful();
assertThat(result.returnedValue()).isNotNull().extracting(HsHostingAssetEntity::getUuid).isNotNull();
assertThatAssetIsPersisted(result.returnedValue());
assertThat(result.returnedValue().isLoaded()).isFalse();
assertThat(assetRepo.count()).isEqualTo(count + 1);
}
@ -413,5 +414,6 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
assertThat(actualResult)
.extracting(HsHostingAssetEntity::toString)
.contains(serverNames);
actualResult.forEach(loadedEntity -> assertThat(loadedEntity.isLoaded()).isTrue());
}
}

View File

@ -54,6 +54,28 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
))
.build();
@Test
void acceptsAlienIdentifierPrefixForPreExistingEntity() {
// given
final var validator = HsHostingAssetEntityValidatorRegistry.forType(MANAGED_WEBSPACE);
final var mangedWebspaceHostingAssetEntity = HsHostingAssetEntity.builder()
.type(MANAGED_WEBSPACE)
.bookingItem(HsBookingItemEntity.builder()
.type(HsBookingItemType.MANAGED_WEBSPACE)
.resources(Map.ofEntries(entry("SSD", 25), entry("Traffic", 250)))
.build())
.parentAsset(mangedServerAssetEntity)
.identifier("xyz00")
.isLoaded(true)
.build();
// when
final var result = validator.validate(mangedWebspaceHostingAssetEntity);
// then
assertThat(result).isEmpty();
}
@Test
void validatesIdentifierAndReferencedEntities() {
// given