Search in sources :

Example 96 with SAXParseException

use of org.xml.sax.SAXParseException in project gocd by gocd.

the class XsdErrorTranslatorTest method shouldOnlyRememberTheFirstValidationError.

@Test
public void shouldOnlyRememberTheFirstValidationError() throws Exception {
    translator.error(new SAXParseException("cvc-attribute.3: The value 'abc!!!' of attribute 'name' on element 'environment' is not valid with respect to its type, 'nameType'", null));
    translator.error(new SAXParseException("cvc-elt.1: Cannot find the declaration of element 'element'", null));
    assertThat(translator.translate(), is("\"abc!!!\" is invalid for Environment name"));
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Test(org.junit.Test)

Example 97 with SAXParseException

use of org.xml.sax.SAXParseException in project gocd by gocd.

the class XsdErrorTranslatorTest method shouldReturnOriginalErrorIfErrorMessageDoesNotContainCVCPattern.

@Test
public void shouldReturnOriginalErrorIfErrorMessageDoesNotContainCVCPattern() throws Exception {
    translator.error(new SAXParseException("Duplicate unique value [coverage] declared for identity constraint of element \"properties\".", null));
    assertThat(translator.translate(), is("Duplicate unique value [coverage] declared for identity constraint of element \"properties\"."));
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Test(org.junit.Test)

Example 98 with SAXParseException

use of org.xml.sax.SAXParseException in project gocd by gocd.

the class XsdErrorTranslatorTest method shouldHumanizeTheNameTypeInTheErrorMessage.

@Test
public void shouldHumanizeTheNameTypeInTheErrorMessage() throws SAXException {
    translator.error(new SAXParseException("cvc-pattern-valid: Value 'abc!!' is not facet-valid with respect to pattern '[Some-Pattern]' for type 'environmentName'.", null));
    assertThat(translator.translate(), is("Environment name is invalid. \"abc!!\" should conform to the pattern - [Some-Pattern]"));
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Test(org.junit.Test)

Example 99 with SAXParseException

use of org.xml.sax.SAXParseException in project gocd by gocd.

the class XsdErrorTranslatorTest method shouldTranslateEvenIfSomeArgumentsAreEmpty.

@Test
public void shouldTranslateEvenIfSomeArgumentsAreEmpty() throws Exception {
    translator.error(new SAXParseException("cvc-attribute.3: The value '' of attribute 'name' on element 'environment' is not valid with respect to its type, 'nameType'", null));
    assertThat(translator.translate(), is("\"\" is invalid for Environment name"));
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Test(org.junit.Test)

Example 100 with SAXParseException

use of org.xml.sax.SAXParseException in project gocd by gocd.

the class XsdErrorTranslatorTest method shouldTranslateXsdErrorIfMappingDefined.

@Test
public void shouldTranslateXsdErrorIfMappingDefined() throws Exception {
    translator.error(new SAXParseException("cvc-attribute.3: The value 'abc!!!' of attribute 'name' on element 'environment' is not valid with respect to its type, 'nameType'", null));
    assertThat(translator.translate(), is("\"abc!!!\" is invalid for Environment name"));
}
Also used : SAXParseException(org.xml.sax.SAXParseException) Test(org.junit.Test)

Aggregations

SAXParseException (org.xml.sax.SAXParseException)168 SAXException (org.xml.sax.SAXException)100 IOException (java.io.IOException)64 DocumentBuilder (javax.xml.parsers.DocumentBuilder)48 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)43 Document (org.w3c.dom.Document)43 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)39 InputSource (org.xml.sax.InputSource)33 ErrorHandler (org.xml.sax.ErrorHandler)31 Test (org.junit.Test)22 InputStream (java.io.InputStream)18 FileNotFoundException (java.io.FileNotFoundException)16 Element (org.w3c.dom.Element)16 ArrayList (java.util.ArrayList)15 NodeList (org.w3c.dom.NodeList)15 FileInputStream (java.io.FileInputStream)14 Node (org.w3c.dom.Node)12 File (java.io.File)11 StringReader (java.io.StringReader)11 URL (java.net.URL)9