Search in sources :

Example 91 with ConstraintViolationException

use of jakarta.validation.ConstraintViolationException in project hibernate-validator by hibernate.

the class ContainerElementTypeConstraintsForParameterXmlMappingTest method canDeclareContainerElementTypeConstraintsForArrayTypeParameterWithXmlMapping.

// HV-1428 Container element support is disabled for arrays
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000226:.*")
@TestForIssue(jiraKey = "HV-1291")
public void canDeclareContainerElementTypeConstraintsForArrayTypeParameterWithXmlMapping() {
    Validator validator = getValidator("parameter-canDeclareContainerElementTypeConstraintsForArrayType-mapping.xml");
    IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
    try {
        fishTank.test5(new String[] { "Too Long" });
        fail("Expected exception wasn't raised");
    } catch (ConstraintViolationException e) {
        assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(Size.class).withMessage("size must be between 0 and 5"));
    }
}
Also used : Size(jakarta.validation.constraints.Size) ConstraintViolationException(jakarta.validation.ConstraintViolationException) Validator(jakarta.validation.Validator) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 92 with ConstraintViolationException

use of jakarta.validation.ConstraintViolationException in project hibernate-validator by hibernate.

the class ContainerElementTypeConstraintsForParameterXmlMappingTest method canDeclareContainerElementTypeConstraintsForListContainingArrayTypeParameterWithXmlMapping.

// HV-1428 Container element support is disabled for arrays
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000226:.*")
@TestForIssue(jiraKey = "HV-1291")
public void canDeclareContainerElementTypeConstraintsForListContainingArrayTypeParameterWithXmlMapping() {
    Validator validator = getValidator("parameter-canDeclareContainerElementTypeConstraintsForListContainingArrayType-mapping.xml");
    IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
    try {
        List<String[]> fishNamesByMonth = new ArrayList<>();
        fishNamesByMonth.add(new String[] { "Too Long" });
        fishTank.test6(fishNamesByMonth);
        fail("Expected exception wasn't raised");
    } catch (ConstraintViolationException e) {
        assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(Size.class).withMessage("size must be between 0 and 5"));
    }
}
Also used : Size(jakarta.validation.constraints.Size) ArrayList(java.util.ArrayList) ConstraintViolationException(jakarta.validation.ConstraintViolationException) Validator(jakarta.validation.Validator) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 93 with ConstraintViolationException

use of jakarta.validation.ConstraintViolationException in project hibernate-validator by hibernate.

the class ContainerElementTypeConstraintsForReturnValueXmlMappingTest method canDeclareContainerElementTypeConstraintsForListContainingArrayTypeReturnValueWithXmlMapping.

// HV-1428 Container element support is disabled for arrays
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000226:.*")
@TestForIssue(jiraKey = "HV-1291")
public void canDeclareContainerElementTypeConstraintsForListContainingArrayTypeReturnValueWithXmlMapping() {
    Validator validator = getValidator("returnvalue-canDeclareContainerElementTypeConstraintsForListContainingArrayType-mapping.xml");
    IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
    try {
        fishTank.test6();
        fail("Expected exception wasn't raised");
    } catch (ConstraintViolationException e) {
        assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(Size.class).withMessage("size must be between 0 and 5"));
    }
}
Also used : Size(jakarta.validation.constraints.Size) ConstraintViolationException(jakarta.validation.ConstraintViolationException) Validator(jakarta.validation.Validator) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 94 with ConstraintViolationException

use of jakarta.validation.ConstraintViolationException in project hibernate-validator by hibernate.

the class ContainerElementTypeConstraintsForReturnValueXmlMappingTest method canDeclareContainerElementTypeConstraintsForArrayTypeReturnValueWithXmlMapping.

// HV-1428 Container element support is disabled for arrays
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000226:.*")
@TestForIssue(jiraKey = "HV-1291")
public void canDeclareContainerElementTypeConstraintsForArrayTypeReturnValueWithXmlMapping() {
    Validator validator = getValidator("returnvalue-canDeclareContainerElementTypeConstraintsForArrayType-mapping.xml");
    IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
    try {
        fishTank.test5();
        fail("Expected exception wasn't raised");
    } catch (ConstraintViolationException e) {
        assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(Size.class).withMessage("size must be between 0 and 5"));
    }
}
Also used : Size(jakarta.validation.constraints.Size) ConstraintViolationException(jakarta.validation.ConstraintViolationException) Validator(jakarta.validation.Validator) Test(org.testng.annotations.Test) TestForIssue(org.hibernate.validator.testutil.TestForIssue)

Example 95 with ConstraintViolationException

use of jakarta.validation.ConstraintViolationException in project Clownfish by rawdog71.

the class TemplateList method onCreate.

@Override
public void onCreate(ActionEvent actionEvent) {
    try {
        if (!templateName.isBlank()) {
            CfTemplate newtemplate = new CfTemplate();
            newtemplate.setName(templateName);
            newtemplate.setContent("//" + templateName);
            newtemplate.setScriptlanguage(templateScriptLanguage);
            newtemplate.setLayout(layout);
            cftemplateService.create(newtemplate);
            templateListe = cftemplateService.findAll();
            templateName = "";
            selectedTemplate = newtemplate;
            refresh();
            onSelect(null);
            onCheckOut(null);
        } else {
            FacesMessage message = new FacesMessage("Please enter template name");
            FacesContext.getCurrentInstance().addMessage(null, message);
        }
    } catch (ConstraintViolationException ex) {
        LOGGER.error(ex.getMessage());
    }
}
Also used : ConstraintViolationException(jakarta.validation.ConstraintViolationException) FacesMessage(javax.faces.application.FacesMessage) CfTemplate(io.clownfish.clownfish.dbentities.CfTemplate)

Aggregations

ConstraintViolationException (jakarta.validation.ConstraintViolationException)114 Test (org.testng.annotations.Test)55 ConstraintMapping (org.hibernate.validator.cfg.ConstraintMapping)35 ConstraintViolation (jakarta.validation.ConstraintViolation)32 Validator (jakarta.validation.Validator)29 TestForIssue (org.hibernate.validator.testutil.TestForIssue)26 HibernateValidator (org.hibernate.validator.HibernateValidator)19 Size (jakarta.validation.constraints.Size)16 SizeDef (org.hibernate.validator.cfg.defs.SizeDef)15 Test (org.junit.Test)14 Session (org.hibernate.Session)10 Transaction (org.hibernate.Transaction)10 NotNullDef (org.hibernate.validator.cfg.defs.NotNullDef)10 CustomerRepositoryImpl (org.hibernate.validator.test.internal.engine.methodvalidation.service.CustomerRepositoryImpl)10 Customer (org.hibernate.validator.test.internal.engine.methodvalidation.model.Customer)9 FacesMessage (javax.faces.application.FacesMessage)8 NotNull (jakarta.validation.constraints.NotNull)7 BigDecimal (java.math.BigDecimal)7 Set (java.util.Set)7 EntityManager (jakarta.persistence.EntityManager)6