Search in sources :

Example 91 with ConstraintViolation

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

the class CmsDocumentBlobSegmentTest method testConstraintDocSegmentSize.

@Test
public void testConstraintDocSegmentSize() throws Exception {
    CmsDocumentBlobSegment blob = new CmsDocumentBlobSegment(docHandle, "002", docBlob);
    Set<ConstraintViolation<CmsDocumentBlobSegment>> violations = validator.validate(blob);
    assertEquals(2, violations.size());
// assertEquals("size must be between 4 and 4", violations.iterator().next().getMessage());
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) CmsDocumentBlobSegment(gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment) Test(org.junit.Test)

Example 92 with ConstraintViolation

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

the class CmsDocumentBlobSegmentTest method testConstraintBlobMinSize.

@Test
public void testConstraintBlobMinSize() throws Exception {
    CmsDocumentBlobSegment blob = new CmsDocumentBlobSegment(docHandle, segmentSequence, "");
    Set<ConstraintViolation<CmsDocumentBlobSegment>> violations = validator.validate(blob);
    assertEquals(1, violations.size());
    assertEquals("size must be between 1 and 4000", violations.iterator().next().getMessage());
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) CmsDocumentBlobSegment(gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment) Test(org.junit.Test)

Example 93 with ConstraintViolation

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

the class CmsDocumentBlobSegmentTest method testConstraintBlobMaxSize.

@Test
public void testConstraintBlobMaxSize() throws Exception {
    StringBuilder buf = new StringBuilder();
    final String alphabet = "abcefghijklmnopqrstuvwxyz";
    for (int i = 0; i < 1000; i++) {
        buf.append(alphabet);
    }
    final String theBlob = buf.toString();
    CmsDocumentBlobSegment blob = new CmsDocumentBlobSegment(docHandle, segmentSequence, theBlob);
    Set<ConstraintViolation<CmsDocumentBlobSegment>> violations = validator.validate(blob);
    assertEquals(1, violations.size());
    assertEquals("size must be between 1 and 4000", violations.iterator().next().getMessage());
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) CmsDocumentBlobSegment(gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment) Test(org.junit.Test)

Example 94 with ConstraintViolation

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

the class CmsDocumentBlobSegmentTest method testConstraintDocHandleSize.

@Test
public void testConstraintDocHandleSize() throws Exception {
    CmsDocumentBlobSegment blob = new CmsDocumentBlobSegment("0131351421120020*JONEM 00004", segmentSequence, docBlob);
    Set<ConstraintViolation<CmsDocumentBlobSegment>> violations = validator.validate(blob);
    assertEquals(1, violations.size());
    assertEquals("size must be between 30 and 30", violations.iterator().next().getMessage());
}
Also used : ConstraintViolation(javax.validation.ConstraintViolation) CmsDocumentBlobSegment(gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment) Test(org.junit.Test)

Example 95 with ConstraintViolation

use of javax.validation.ConstraintViolation in project javaee7-firstcup by ecabrerar.

the class BooksCollectionTest method shouldReturnAValidationError.

@Test
public void shouldReturnAValidationError() {
    Book book = new Book("Effective Java", "2234555568", "");
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    Set<ConstraintViolation<Book>> violations = validator.validate(book);
    Assert.assertEquals(2, violations.size());
    System.out.println(violations.stream().map(error -> error.getMessage()).collect(Collectors.joining(", ")));
}
Also used : Book(org.ecabrerar.examples.javax.rs.validation.domain.Book) ConstraintViolation(javax.validation.ConstraintViolation) Validator(javax.validation.Validator) Test(org.junit.Test)

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