Search in sources :

Example 6 with ValidationContext

use of org.summerb.approaches.validation.ValidationContext in project summerb by skarpushin.

the class StringTemplateValidationUtilsTest method testValidateStringTemplate_blackbox_expectOkForConstant.

@Test
public void testValidateStringTemplate_blackbox_expectOkForConstant() throws Exception {
    StringTemplateCompiler stringTemplateCompiler = new StringTemplateCompilerlImpl();
    String stringTemplate = "Constant text";
    ValidationContext ctx = new ValidationContext();
    String fieldToken = "fieldToken";
    StringTemplateValidationUtils.validateStringTemplate(stringTemplateCompiler, stringTemplate, ctx, fieldToken);
    assertEquals(false, ctx.getHasErrors());
}
Also used : StringTemplateCompilerlImpl(org.summerb.utils.stringtemplate.impl.StringTemplateCompilerlImpl) StringTemplateCompiler(org.summerb.utils.stringtemplate.api.StringTemplateCompiler) ValidationContext(org.summerb.approaches.validation.ValidationContext) Test(org.junit.Test)

Example 7 with ValidationContext

use of org.summerb.approaches.validation.ValidationContext in project summerb by skarpushin.

the class EasyCrudValidationStrategyAbstract method validateForUpdate.

@Override
public void validateForUpdate(TDto existingVersion, TDto newVersion) throws FieldValidationException {
    ValidationContext ctx = new ValidationContext();
    doValidateForUpdate(existingVersion, newVersion, ctx);
    if (ctx.getHasErrors()) {
        throw new FieldValidationException(ctx.getErrors());
    }
}
Also used : FieldValidationException(org.summerb.approaches.validation.FieldValidationException) ValidationContext(org.summerb.approaches.validation.ValidationContext)

Example 8 with ValidationContext

use of org.summerb.approaches.validation.ValidationContext in project summerb by skarpushin.

the class EasyCrudValidationStrategyAbstract method validateForCreate.

@Override
public void validateForCreate(TDto dto) throws FieldValidationException {
    ValidationContext ctx = new ValidationContext();
    doValidateForCreate(dto, ctx);
    if (ctx.getHasErrors()) {
        throw new FieldValidationException(ctx.getErrors());
    }
}
Also used : FieldValidationException(org.summerb.approaches.validation.FieldValidationException) ValidationContext(org.summerb.approaches.validation.ValidationContext)

Example 9 with ValidationContext

use of org.summerb.approaches.validation.ValidationContext in project summerb by skarpushin.

the class UsersServiceFacadeImpl method validatePasswordReset.

protected void validatePasswordReset(PasswordReset resetPasswordRequest) throws FieldValidationException {
    ValidationContext ctx = new ValidationContext();
    validatePassword(resetPasswordRequest.getPassword(), ctx);
    if (!resetPasswordRequest.getPassword().equals(resetPasswordRequest.getNewPasswordAgain())) {
        ctx.add(new PasswordsDontMatchValidationError());
    }
    ctx.throwIfHasErrors();
}
Also used : PasswordsDontMatchValidationError(org.summerb.approaches.springmvc.security.ve.PasswordsDontMatchValidationError) ValidationContext(org.summerb.approaches.validation.ValidationContext)

Example 10 with ValidationContext

use of org.summerb.approaches.validation.ValidationContext in project summerb by skarpushin.

the class StringTemplateValidationUtilsTest method testValidateStringTemplate_blackbox_expectOkForValidExpression.

@Test
public void testValidateStringTemplate_blackbox_expectOkForValidExpression() throws Exception {
    StringTemplateCompiler stringTemplateCompiler = new StringTemplateCompilerlImpl();
    String stringTemplate = "Constant text plus ${vars['4444']}";
    ValidationContext ctx = new ValidationContext();
    String fieldToken = "fieldToken";
    StringTemplateValidationUtils.validateStringTemplate(stringTemplateCompiler, stringTemplate, ctx, fieldToken);
    assertEquals(false, ctx.getHasErrors());
}
Also used : StringTemplateCompilerlImpl(org.summerb.utils.stringtemplate.impl.StringTemplateCompilerlImpl) StringTemplateCompiler(org.summerb.utils.stringtemplate.api.StringTemplateCompiler) ValidationContext(org.summerb.approaches.validation.ValidationContext) Test(org.junit.Test)

Aggregations

ValidationContext (org.summerb.approaches.validation.ValidationContext)12 FieldValidationException (org.summerb.approaches.validation.FieldValidationException)5 Test (org.junit.Test)3 StringTemplateCompiler (org.summerb.utils.stringtemplate.api.StringTemplateCompiler)3 StringTemplateCompilerlImpl (org.summerb.utils.stringtemplate.impl.StringTemplateCompilerlImpl)3 User (org.summerb.microservices.users.api.dto.User)2 UserStatus (org.summerb.approaches.springmvc.security.dto.UserStatus)1 PasswordsDontMatchValidationError (org.summerb.approaches.springmvc.security.ve.PasswordsDontMatchValidationError)1 RegistrationRequiredValidationError (org.summerb.approaches.springmvc.security.ve.RegistrationRequiredValidationError)1 UserNotFoundException (org.summerb.microservices.users.api.exceptions.UserNotFoundException)1