@Test
public void createErrorElementsTest() throws ParserConfigurationException, XPathExpressionException {

  final ValidationResult vr = new ValidationResult();
  vr.addError( "parameter1", new ValidationMessage( "not good" ) );
  vr.addError( "parameter2", new ValidationMessage( "not good at all" ) );
  vr.addError( new ValidationMessage( "kernel panic" ) );
  // save parameter name - attribute value mapping
  final Map<String, String> attrMap = new HashMap();
  attrMap.put( "parameter3", "" );
  attrMap.put( "parameter2", "not good at all" );
  attrMap.put( "parameter1", "not good" );
  handler.document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
  final Element el = handler.createErrorElements( vr );
  handler.document.appendChild( el );
  assertNotNull( el );
  assertEquals( 3, el.getChildNodes().getLength() );
  // use xpath for future validation just to get rid of numerous for() loops in DOM api
  final XPath xpath = xpathFactory.newXPath();
  final NodeList found =
    NodeList.class.cast( xpath.evaluate( "/errors/error", handler.document, XPathConstants.NODESET ) );
  assertNotNull( found );
  for ( int i = 0; i < found.getLength(); i++ ) {
    final Node node = found.item( i );
    assertEquals( "error", node.getNodeName() );
    final Element oneError = (Element) node;
    final String paramName = oneError.getAttribute( "parameter" );
    assertTrue( attrMap.containsKey( paramName ) );
    assertEquals( attrMap.get( paramName ), oneError.getAttribute( "message" ) );
  }
  final Node globalError = (Node) xpath.evaluate( "/errors/global-error", handler.document, XPathConstants.NODE );
  assertNotNull( globalError );
  assertEquals( "global-error", globalError.getNodeName() );
  final Element globalErrEl = Element.class.cast( globalError );
  assertEquals( "kernel panic", globalErrEl.getAttribute( "message" ) );
}