Search in sources :

Example 51 with ConstraintViolation

use of javax.validation.ConstraintViolation in project API by ca-cwds.

the class CmsDocumentBlobSegmentTest method testConstraintDocSegmentPattern.

@Test
public void testConstraintDocSegmentPattern() throws Exception {
    CmsDocumentBlobSegment blob = new CmsDocumentBlobSegment(docHandle, "abcd", docBlob);
    Set<ConstraintViolation<CmsDocumentBlobSegment>> violations = validator.validate(blob);
    assertEquals(1, violations.size());
// assertEquals("invalid DOC_HANDLE", violations.iterator().next().getMessage());
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) CmsDocumentBlobSegment(gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment) Test(org.junit.Test)

Example 52 with ConstraintViolation

use of javax.validation.ConstraintViolation in project API by ca-cwds.

the class CmsDocumentBlobSegmentTest method testConstraintDocHandlePattern.

// ====================
// DOC_HANDLE
// ====================
@Test
public void testConstraintDocHandlePattern() throws Exception {
    CmsDocumentBlobSegment blob = new CmsDocumentBlobSegment("123456789012345678901234567890", segmentSequence, docBlob);
    Set<ConstraintViolation<CmsDocumentBlobSegment>> violations = validator.validate(blob);
    assertEquals(1, violations.size());
    assertEquals("invalid DOC_HANDLE", violations.iterator().next().getMessage());
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) CmsDocumentBlobSegment(gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment) Test(org.junit.Test)

Example 53 with ConstraintViolation

use of javax.validation.ConstraintViolation in project API by ca-cwds.

the class CmsDocumentBlobSegmentTest method testConstraintDocSegmentNull.

// ====================
// DOC_SEGMENT
// ====================
@Test
public void testConstraintDocSegmentNull() throws Exception {
    CmsDocumentBlobSegment blob = new CmsDocumentBlobSegment(docHandle, null, docBlob);
    Set<ConstraintViolation<CmsDocumentBlobSegment>> violations = validator.validate(blob);
    assertEquals(1, violations.size());
    assertEquals("may not be null", violations.iterator().next().getMessage());
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) CmsDocumentBlobSegment(gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment) Test(org.junit.Test)

Example 54 with ConstraintViolation

use of javax.validation.ConstraintViolation in project dropwizard by dropwizard.

the class JerseyViolationExceptionMapper method toResponse.

@Override
public Response toResponse(final JerseyViolationException exception) {
    final Set<ConstraintViolation<?>> violations = exception.getConstraintViolations();
    final Invocable invocable = exception.getInvocable();
    final ImmutableList<String> errors = FluentIterable.from(exception.getConstraintViolations()).transform(violation -> ConstraintMessage.getMessage(violation, invocable)).toList();
    final int status = ConstraintMessage.determineStatus(violations, invocable);
    return Response.status(status).entity(new ValidationErrorMessage(errors)).build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Response(javax.ws.rs.core.Response) Provider(javax.ws.rs.ext.Provider) FluentIterable(com.google.common.collect.FluentIterable) ExceptionMapper(javax.ws.rs.ext.ExceptionMapper) Set(java.util.Set) ConstraintViolation(javax.validation.ConstraintViolation) Invocable(org.glassfish.jersey.server.model.Invocable) Invocable(org.glassfish.jersey.server.model.Invocable) ConstraintViolation(javax.validation.ConstraintViolation)

Example 55 with ConstraintViolation

use of javax.validation.ConstraintViolation in project dropwizard by dropwizard.

the class ConfigurationValidationExceptionTest method setUp.

@Before
public void setUp() throws Exception {
    assumeThat(Locale.getDefault().getLanguage(), is("en"));
    final Validator validator = BaseValidator.newValidator();
    final Set<ConstraintViolation<Example>> violations = validator.validate(new Example());
    this.e = new ConfigurationValidationException("config.yml", violations);
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) Validator(javax.validation.Validator) BaseValidator(io.dropwizard.validation.BaseValidator) Before(org.junit.Before)

Aggregations

ConstraintViolation (javax.validation.ConstraintViolation)95 Test (org.junit.Test)78 Validator (javax.validation.Validator)19 ConstraintViolationException (javax.validation.ConstraintViolationException)12 SMSMessage (org.apache.camel.component.cm.client.SMSMessage)12 ChangePasswordForm (org.orcid.frontend.web.forms.ChangePasswordForm)11 CmsDocumentBlobSegment (gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment)10 ValidatorFactory (javax.validation.ValidatorFactory)9 ManagePasswordOptionsForm (org.orcid.frontend.web.forms.ManagePasswordOptionsForm)8 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 CMConfiguration (org.apache.camel.component.cm.CMConfiguration)6 Set (java.util.Set)5 InitialContext (javax.naming.InitialContext)5 Session (org.hibernate.Session)5 Transaction (org.hibernate.Transaction)5 Method (java.lang.reflect.Method)4 ExecutableValidator (javax.validation.executable.ExecutableValidator)4 CamelExecutionException (org.apache.camel.CamelExecutionException)4 Exchange (org.apache.camel.Exchange)4