hosting-asset-data-migration #79
@ -13,8 +13,8 @@ class HsCloudServerBookingItemValidator extends HsBookingItemEntityValidator {
|
|||||||
|
|
||||||
integerProperty("CPU") .min( 1) .max( 32) .required(),
|
integerProperty("CPU") .min( 1) .max( 32) .required(),
|
||||||
integerProperty("RAM").unit("GB") .min( 1) .max( 8192) .required(),
|
integerProperty("RAM").unit("GB") .min( 1) .max( 8192) .required(),
|
||||||
integerProperty("SSD").unit("GB") .min( 0) .max( 1000) .step(25).requiresExactlyOneOf("SDD", "HDD").withDefault(0),
|
integerProperty("SSD").unit("GB") .min( 25) .max( 1000) .step(25).requiresAtLeastOneOf("SDD", "HDD"),
|
||||||
integerProperty("HDD").unit("GB") .min( 0) .max( 4000) .step(250).requiresExactlyOneOf("SSD", "HDD").withDefault(0),
|
integerProperty("HDD").unit("GB") .min(250) .max( 4000) .step(250).requiresAtLeastOneOf("SSD", "HDD"),
|
||||||
integerProperty("Traffic").unit("GB") .min(250) .max(10000) .step(250).requiresAtMaxOneOf("Bandwidth", "Traffic"),
|
integerProperty("Traffic").unit("GB") .min(250) .max(10000) .step(250).requiresAtMaxOneOf("Bandwidth", "Traffic"),
|
||||||
integerProperty("Bandwidth").unit("GB") .min(250) .max(10000) .step(250).requiresAtMaxOneOf("Bandwidth", "Traffic"), // TODO.spec
|
integerProperty("Bandwidth").unit("GB") .min(250) .max(10000) .step(250).requiresAtMaxOneOf("Bandwidth", "Traffic"), // TODO.spec
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ class HsManagedServerBookingItemValidator extends HsBookingItemEntityValidator {
|
|||||||
super(
|
super(
|
||||||
integerProperty("CPU").min(1).max(32).required(),
|
integerProperty("CPU").min(1).max(32).required(),
|
||||||
integerProperty("RAM").unit("GB").min(1).max(128).required(),
|
integerProperty("RAM").unit("GB").min(1).max(128).required(),
|
||||||
integerProperty("SSD").unit("GB").min(25).max(2000).step(25).requiresExactlyOneOf("SSD", "HDD").withDefault(0).asTotalLimit().withThreshold(200),
|
integerProperty("SSD").unit("GB").min(25).max(2000).step(25).requiresAtLeastOneOf("SSD", "HDD").asTotalLimit().withThreshold(200),
|
||||||
integerProperty("HDD").unit("GB").min(0).max(10000).step(250).requiresExactlyOneOf("SSD", "HDD").withDefault(0).asTotalLimit().withThreshold(200),
|
integerProperty("HDD").unit("GB").min(250).max(10000).step(250).requiresAtLeastOneOf("SSD", "HDD").asTotalLimit().withThreshold(200),
|
||||||
integerProperty("Traffic").unit("GB").min(250).max(64000).step(250).requiresAtMaxOneOf("Bandwidth", "Traffic").asTotalLimit().withThreshold(200),
|
integerProperty("Traffic").unit("GB").min(250).max(64000).step(250).requiresAtMaxOneOf("Bandwidth", "Traffic").asTotalLimit().withThreshold(200),
|
||||||
integerProperty("Bandwidth").unit("GB").min(250).max(64000).step(250).requiresAtMaxOneOf("Bandwidth", "Traffic").asTotalLimit().withThreshold(200), // TODO.spec
|
integerProperty("Bandwidth").unit("GB").min(250).max(64000).step(250).requiresAtMaxOneOf("Bandwidth", "Traffic").asTotalLimit().withThreshold(200), // TODO.spec
|
||||||
enumerationProperty("SLA-Platform").values("BASIC", "EXT8H", "EXT4H", "EXT2H").withDefault("BASIC"),
|
enumerationProperty("SLA-Platform").values("BASIC", "EXT8H", "EXT4H", "EXT2H").withDefault("BASIC"),
|
||||||
|
@ -9,8 +9,8 @@ class HsPrivateCloudBookingItemValidator extends HsBookingItemEntityValidator {
|
|||||||
// @formatter:off
|
// @formatter:off
|
||||||
integerProperty("CPU") .min( 1).max( 128).required().asTotalLimit(),
|
integerProperty("CPU") .min( 1).max( 128).required().asTotalLimit(),
|
||||||
integerProperty("RAM").unit("GB") .min( 1).max( 512).required().asTotalLimit(),
|
integerProperty("RAM").unit("GB") .min( 1).max( 512).required().asTotalLimit(),
|
||||||
integerProperty("SSD").unit("GB") .min( 25).max( 4000).step(25).requiresExactlyOneOf("SSD", "HDD").withDefault(0).asTotalLimit(),
|
integerProperty("SSD").unit("GB") .min( 25).max( 4000).step(25).requiresAtLeastOneOf("SSD", "HDD").asTotalLimit(),
|
||||||
integerProperty("HDD").unit("GB") .min( 0).max(16000).step(250).requiresExactlyOneOf("SSD", "HDD").withDefault(0).asTotalLimit(),
|
integerProperty("HDD").unit("GB") .min(250).max(16000).step(250).requiresAtLeastOneOf("SSD", "HDD").asTotalLimit(),
|
||||||
integerProperty("Traffic").unit("GB") .min(250).max(64000).step(250).requiresAtMaxOneOf("Bandwidth", "Traffic").asTotalLimit(),
|
integerProperty("Traffic").unit("GB") .min(250).max(64000).step(250).requiresAtMaxOneOf("Bandwidth", "Traffic").asTotalLimit(),
|
||||||
integerProperty("Bandwidth").unit("GB") .min(250).max(64000).step(250).requiresAtMaxOneOf("Bandwidth", "Traffic").asTotalLimit(), // TODO.spec
|
integerProperty("Bandwidth").unit("GB") .min(250).max(64000).step(250).requiresAtMaxOneOf("Bandwidth", "Traffic").asTotalLimit(), // TODO.spec
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ import static org.apache.commons.lang3.ObjectUtils.isArray;
|
|||||||
public abstract class ValidatableProperty<P extends ValidatableProperty<?, ?>, T> {
|
public abstract class ValidatableProperty<P extends ValidatableProperty<?, ?>, T> {
|
||||||
|
|
||||||
protected static final String[] KEY_ORDER_HEAD = Array.of("propertyName");
|
protected static final String[] KEY_ORDER_HEAD = Array.of("propertyName");
|
||||||
protected static final String[] KEY_ORDER_TAIL = Array.of("required", "requiresExactlyOneOf", "requiresAtMaxOneOf", "defaultValue", "readOnly", "writeOnly", "computed", "isTotalsValidator", "thresholdPercentage");
|
protected static final String[] KEY_ORDER_TAIL = Array.of("required", "requiresAtLeastOneOf", "requiresAtMaxOneOf", "defaultValue", "readOnly", "writeOnly", "computed", "isTotalsValidator", "thresholdPercentage");
|
||||||
protected static final String[] KEY_ORDER = Array.join(KEY_ORDER_HEAD, KEY_ORDER_TAIL);
|
protected static final String[] KEY_ORDER = Array.join(KEY_ORDER_HEAD, KEY_ORDER_TAIL);
|
||||||
|
|
||||||
final Class<T> type;
|
final Class<T> type;
|
||||||
@ -42,7 +42,7 @@ public abstract class ValidatableProperty<P extends ValidatableProperty<?, ?>, T
|
|||||||
private final String[] keyOrder;
|
private final String[] keyOrder;
|
||||||
|
|
||||||
private Boolean required;
|
private Boolean required;
|
||||||
private Set<String> requiresExactlyOneOf;
|
private Set<String> requiresAtLeastOneOf;
|
||||||
private Set<String> requiresAtMaxOneOf;
|
private Set<String> requiresAtMaxOneOf;
|
||||||
private T defaultValue;
|
private T defaultValue;
|
||||||
|
|
||||||
@ -109,8 +109,8 @@ protected void setDeferredInit(final Function<ValidatableProperty<?, ?>[], T[]>
|
|||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
public P requiresExactlyOneOf(final String... propNames) {
|
public P requiresAtLeastOneOf(final String... propNames) {
|
||||||
requiresExactlyOneOf = new LinkedHashSet<>(List.of(propNames));
|
requiresAtLeastOneOf = new LinkedHashSet<>(List.of(propNames));
|
||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ protected void setDeferredInit(final Function<ValidatableProperty<?, ?>[], T[]>
|
|||||||
if (required == TRUE) {
|
if (required == TRUE) {
|
||||||
result.add(propertyName + "' is required but missing");
|
result.add(propertyName + "' is required but missing");
|
||||||
}
|
}
|
||||||
validateRequiresExactlyOneOf(result, propsProvider);
|
validateRequiresAtLeastOneOf(result, propsProvider);
|
||||||
}
|
}
|
||||||
if (propValue != null){
|
if (propValue != null){
|
||||||
validateRequiresAtMaxOneOf(result, propsProvider);
|
validateRequiresAtMaxOneOf(result, propsProvider);
|
||||||
@ -207,16 +207,14 @@ protected void setDeferredInit(final Function<ValidatableProperty<?, ?>[], T[]>
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateRequiresExactlyOneOf(final ArrayList<String> result, final PropertiesProvider propsProvider) {
|
private void validateRequiresAtLeastOneOf(final ArrayList<String> result, final PropertiesProvider propsProvider) {
|
||||||
if (requiresExactlyOneOf != null ) {
|
if (requiresAtLeastOneOf != null ) {
|
||||||
final var allPropNames = propsProvider.directProps().keySet();
|
final var allPropNames = propsProvider.directProps().keySet();
|
||||||
final var entriesWithValue = allPropNames.stream()
|
final var entriesWithValue = allPropNames.stream()
|
||||||
.filter(name -> requiresExactlyOneOf.contains(name))
|
.filter(name -> requiresAtLeastOneOf.contains(name))
|
||||||
.count();
|
.count();
|
||||||
if (entriesWithValue == 0) {
|
if (entriesWithValue == 0) {
|
||||||
result.add(propertyName + "' is required once in group " + requiresExactlyOneOf + " but missing");
|
result.add(propertyName + "' is required once in group " + requiresAtLeastOneOf + " but missing");
|
||||||
} else if (entriesWithValue > 1) {
|
|
||||||
result.add(propertyName + "' is required once in group " + requiresExactlyOneOf + " but multiple properties are set");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,8 +235,8 @@ protected void setDeferredInit(final Function<ValidatableProperty<?, ?>[], T[]>
|
|||||||
protected abstract void validate(final List<String> result, final T propValue, final PropertiesProvider propProvider);
|
protected abstract void validate(final List<String> result, final T propValue, final PropertiesProvider propProvider);
|
||||||
|
|
||||||
public void verifyConsistency(final Map.Entry<? extends Enum<?>, ?> typeDef) {
|
public void verifyConsistency(final Map.Entry<? extends Enum<?>, ?> typeDef) {
|
||||||
if (required == null && requiresExactlyOneOf == null && requiresAtMaxOneOf == null) {
|
if (required == null && requiresAtLeastOneOf == null && requiresAtMaxOneOf == null) {
|
||||||
throw new IllegalStateException(typeDef.getKey() + "[" + propertyName + "] not fully initialized, please call either .required(), .optional(), .withDefault(...), .requiresExactlyOneOf(...) or .requiresAtMaxOneOf(...)" );
|
throw new IllegalStateException(typeDef.getKey() + "[" + propertyName + "] not fully initialized, please call either .required(), .optional(), .withDefault(...), .requiresAtLeastOneOf(...) or .requiresAtMaxOneOf(...)" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +58,8 @@ class HsCloudServerBookingItemValidatorUnitTest {
|
|||||||
"{type=boolean, propertyName=active, defaultValue=true}",
|
"{type=boolean, propertyName=active, defaultValue=true}",
|
||||||
"{type=integer, propertyName=CPU, min=1, max=32, required=true}",
|
"{type=integer, propertyName=CPU, min=1, max=32, required=true}",
|
||||||
"{type=integer, propertyName=RAM, unit=GB, min=1, max=8192, required=true}",
|
"{type=integer, propertyName=RAM, unit=GB, min=1, max=8192, required=true}",
|
||||||
"{type=integer, propertyName=SSD, unit=GB, min=0, max=1000, step=25, requiresExactlyOneOf=[SDD, HDD], defaultValue=0}",
|
"{type=integer, propertyName=SSD, unit=GB, min=25, max=1000, step=25, requiresAtLeastOneOf=[SDD, HDD]}",
|
||||||
"{type=integer, propertyName=HDD, unit=GB, min=0, max=4000, step=250, requiresExactlyOneOf=[SSD, HDD], defaultValue=0}",
|
"{type=integer, propertyName=HDD, unit=GB, min=250, max=4000, step=250, requiresAtLeastOneOf=[SSD, HDD]}",
|
||||||
"{type=integer, propertyName=Traffic, unit=GB, min=250, max=10000, step=250, requiresAtMaxOneOf=[Bandwidth, Traffic]}",
|
"{type=integer, propertyName=Traffic, unit=GB, min=250, max=10000, step=250, requiresAtMaxOneOf=[Bandwidth, Traffic]}",
|
||||||
"{type=integer, propertyName=Bandwidth, unit=GB, min=250, max=10000, step=250, requiresAtMaxOneOf=[Bandwidth, Traffic]}",
|
"{type=integer, propertyName=Bandwidth, unit=GB, min=250, max=10000, step=250, requiresAtMaxOneOf=[Bandwidth, Traffic]}",
|
||||||
"{type=enumeration, propertyName=SLA-Infrastructure, values=[BASIC, EXT8H, EXT4H, EXT2H]}");
|
"{type=enumeration, propertyName=SLA-Infrastructure, values=[BASIC, EXT8H, EXT4H, EXT2H]}");
|
||||||
|
@ -65,8 +65,8 @@ class HsManagedServerBookingItemValidatorUnitTest {
|
|||||||
assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder(
|
assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder(
|
||||||
"{type=integer, propertyName=CPU, min=1, max=32, required=true}",
|
"{type=integer, propertyName=CPU, min=1, max=32, required=true}",
|
||||||
"{type=integer, propertyName=RAM, unit=GB, min=1, max=128, required=true}",
|
"{type=integer, propertyName=RAM, unit=GB, min=1, max=128, required=true}",
|
||||||
"{type=integer, propertyName=SSD, unit=GB, min=25, max=2000, step=25, requiresExactlyOneOf=[SSD, HDD], defaultValue=0, isTotalsValidator=true, thresholdPercentage=200}",
|
"{type=integer, propertyName=SSD, unit=GB, min=25, max=2000, step=25, requiresAtLeastOneOf=[SSD, HDD], isTotalsValidator=true, thresholdPercentage=200}",
|
||||||
"{type=integer, propertyName=HDD, unit=GB, min=0, max=10000, step=250, requiresExactlyOneOf=[SSD, HDD], defaultValue=0, isTotalsValidator=true, thresholdPercentage=200}",
|
"{type=integer, propertyName=HDD, unit=GB, min=250, max=10000, step=250, requiresAtLeastOneOf=[SSD, HDD], isTotalsValidator=true, thresholdPercentage=200}",
|
||||||
"{type=integer, propertyName=Traffic, unit=GB, min=250, max=64000, step=250, requiresAtMaxOneOf=[Bandwidth, Traffic], isTotalsValidator=true, thresholdPercentage=200}",
|
"{type=integer, propertyName=Traffic, unit=GB, min=250, max=64000, step=250, requiresAtMaxOneOf=[Bandwidth, Traffic], isTotalsValidator=true, thresholdPercentage=200}",
|
||||||
"{type=integer, propertyName=Bandwidth, unit=GB, min=250, max=64000, step=250, requiresAtMaxOneOf=[Bandwidth, Traffic], isTotalsValidator=true, thresholdPercentage=200}",
|
"{type=integer, propertyName=Bandwidth, unit=GB, min=250, max=64000, step=250, requiresAtMaxOneOf=[Bandwidth, Traffic], isTotalsValidator=true, thresholdPercentage=200}",
|
||||||
"{type=enumeration, propertyName=SLA-Platform, values=[BASIC, EXT8H, EXT4H, EXT2H], defaultValue=BASIC}",
|
"{type=enumeration, propertyName=SLA-Platform, values=[BASIC, EXT8H, EXT4H, EXT2H], defaultValue=BASIC}",
|
||||||
|
@ -11,6 +11,7 @@ import static java.util.Map.ofEntries;
|
|||||||
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.CLOUD_SERVER;
|
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.CLOUD_SERVER;
|
||||||
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.MANAGED_SERVER;
|
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.MANAGED_SERVER;
|
||||||
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.PRIVATE_CLOUD;
|
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.PRIVATE_CLOUD;
|
||||||
|
import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.TEST_PROJECT;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class HsPrivateCloudBookingItemValidatorUnitTest {
|
class HsPrivateCloudBookingItemValidatorUnitTest {
|
||||||
@ -28,6 +29,7 @@ class HsPrivateCloudBookingItemValidatorUnitTest {
|
|||||||
// given
|
// given
|
||||||
final var privateCloudBookingItemEntity = HsBookingItemEntity.builder()
|
final var privateCloudBookingItemEntity = HsBookingItemEntity.builder()
|
||||||
.type(PRIVATE_CLOUD)
|
.type(PRIVATE_CLOUD)
|
||||||
|
.project(TEST_PROJECT)
|
||||||
.caption("myPC")
|
.caption("myPC")
|
||||||
.resources(ofEntries(
|
.resources(ofEntries(
|
||||||
entry("CPU", 4),
|
entry("CPU", 4),
|
||||||
|
@ -212,7 +212,6 @@ public class CsvDataImport extends ContextBasedTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void logError(final Runnable assertion) {
|
void logError(final Runnable assertion) {
|
||||||
assertion.run();
|
|
||||||
try {
|
try {
|
||||||
assertion.run();
|
assertion.run();
|
||||||
} catch (final AssertionError exc) {
|
} catch (final AssertionError exc) {
|
||||||
|
@ -37,7 +37,6 @@ import static java.util.Optional.ofNullable;
|
|||||||
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange;
|
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange;
|
||||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||||
import static org.assertj.core.api.Assertions.as;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||||
import static org.assertj.core.api.Fail.fail;
|
import static org.assertj.core.api.Fail.fail;
|
||||||
|
Loading…
Reference in New Issue
Block a user