private ModelBeanViolation buildViolation(final ConstraintViolation<?> rootViolation) { LOGGER.log(Level.INFO, "Bean constraint violation found with message [" + rootViolation.getMessage() + "]"); return ModelBeanViolationImpl.Builder.build(rootViolation); } }
@Test @SuppressWarnings("unchecked") public void testDiagramValidationMessage() { final ConstraintViolation<?> rootViolation = mock(ConstraintViolation.class); final Path propertyPath = mock(Path.class); when(propertyPath.toString()).thenReturn("path1"); when(rootViolation.getPropertyPath()).thenReturn(propertyPath); when(rootViolation.getMessage()).thenReturn("message1"); final ModelBeanViolation beanViolation = ModelBeanViolationImpl.Builder.build(rootViolation); final RuleViolation ruleViolation = mock(RuleViolation.class); final DiagramElementViolation<RuleViolation> diagramViolation = mock(DiagramElementViolation.class); when(diagramViolation.getUUID()).thenReturn("uuid1"); when(diagramViolation.getModelViolations()).thenReturn(Collections.singletonList(beanViolation)); when(diagramViolation.getGraphViolations()).thenReturn(Collections.singletonList(ruleViolation)); when(ruleViolation.getViolationType()).thenReturn(Violation.Type.WARNING); when(translationService.getViolationMessage(eq(ruleViolation))).thenReturn("rv1"); when(translationService.getValue(eq("aKey"))).thenReturn("aValue"); String message = CoreTranslationMessages.getDiagramValidationsErrorMessage(translationService, "aKey", Collections.singleton(diagramViolation)); message = new SafeHtmlBuilder().appendEscapedLines(message).toSafeHtml().asString(); assertEquals("aValue." + HTML_NEW_LINE + "R" + COLON + HTML_NEW_LINE + OPEN_BRA + "E" + COLON + "uuid1" + CLOSE_BRA + HTML_NEW_LINE + "(WARNING) " + HTML_OPEN_COMMENT + "path1" + HTML_CLOSE_COMMENT + "message1" + HTML_NEW_LINE + "(WARNING) rv1" + HTML_NEW_LINE, message); } }
@Test public void testBeanValidationMessage() { final ConstraintViolation<?> rootViolation = mock(ConstraintViolation.class); final Path propertyPath = mock(Path.class); when(propertyPath.toString()).thenReturn("path1"); when(rootViolation.getPropertyPath()).thenReturn(propertyPath); when(rootViolation.getMessage()).thenReturn("message1"); final ModelBeanViolation violation = ModelBeanViolationImpl.Builder.build(rootViolation); final String message = CoreTranslationMessages.getBeanValidationMessage(translationService, violation); assertEquals("(WARNING) " + OPEN_COMMENT + "path1" + CLOSE_COMMENT + "message1", message); }