Search in sources :

Example 1 with ConstraintValidatorContext

use of javax.validation.ConstraintValidatorContext in project kie-wb-common by kiegroup.

the class TimerSettingsValueValidatorTest method gwtSetUp.

@Override
protected void gwtSetUp() throws Exception {
    super.gwtSetUp();
    validator = new TimerSettingsValueValidator();
    value = new TimerSettingsValue();
    context = new ConstraintValidatorContext() {

        @Override
        public void disableDefaultConstraintViolation() {
        }

        @Override
        public String getDefaultConstraintMessageTemplate() {
            return null;
        }

        @Override
        public ConstraintViolationBuilder buildConstraintViolationWithTemplate(String message) {
            errorMessages.add(message);
            return new ConstraintViolationBuilder() {

                @Override
                public NodeBuilderDefinedContext addNode(String name) {
                    return null;
                }

                @Override
                public ConstraintValidatorContext addConstraintViolation() {
                    return context;
                }
            };
        }
    };
}
Also used : ConstraintValidatorContext(javax.validation.ConstraintValidatorContext) TimerSettingsValue(org.kie.workbench.common.stunner.bpmn.definition.property.event.timer.TimerSettingsValue)

Example 2 with ConstraintValidatorContext

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

the class SystemCodeDescriptionValidatorTest method isValid_Args__Object__ConstraintValidatorContext.

@Test
public void isValid_Args__Object__ConstraintValidatorContext() throws Exception {
    SystemCodeDescriptionValidator target = new SystemCodeDescriptionValidator();
    String value = "";
    ConstraintValidatorContext context_ = mock(ConstraintValidatorContext.class);
    boolean actual = target.isValid(value, context_);
    boolean expected = false;
    assertThat(actual, is(equalTo(expected)));
}
Also used : ConstraintValidatorContext(javax.validation.ConstraintValidatorContext) Test(org.junit.Test)

Example 3 with ConstraintValidatorContext

use of javax.validation.ConstraintValidatorContext 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 4 with ConstraintValidatorContext

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

the class SystemCodeIdValidatorTest method isValid_Args__Object__EmptyCollectionPassWhenIgnorableTrue.

@Test
public void isValid_Args__Object__EmptyCollectionPassWhenIgnorableTrue() throws Exception {
    ValidSystemCodeId anno = mock(ValidSystemCodeId.class);
    when(anno.required()).thenReturn(false);
    when(anno.ignoreable()).thenReturn(true);
    target.initialize(anno);
    Set<String> validCodes = new HashSet<>();
    ConstraintValidatorContext context_ = mock(ConstraintValidatorContext.class);
    boolean actual = target.isValid(validCodes, context_);
    boolean expected = true;
    assertThat(actual, is(equalTo(expected)));
}
Also used : ConstraintValidatorContext(javax.validation.ConstraintValidatorContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ConstraintValidatorContext

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

the class SystemCodeIdValidatorTest method isValid_Args__Object__EmptyCollection.

@Test
public void isValid_Args__Object__EmptyCollection() throws Exception {
    ValidSystemCodeId anno = mock(ValidSystemCodeId.class);
    when(anno.required()).thenReturn(true);
    target.initialize(anno);
    Set<String> validCodes = new HashSet<>();
    ConstraintValidatorContext context_ = mock(ConstraintValidatorContext.class);
    boolean actual = target.isValid(validCodes, context_);
    boolean expected = false;
    assertThat(actual, is(equalTo(expected)));
}
Also used : ConstraintValidatorContext(javax.validation.ConstraintValidatorContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ConstraintValidatorContext (javax.validation.ConstraintValidatorContext)11 Test (org.junit.Test)9 HashSet (java.util.HashSet)5 ConstraintViolationBuilder (javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder)2 NodeBuilderCustomizableContext (javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 DroolsConfiguration (gov.ca.cwds.drools.DroolsConfiguration)1 DroolsErrorMessages (gov.ca.cwds.drools.DroolsErrorMessages)1 DroolsException (gov.ca.cwds.drools.DroolsException)1 DroolsService (gov.ca.cwds.drools.DroolsService)1 InjectorHolder (gov.ca.cwds.inject.InjectorHolder)1 IssueDetails (gov.ca.cwds.rest.exception.IssueDetails)1 JsonUtils (gov.ca.cwds.utils.JsonUtils)1 Annotation (java.lang.annotation.Annotation)1 Set (java.util.Set)1 ConstraintValidator (javax.validation.ConstraintValidator)1 TimerSettingsValue (org.kie.workbench.common.stunner.bpmn.definition.property.event.timer.TimerSettingsValue)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1