1   /*
2    * Copyright 2005 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.springframework.oxm.xmlbeans;
17  
18  import junit.framework.TestCase;
19  import org.apache.xmlbeans.XMLStreamValidationException;
20  import org.apache.xmlbeans.XmlError;
21  import org.apache.xmlbeans.XmlException;
22  import org.xml.sax.SAXException;
23  
24  public class XmlBeansUtilsTest extends TestCase {
25  
26      public void testConvertXMLStreamValidationException() {
27          assertTrue("Invalid exception conversion", XmlBeansUtils.convertXmlBeansException(
28                  new XMLStreamValidationException(XmlError.forMessage("")),
29                  true) instanceof XmlBeansValidationFailureException);
30  
31      }
32  
33      public void testConvertXmlException() {
34          assertTrue("Invalid exception conversion", XmlBeansUtils
35                  .convertXmlBeansException(new XmlException(""), true) instanceof XmlBeansMarshallingFailureException);
36          assertTrue("Invalid exception conversion", XmlBeansUtils.convertXmlBeansException(new XmlException(""),
37                  false) instanceof XmlBeansUnmarshallingFailureException);
38      }
39  
40      public void testConvertSAXException() {
41          assertTrue("Invalid exception conversion", XmlBeansUtils
42                  .convertXmlBeansException(new SAXException(""), true) instanceof XmlBeansMarshallingFailureException);
43          assertTrue("Invalid exception conversion", XmlBeansUtils.convertXmlBeansException(new SAXException(""),
44                  false) instanceof XmlBeansUnmarshallingFailureException);
45      }
46  
47      public void testFallbackException() {
48          assertTrue("Invalid exception conversion",
49                  XmlBeansUtils.convertXmlBeansException(new Exception(""), false) instanceof XmlBeansSystemException);
50  
51      }
52  
53  }