diff options
author | Harald Musum <musum@yahooinc.com> | 2022-04-20 08:23:39 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-04-20 08:23:39 +0200 |
commit | 3889010d96f7b844b182e7fccffdf7cbb07a85b2 (patch) | |
tree | 6049a31e5e4bdddb6bf2f7ecfb24c37a6478efe9 /config-model/src/test/java/com/yahoo/config/model/builder/xml/XmlErrorHandlingTest.java | |
parent | 2dcb262db7e0087cb7f2ea455c732fd1ea84dd6b (diff) |
Add error handler for XML parsing
Will output name of source if there is a warning or error
Diffstat (limited to 'config-model/src/test/java/com/yahoo/config/model/builder/xml/XmlErrorHandlingTest.java')
-rw-r--r-- | config-model/src/test/java/com/yahoo/config/model/builder/xml/XmlErrorHandlingTest.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/config-model/src/test/java/com/yahoo/config/model/builder/xml/XmlErrorHandlingTest.java b/config-model/src/test/java/com/yahoo/config/model/builder/xml/XmlErrorHandlingTest.java new file mode 100644 index 00000000000..ee616f59d04 --- /dev/null +++ b/config-model/src/test/java/com/yahoo/config/model/builder/xml/XmlErrorHandlingTest.java @@ -0,0 +1,37 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.config.model.builder.xml; + +import org.junit.Test; +import org.xml.sax.InputSource; +import java.io.FileReader; + +import static org.junit.Assert.assertEquals; + +/** + * @author hmusum + */ +public class XmlErrorHandlingTest { + + @Test + public void requireExceptionWithSourceAndFilenameAndLineNumber() { + try { + XmlHelper.getDocument(new FileReader("src/test/cfg/application/invalid-services-syntax/services.xml"), "services.xml"); + } catch (Exception e) { + assertEquals("Invalid XML in services.xml: The element type \"config\" must be terminated by the matching end-tag \"</config>\". [7:5]", + e.getMessage()); + } + } + + + @Test + public void requireExceptionWithLineNumber() { + try { + XmlHelper.getDocumentBuilder().parse( + new InputSource(new FileReader("src/test/cfg/application/invalid-services-syntax/services.xml"))); + } catch (Exception e) { + assertEquals("Invalid XML (unknown source): The element type \"config\" must be terminated by the matching end-tag \"</config>\". [7:5]", + e.getMessage()); + } + } + +} |