javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder Java Examples
The following examples show how to use
javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConstraintViolationFactory.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Override public boolean isValid(final HelperBean bean, final ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); // build a custom property path ConstraintViolationBuilder builder = context.buildConstraintViolationWithTemplate(getEscapeHelper().stripJavaEl(bean.getMessage())); NodeBuilderCustomizableContext nodeBuilder = null; for (String part : bean.getPath().split("\\.")) { if (nodeBuilder == null) { nodeBuilder = builder.addPropertyNode(part); } else { nodeBuilder = nodeBuilder.addPropertyNode(part); } } if (nodeBuilder != null) { nodeBuilder.addConstraintViolation(); } return false; }
Example #2
Source File: EitherServerConfigsOrServerValidatorTest.java From tessera with Apache License 2.0 | 5 votes |
@Before public void onSetUp() { eitherServerConfigsOrServerValidator = new EitherServerConfigsOrServerValidator(); constraintContext = mock(ConstraintValidatorContext.class); ConstraintViolationBuilder constraintViolationBuilder = mock(ConstraintValidatorContext.ConstraintViolationBuilder.class); when(constraintContext.buildConstraintViolationWithTemplate(anyString())).thenReturn(constraintViolationBuilder); }
Example #3
Source File: UniquePropertyValidatorTest.java From syndesis with Apache License 2.0 | 5 votes |
@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); }
Example #4
Source File: AbstractValidatorTest.java From cloudbreak with Apache License 2.0 | 5 votes |
ConstraintViolationBuilder getConstraintViolationBuilder() { return new ConstraintValidatorContextImpl(null, PathImpl.createRootPath(), new DummyConstraintDescriptor(), null ).buildConstraintViolationWithTemplate("dummytemplate"); }
Example #5
Source File: DistroXAutoscaleRequestValidatorTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Before public void setupMocks() { constraintViolationBuilder = mock(ConstraintValidatorContext.ConstraintViolationBuilder.class); nodeBuilderCustomizableContext = mock(ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext.class); validatorContext = mock(ConstraintValidatorContext.class); when(validatorContext.buildConstraintViolationWithTemplate(any())).thenReturn(constraintViolationBuilder); when(constraintViolationBuilder.addPropertyNode(any())).thenReturn(nodeBuilderCustomizableContext); when(nodeBuilderCustomizableContext.addConstraintViolation()).thenReturn(validatorContext); doNothing().when(validatorContext).disableDefaultConstraintViolation(); }
Example #6
Source File: SingleOutputValidatorTest.java From sejda with GNU Affero General Public License v3.0 | 5 votes |
@Test public void destinationExistsPolicyFail() throws IOException { ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class); when(context.buildConstraintViolationWithTemplate(anyString())).thenReturn(builder); SetMetadataParameters params = new SetMetadataParameters(); params.setOutput(new FileTaskOutput(folder.newFile())); params.setExistingOutputPolicy(ExistingOutputPolicy.FAIL); assertFalse(victim.isValid(params, context)); verify(context).buildConstraintViolationWithTemplate(contains("File destination already exists")); }
Example #7
Source File: SingleOutputValidatorTest.java From sejda with GNU Affero General Public License v3.0 | 5 votes |
@Test public void destinationExistsPolicySkip() throws IOException { ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class); when(context.buildConstraintViolationWithTemplate(anyString())).thenReturn(builder); SetMetadataParameters params = new SetMetadataParameters(); params.setOutput(new FileTaskOutput(folder.newFile())); params.setExistingOutputPolicy(ExistingOutputPolicy.SKIP); assertFalse(victim.isValid(params, context)); verify(context).buildConstraintViolationWithTemplate(contains("File destination already exists")); }
Example #8
Source File: PdfVersionValidatorTest.java From sejda with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testInvalidValue() { ConstraintValidatorContext context = mock(ConstraintValidatorContext.class); ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class); when(context.buildConstraintViolationWithTemplate(anyString())).thenReturn(builder); NodeBuilderDefinedContext nodeBuilderContext = mock(NodeBuilderDefinedContext.class); when(builder.addNode(anyString())).thenReturn(nodeBuilderContext); when(params.getVersion()).thenReturn(PdfVersion.VERSION_1_2); when(params.getMinRequiredPdfVersion()).thenReturn(PdfVersion.VERSION_1_5); assertFalse(victim.isValid(params, context)); verify(context).buildConstraintViolationWithTemplate(anyString()); }