use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class ConstraintValidationTest method checkNotEmptyErrorCause.
protected void checkNotEmptyErrorCause(Class<?> outerClass, String fieldPath, T review) {
String lastField = getLastField(fieldPath);
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> validator.validate(review));
String message = ValidationUtils.getNotEmptyMessage(outerClass, lastField);
ValidationUtils.checkErrorCause(ex.getResult(), fieldPath, message, NotEmpty.class.getName());
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class ConstraintValidationTest method checkNotNullErrorCause.
protected void checkNotNullErrorCause(Class<?> outerClass, String fieldPath, T review) {
String lastField = getLastField(fieldPath);
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> validator.validate(review));
String message = ValidationUtils.getNotNullMessage(outerClass, lastField);
ValidationUtils.checkErrorCause(ex.getResult(), fieldPath, message, NotNull.class.getName());
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class ConstraintValidationTest method checkErrorCause.
protected void checkErrorCause(Class<?> outerClass, String[] fieldPaths, String validationPath, T review, Class<? extends Annotation> constraint) {
String lastField = getLastField(validationPath);
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> validator.validate(review));
String message = ValidationUtils.getConstraintMessage(outerClass, lastField, constraint);
ValidationUtils.checkErrorCause(ex.getResult(), fieldPaths, message, constraint.getName());
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class PoolingValidatorTest method giveInvalidStackGresPoolingOnCreation_shouldFail.
@Test
void giveInvalidStackGresPoolingOnCreation_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
String poolingConfig = review.getRequest().getObject().getSpec().getConfiguration().getConnectionPoolingConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(configFinder.findByNameAndNamespace(poolingConfig, namespace)).thenReturn(Optional.empty());
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = ex.getMessage();
assertEquals("Pooling config " + poolingConfig + " not found", resultMessage);
}
use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.
the class PoolingValidatorTest method giveAnAttemptToUpdateToAnUnknownPoolingConfig_shouldFail.
@Test
void giveAnAttemptToUpdateToAnUnknownPoolingConfig_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/connectionpooling_config_update.json", StackGresClusterReview.class);
String poolingConfig = review.getRequest().getObject().getSpec().getConfiguration().getConnectionPoolingConfig();
String namespace = review.getRequest().getObject().getMetadata().getNamespace();
when(configFinder.findByNameAndNamespace(poolingConfig, namespace)).thenReturn(Optional.empty());
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = ex.getMessage();
assertEquals("Cannot update to pooling config " + poolingConfig + " because it doesn't exists", resultMessage);
verify(configFinder).findByNameAndNamespace(eq(poolingConfig), eq(namespace));
}
Aggregations