use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForParameterTest method canDeclareNestedContainerElementConstraintsForParameterProgrammatically.
@Test
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareNestedContainerElementConstraintsForParameterProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(IFishTank.class).method("test2", Map.class).parameter(0).containerElementType(1, 0).constraint(new NotNullDef());
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
try {
Map<String, List<Fish>> fishOfTheMonth = new HashMap<>();
List<Fish> january = Arrays.asList(null, new Fish());
fishOfTheMonth.put("january", january);
fishTank.test2(fishOfTheMonth);
fail("Expected exception wasn't raised");
} catch (ConstraintViolationException e) {
assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null"));
}
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForParameterTest method canDeclareDeeplyNestedContainerElementConstraintsForParameterProgrammatically.
@Test
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareDeeplyNestedContainerElementConstraintsForParameterProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(IFishTank.class).method("test3", List.class).parameter(0).containerElementType(0, 1, 0).constraint(new NotNullDef());
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
try {
Set<String> bobsTags = CollectionHelper.asSet((String) null);
Map<String, Set<String>> januaryTags = new HashMap<>();
januaryTags.put("bob", bobsTags);
List<Map<String, Set<String>>> tagsOfFishOfTheMonth = new ArrayList<>();
tagsOfFishOfTheMonth.add(januaryTags);
fishTank.test3(tagsOfFishOfTheMonth);
fail("Expected exception wasn't raised");
} catch (ConstraintViolationException e) {
assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null"));
}
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForReturnValueTest method canDeclareDeeplyNestedContainerElementConstraintsForReturnValueProgrammatically.
@Test
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareDeeplyNestedContainerElementConstraintsForReturnValueProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(IFishTank.class).method("test3").returnValue().containerElementType(0, 1, 0).constraint(new NotNullDef());
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
try {
fishTank.test3();
fail("Expected exception wasn't raised");
} catch (ConstraintViolationException e) {
assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null"));
}
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForReturnValueTest method canDeclareContainerElementCascadesForReturnValueProgrammatically.
@Test
@TestForIssue(jiraKey = "HV-1239")
public void canDeclareContainerElementCascadesForReturnValueProgrammatically() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(IFishTank.class).method("test4").returnValue().containerElementType().valid().type(Fish.class).field("name").constraint(new NotNullDef());
config.addMapping(newMapping);
Validator validator = config.buildValidatorFactory().getValidator();
IFishTank fishTank = ValidatorUtil.getValidatingProxy(new FishTank(), validator);
try {
fishTank.test4();
fail("Expected exception wasn't raised");
} catch (ConstraintViolationException e) {
assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(NotNull.class).withMessage("must not be null"));
}
}
use of org.hibernate.validator.cfg.defs.NotNullDef in project hibernate-validator by hibernate.
the class ProgrammaticContainerElementConstraintsForReturnValueTest method configuringSameContainerElementTwiceCausesException.
@Test(expectedExceptions = ValidationException.class, expectedExceptionsMessageRegExp = "HV000214.*")
@TestForIssue(jiraKey = "HV-1239")
public void configuringSameContainerElementTwiceCausesException() {
ConstraintMapping newMapping = config.createConstraintMapping();
newMapping.type(FishTank.class).method("test3").returnValue().containerElementType(0, 1, 0).constraint(new NotNullDef()).containerElementType(0, 1, 0);
}
Aggregations