Search in sources :

Example 1 with ConstraintViolationBuilder

use of javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder in project api-core by ca-cwds.

the class SystemCodeIdValidatorTest method isValid_Args__Object__ValidWhenIgnoredValue0.

@Test
public void isValid_Args__Object__ValidWhenIgnoredValue0() throws Exception {
    ValidSystemCodeId anno = mock(ValidSystemCodeId.class);
    when(anno.required()).thenReturn(false);
    when(anno.ignoreable()).thenReturn(true);
    when(anno.ignoredValue()).thenReturn(0);
    when(anno.category()).thenReturn("ETHNCTYC");
    target.initialize(anno);
    Set<String> validCodes = new HashSet<>();
    validCodes.add("0");
    ConstraintValidatorContext context_ = mock(ConstraintValidatorContext.class);
    ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
    when(builder.addPropertyNode(any())).thenReturn(mock(NodeBuilderCustomizableContext.class));
    when(context_.buildConstraintViolationWithTemplate(any())).thenReturn(builder);
    boolean actual = target.isValid(validCodes, context_);
    boolean expected = true;
    assertThat(actual, is(equalTo(expected)));
}
Also used : ConstraintViolationBuilder(javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder) ConstraintValidatorContext(javax.validation.ConstraintValidatorContext) NodeBuilderCustomizableContext(javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with ConstraintViolationBuilder

use of javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder in project api-core by ca-cwds.

the class SystemCodeIdValidatorTest method isValid_Args__Object__InvalidCollectionValues.

@Test
public void isValid_Args__Object__InvalidCollectionValues() throws Exception {
    ValidSystemCodeId anno = mock(ValidSystemCodeId.class);
    when(anno.required()).thenReturn(true);
    when(anno.category()).thenReturn("ETHNCTYC");
    target.initialize(anno);
    Set<String> validCodes = new HashSet<>();
    validCodes.add("0");
    ConstraintValidatorContext context_ = mock(ConstraintValidatorContext.class);
    ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
    when(builder.addPropertyNode(any())).thenReturn(mock(NodeBuilderCustomizableContext.class));
    when(context_.buildConstraintViolationWithTemplate(any())).thenReturn(builder);
    boolean actual = target.isValid(validCodes, context_);
    boolean expected = false;
    assertThat(actual, is(equalTo(expected)));
}
Also used : ConstraintViolationBuilder(javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder) ConstraintValidatorContext(javax.validation.ConstraintValidatorContext) NodeBuilderCustomizableContext(javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ConstraintViolationBuilder

use of javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder in project syndesis by syndesisio.

the class UniquePropertyValidatorTest method shouldAscertainPropertyUniqueness.

@Test
public void shouldAscertainPropertyUniqueness() {
    final HibernateConstraintValidatorContext context = mock(HibernateConstraintValidatorContext.class);
    when(context.unwrap(HibernateConstraintValidatorContext.class)).thenReturn(context);
    when(context.addExpressionVariable(eq("nonUnique"), anyString())).thenReturn(context);
    when(context.getDefaultConstraintMessageTemplate()).thenReturn("template");
    final ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
    when(context.buildConstraintViolationWithTemplate("template")).thenReturn(builder);
    when(builder.addPropertyNode(anyString())).thenReturn(mock(NodeBuilderCustomizableContext.class));
    assertThat(validator.isValid(connection, context)).isEqualTo(validity);
}
Also used : ConstraintViolationBuilder(javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder) HibernateConstraintValidatorContext(org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext) NodeBuilderCustomizableContext(javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext) Test(org.junit.Test)

Aggregations

ConstraintViolationBuilder (javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder)3 NodeBuilderCustomizableContext (javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 ConstraintValidatorContext (javax.validation.ConstraintValidatorContext)2 HibernateConstraintValidatorContext (org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext)1