Search in sources :

Example 6 with ValidationFailed

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());
}
Also used : ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) NotEmpty(javax.validation.constraints.NotEmpty)

Example 7 with ValidationFailed

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());
}
Also used : ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) NotNull(javax.validation.constraints.NotNull)

Example 8 with ValidationFailed

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());
}
Also used : ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed)

Example 9 with ValidationFailed

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);
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) Test(org.junit.jupiter.api.Test)

Example 10 with ValidationFailed

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));
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationFailed (io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed)61 Test (org.junit.jupiter.api.Test)46 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)24 BackupConfigReview (io.stackgres.operator.common.BackupConfigReview)17 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)15 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)10 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)5 Status (io.fabric8.kubernetes.api.model.Status)4 StackGresPostgresConfig (io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig)4 StatusBuilder (io.fabric8.kubernetes.api.model.StatusBuilder)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 StatusDetailsBuilder (io.fabric8.kubernetes.api.model.StatusDetailsBuilder)2 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)2 PgConfigReview (io.stackgres.operator.common.PgConfigReview)2 StackGresDbOpsReview (io.stackgres.operator.common.StackGresDbOpsReview)2 Operation (io.stackgres.operatorframework.admissionwebhook.Operation)2 List (java.util.List)2 ImmutableList (com.google.common.collect.ImmutableList)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1