Search in sources :

Example 1 with GroupDefinitionException

use of jakarta.validation.GroupDefinitionException in project resteasy by resteasy.

the class ResteasyViolationExceptionMapper method toResponse.

public Response toResponse(ValidationException exception) {
    if (exception instanceof ConstraintDefinitionException) {
        return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
    }
    if (exception instanceof ConstraintDeclarationException) {
        return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
    }
    if (exception instanceof GroupDefinitionException) {
        return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
    }
    if (exception instanceof ResteasyViolationException) {
        ResteasyViolationException resteasyViolationException = ResteasyViolationException.class.cast(exception);
        Exception e = resteasyViolationException.getException();
        if (e != null) {
            return buildResponse(unwrapException(e), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
        } else if (resteasyViolationException.getReturnValueViolations().size() == 0) {
            return buildViolationReportResponse(resteasyViolationException, Status.BAD_REQUEST);
        } else {
            return buildViolationReportResponse(resteasyViolationException, Status.INTERNAL_SERVER_ERROR);
        }
    }
    return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
}
Also used : GroupDefinitionException(jakarta.validation.GroupDefinitionException) ConstraintDeclarationException(jakarta.validation.ConstraintDeclarationException) ResteasyViolationException(org.jboss.resteasy.api.validation.ResteasyViolationException) ResteasyViolationException(org.jboss.resteasy.api.validation.ResteasyViolationException) ConstraintDeclarationException(jakarta.validation.ConstraintDeclarationException) ConstraintDefinitionException(jakarta.validation.ConstraintDefinitionException) ValidationException(jakarta.validation.ValidationException) GroupDefinitionException(jakarta.validation.GroupDefinitionException) ConstraintDefinitionException(jakarta.validation.ConstraintDefinitionException)

Example 2 with GroupDefinitionException

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

the class GroupC method testAssertDefaultGroupSequenceIsExpandableWithDefaultAtBeginningOfSequence.

@Test
public void testAssertDefaultGroupSequenceIsExpandableWithDefaultAtBeginningOfSequence() {
    // create a dummy sequence
    Group a = new Group(GroupA.class);
    Group b = new Group(GroupB.class);
    Group c = new Group(GroupC.class);
    Group defaultGroup = Group.DEFAULT_GROUP;
    List<Group> sequence = new ArrayList<Group>();
    sequence.add(defaultGroup);
    sequence.add(a);
    sequence.add(b);
    sequence.add(c);
    DefaultValidationOrder chain = new DefaultValidationOrder();
    chain.insertSequence(new Sequence(TestSequence.class, sequence));
    // create test default sequence
    List<Class<?>> defaultSequence = new ArrayList<Class<?>>();
    defaultSequence.add(Default.class);
    defaultSequence.add(GroupA.class);
    chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
    defaultSequence.clear();
    defaultSequence.add(GroupA.class);
    defaultSequence.add(Default.class);
    try {
        chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
        fail();
    } catch (GroupDefinitionException e) {
    // success
    }
    defaultSequence.clear();
    defaultSequence.add(Default.class);
    defaultSequence.add(GroupC.class);
    try {
        chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
        fail();
    } catch (GroupDefinitionException e) {
    // success
    }
    defaultSequence.clear();
    defaultSequence.add(GroupC.class);
    defaultSequence.add(Default.class);
    try {
        chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
        fail();
    } catch (GroupDefinitionException e) {
    // success
    }
}
Also used : Group(org.hibernate.validator.internal.engine.groups.Group) GroupDefinitionException(jakarta.validation.GroupDefinitionException) ArrayList(java.util.ArrayList) Sequence(org.hibernate.validator.internal.engine.groups.Sequence) DefaultValidationOrder(org.hibernate.validator.internal.engine.groups.DefaultValidationOrder) Test(org.testng.annotations.Test)

Example 3 with GroupDefinitionException

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

the class GroupC method testAssertDefaultGroupSequenceIsExpandableWithDefaultAtEndOfSequence.

@Test
public void testAssertDefaultGroupSequenceIsExpandableWithDefaultAtEndOfSequence() {
    // create a dummy sequence
    Group a = new Group(GroupA.class);
    Group b = new Group(GroupB.class);
    Group c = new Group(GroupC.class);
    Group defaultGroup = Group.DEFAULT_GROUP;
    List<Group> sequence = new ArrayList<Group>();
    sequence.add(a);
    sequence.add(b);
    sequence.add(c);
    sequence.add(defaultGroup);
    DefaultValidationOrder chain = new DefaultValidationOrder();
    chain.insertSequence(new Sequence(TestSequence.class, sequence));
    // create test default sequence
    List<Class<?>> defaultSequence = new ArrayList<Class<?>>();
    defaultSequence.add(Default.class);
    defaultSequence.add(GroupA.class);
    try {
        chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
        fail();
    } catch (GroupDefinitionException e) {
    // success
    }
    defaultSequence.clear();
    defaultSequence.add(GroupA.class);
    defaultSequence.add(Default.class);
    try {
        chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
        fail();
    } catch (GroupDefinitionException e) {
    // success
    }
    defaultSequence.clear();
    defaultSequence.add(Default.class);
    defaultSequence.add(GroupC.class);
    try {
        chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
        fail();
    } catch (GroupDefinitionException e) {
    // success
    }
    defaultSequence.clear();
    defaultSequence.add(GroupC.class);
    defaultSequence.add(Default.class);
    chain.assertDefaultGroupSequenceIsExpandable(defaultSequence);
}
Also used : Group(org.hibernate.validator.internal.engine.groups.Group) GroupDefinitionException(jakarta.validation.GroupDefinitionException) ArrayList(java.util.ArrayList) Sequence(org.hibernate.validator.internal.engine.groups.Sequence) DefaultValidationOrder(org.hibernate.validator.internal.engine.groups.DefaultValidationOrder) Test(org.testng.annotations.Test)

Aggregations

GroupDefinitionException (jakarta.validation.GroupDefinitionException)3 ArrayList (java.util.ArrayList)2 DefaultValidationOrder (org.hibernate.validator.internal.engine.groups.DefaultValidationOrder)2 Group (org.hibernate.validator.internal.engine.groups.Group)2 Sequence (org.hibernate.validator.internal.engine.groups.Sequence)2 Test (org.testng.annotations.Test)2 ConstraintDeclarationException (jakarta.validation.ConstraintDeclarationException)1 ConstraintDefinitionException (jakarta.validation.ConstraintDefinitionException)1 ValidationException (jakarta.validation.ValidationException)1 ResteasyViolationException (org.jboss.resteasy.api.validation.ResteasyViolationException)1