revised OXM package: no provider-specific exceptions anymore, etc
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.oxm;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -38,7 +39,10 @@ import org.w3c.dom.Text;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
public abstract class AbstractMarshallerTestCase {
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public abstract class AbstractMarshallerTests {
|
||||
|
||||
protected Marshaller marshaller;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.oxm;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -41,7 +42,10 @@ import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
public abstract class AbstractUnmarshallerTestCase {
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public abstract class AbstractUnmarshallerTests {
|
||||
|
||||
protected Unmarshaller unmarshaller;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.oxm.castor;
|
||||
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
@@ -24,10 +25,13 @@ import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.oxm.AbstractMarshallerTestCase;
|
||||
import org.springframework.oxm.AbstractMarshallerTests;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
|
||||
public class CastorMarshallerTest extends AbstractMarshallerTestCase {
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class CastorMarshallerTests extends AbstractMarshallerTests {
|
||||
|
||||
@Override
|
||||
protected Marshaller createMarshaller() throws Exception {
|
||||
@@ -77,5 +81,4 @@ public class CastorMarshallerTest extends AbstractMarshallerTestCase {
|
||||
assertTrue("CastorMarshaller does not support Flight", marshaller.supports(Flight.class));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.oxm.castor;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -24,10 +25,13 @@ import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.oxm.AbstractUnmarshallerTestCase;
|
||||
import org.springframework.oxm.AbstractUnmarshallerTests;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
|
||||
public class CastorUnmarshallerTest extends AbstractUnmarshallerTestCase {
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class CastorUnmarshallerTests extends AbstractUnmarshallerTests {
|
||||
|
||||
@Override
|
||||
protected void testFlights(Object o) {
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.oxm.castor;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.exolab.castor.xml.MarshalException;
|
||||
import org.exolab.castor.xml.ValidationException;
|
||||
import org.exolab.castor.xml.XMLException;
|
||||
|
||||
public class CastorUtilsTest extends TestCase {
|
||||
|
||||
public void testConvertMarshalException() {
|
||||
assertTrue("Invalid exception conversion", CastorUtils
|
||||
.convertXmlException(new MarshalException(""), true) instanceof CastorMarshallingFailureException);
|
||||
assertTrue("Invalid exception conversion", CastorUtils
|
||||
.convertXmlException(new MarshalException(""), false) instanceof CastorUnmarshallingFailureException);
|
||||
}
|
||||
|
||||
public void testConvertValidationException() {
|
||||
assertTrue("Invalid exception conversion", CastorUtils
|
||||
.convertXmlException(new ValidationException(""), false) instanceof CastorValidationFailureException);
|
||||
}
|
||||
|
||||
public void testConvertXMLException() {
|
||||
assertTrue("Invalid exception conversion",
|
||||
CastorUtils.convertXmlException(new XMLException(""), false) instanceof CastorSystemException);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,12 +21,13 @@ import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import javax.activation.DataHandler;
|
||||
import javax.activation.FileDataSource;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
@@ -34,13 +35,13 @@ import org.xml.sax.Locator;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.oxm.AbstractMarshallerTestCase;
|
||||
import org.springframework.oxm.AbstractMarshallerTests;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.oxm.XmlMappingException;
|
||||
import org.springframework.oxm.mime.MimeContainer;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
public class Jaxb2MarshallerTest extends AbstractMarshallerTestCase {
|
||||
public class Jaxb2MarshallerTests extends AbstractMarshallerTests {
|
||||
|
||||
private static final String CONTEXT_PATH = "org.springframework.oxm.jaxb";
|
||||
|
||||
@@ -106,7 +107,7 @@ public class Jaxb2MarshallerTest extends AbstractMarshallerTestCase {
|
||||
marshaller.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected = XmlMappingException.class)
|
||||
@Test(expected = JAXBException.class)
|
||||
public void testInvalidContextPath() throws Exception {
|
||||
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
|
||||
marshaller.setContextPath("ab");
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,12 +31,12 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.oxm.AbstractUnmarshallerTestCase;
|
||||
import org.springframework.oxm.AbstractUnmarshallerTests;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.mime.MimeContainer;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
public class Jaxb2UnmarshallerTest extends AbstractUnmarshallerTestCase {
|
||||
public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests {
|
||||
|
||||
private static final String INPUT_STRING = "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
|
||||
"<tns:flight><tns:number>42</tns:number></tns:flight></tns:flights>";
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,10 +25,10 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.oxm.AbstractMarshallerTestCase;
|
||||
import org.springframework.oxm.AbstractMarshallerTests;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
|
||||
public class JibxMarshallerTest extends AbstractMarshallerTestCase {
|
||||
public class JibxMarshallerTests extends AbstractMarshallerTests {
|
||||
|
||||
@Override
|
||||
protected Marshaller createMarshaller() throws Exception {
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,16 +13,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.oxm.jibx;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.Ignore;
|
||||
|
||||
import org.springframework.oxm.AbstractUnmarshallerTestCase;
|
||||
import org.springframework.oxm.AbstractUnmarshallerTests;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
|
||||
public class JibxUnmarshallerTest extends AbstractUnmarshallerTestCase {
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class JibxUnmarshallerTests extends AbstractUnmarshallerTests {
|
||||
|
||||
@Override
|
||||
protected Unmarshaller createUnmarshaller() throws Exception {
|
||||
@@ -52,4 +56,5 @@ public class JibxUnmarshallerTest extends AbstractUnmarshallerTestCase {
|
||||
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
|
||||
// JiBX does not support reading XML fragments, hence the override here
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.oxm.jibx;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.jibx.runtime.JiBXException;
|
||||
import org.jibx.runtime.ValidationException;
|
||||
|
||||
public class JibxUtilsTest extends TestCase {
|
||||
|
||||
public void testConvertMarshallingException() throws Exception {
|
||||
assertTrue("Invalid exception conversion",
|
||||
JibxUtils.convertJibxException(new JiBXException(""), true) instanceof JibxMarshallingFailureException);
|
||||
}
|
||||
|
||||
public void testConvertUnmarshallingException() throws Exception {
|
||||
assertTrue("Invalid exception conversion", JibxUtils
|
||||
.convertJibxException(new JiBXException(""), false) instanceof JibxUnmarshallingFailureException);
|
||||
}
|
||||
|
||||
public void testConvertValidationException() throws Exception {
|
||||
assertTrue("Invalid exception conversion", JibxUtils
|
||||
.convertJibxException(new ValidationException(""), true) instanceof JibxValidationFailureException);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.oxm.xmlbeans;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -23,12 +24,15 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.oxm.AbstractMarshallerTestCase;
|
||||
import org.springframework.oxm.AbstractMarshallerTests;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
import org.springframework.samples.flight.FlightType;
|
||||
import org.springframework.samples.flight.FlightsDocument;
|
||||
|
||||
public class XmlBeansMarshallerTest extends AbstractMarshallerTestCase {
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class XmlBeansMarshallerTests extends AbstractMarshallerTests {
|
||||
|
||||
@Override
|
||||
protected Marshaller createMarshaller() throws Exception {
|
||||
@@ -57,4 +61,5 @@ public class XmlBeansMarshallerTest extends AbstractMarshallerTestCase {
|
||||
assertTrue("XmlBeansMarshaller does not support Flights", marshaller.supports(FlightsDocument.Flights.class));
|
||||
assertTrue("XmlBeansMarshaller does not support FlightType", marshaller.supports(FlightType.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.oxm.xmlbeans;
|
||||
|
||||
import java.io.StringReader;
|
||||
@@ -22,18 +23,21 @@ import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.oxm.AbstractUnmarshallerTestCase;
|
||||
import org.springframework.oxm.AbstractUnmarshallerTests;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.ValidationFailureException;
|
||||
import org.springframework.samples.flight.FlightDocument;
|
||||
import org.springframework.samples.flight.FlightType;
|
||||
import org.springframework.samples.flight.FlightsDocument;
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
public class XmlBeansUnmarshallerTest extends AbstractUnmarshallerTestCase {
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class XmlBeansUnmarshallerTests extends AbstractUnmarshallerTests {
|
||||
|
||||
@Override
|
||||
protected Unmarshaller createUnmarshaller() throws Exception {
|
||||
@@ -78,7 +82,7 @@ public class XmlBeansUnmarshallerTest extends AbstractUnmarshallerTestCase {
|
||||
testFlight(flight);
|
||||
}
|
||||
|
||||
@Test(expected = XmlBeansValidationFailureException.class)
|
||||
@Test(expected = ValidationFailureException.class)
|
||||
public void testValidate() throws Exception {
|
||||
((XmlBeansMarshaller) unmarshaller).setValidating(true);
|
||||
String invalidInput = "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.oxm.xmlbeans;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.xmlbeans.XMLStreamValidationException;
|
||||
import org.apache.xmlbeans.XmlError;
|
||||
import org.apache.xmlbeans.XmlException;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class XmlBeansUtilsTest extends TestCase {
|
||||
|
||||
public void testConvertXMLStreamValidationException() {
|
||||
assertTrue("Invalid exception conversion", XmlBeansUtils.convertXmlBeansException(
|
||||
new XMLStreamValidationException(XmlError.forMessage("")),
|
||||
true) instanceof XmlBeansValidationFailureException);
|
||||
|
||||
}
|
||||
|
||||
public void testConvertXmlException() {
|
||||
assertTrue("Invalid exception conversion", XmlBeansUtils
|
||||
.convertXmlBeansException(new XmlException(""), true) instanceof XmlBeansMarshallingFailureException);
|
||||
assertTrue("Invalid exception conversion", XmlBeansUtils.convertXmlBeansException(new XmlException(""),
|
||||
false) instanceof XmlBeansUnmarshallingFailureException);
|
||||
}
|
||||
|
||||
public void testConvertSAXException() {
|
||||
assertTrue("Invalid exception conversion", XmlBeansUtils
|
||||
.convertXmlBeansException(new SAXException(""), true) instanceof XmlBeansMarshallingFailureException);
|
||||
assertTrue("Invalid exception conversion", XmlBeansUtils.convertXmlBeansException(new SAXException(""),
|
||||
false) instanceof XmlBeansUnmarshallingFailureException);
|
||||
}
|
||||
|
||||
public void testFallbackException() {
|
||||
assertTrue("Invalid exception conversion",
|
||||
XmlBeansUtils.convertXmlBeansException(new Exception(""), false) instanceof XmlBeansSystemException);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,23 +18,24 @@ package org.springframework.oxm.xmlbeans;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.xmlbeans.XmlOptions;
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
public class XmlOptionsFactoryBeanTest extends TestCase {
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class XmlOptionsFactoryBeanTests {
|
||||
|
||||
private XmlOptionsFactoryBean factoryBean;
|
||||
private XmlOptionsFactoryBean factoryBean = new XmlOptionsFactoryBean();
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
factoryBean = new XmlOptionsFactoryBean();
|
||||
}
|
||||
|
||||
public void testXmlOptionsFactoryBean() throws Exception {
|
||||
@Test
|
||||
public void xmlOptionsFactoryBean() throws Exception {
|
||||
factoryBean.setOptions(Collections.singletonMap(XmlOptions.SAVE_PRETTY_PRINT, Boolean.TRUE));
|
||||
factoryBean.afterPropertiesSet();
|
||||
XmlOptions xmlOptions = (XmlOptions) factoryBean.getObject();
|
||||
XmlOptions xmlOptions = factoryBean.getObject();
|
||||
assertNotNull("No XmlOptions returned", xmlOptions);
|
||||
assertTrue("Option not set", xmlOptions.hasOption(XmlOptions.SAVE_PRETTY_PRINT));
|
||||
assertFalse("Invalid option set", xmlOptions.hasOption(XmlOptions.LOAD_LINE_NUMBERS));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,8 +23,8 @@ import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.stream.XMLEventWriter;
|
||||
@@ -39,10 +39,11 @@ import javax.xml.transform.stream.StreamSource;
|
||||
import com.thoughtworks.xstream.converters.Converter;
|
||||
import com.thoughtworks.xstream.converters.extended.EncodedByteArrayConverter;
|
||||
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import org.easymock.MockControl;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
@@ -52,7 +53,10 @@ import org.xml.sax.ContentHandler;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
public class XStreamMarshallerTest {
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class XStreamMarshallerTests {
|
||||
|
||||
private static final String EXPECTED_STRING = "<flight><flightNumber>42</flightNumber></flight>";
|
||||
|
||||
@@ -63,8 +67,8 @@ public class XStreamMarshallerTest {
|
||||
@Before
|
||||
public void createMarshaller() throws Exception {
|
||||
marshaller = new XStreamMarshaller();
|
||||
Properties aliases = new Properties();
|
||||
aliases.setProperty("flight", AnnotatedFlight.class.getName());
|
||||
Map<String, Class> aliases = new HashMap<String, Class>();
|
||||
aliases.put("flight", AnnotatedFlight.class);
|
||||
marshaller.setAliases(aliases);
|
||||
flight = new AnnotatedFlight();
|
||||
flight.setFlightNumber(42L);
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,8 @@ package org.springframework.oxm.xstream;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.StringReader;
|
||||
import java.util.Properties;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
@@ -35,7 +36,10 @@ import org.xml.sax.InputSource;
|
||||
|
||||
import org.springframework.util.xml.StaxUtils;
|
||||
|
||||
public class XStreamUnmarshallerTest {
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
*/
|
||||
public class XStreamUnmarshallerTests {
|
||||
|
||||
protected static final String INPUT_STRING = "<flight><flightNumber>42</flightNumber></flight>";
|
||||
|
||||
@@ -44,8 +48,8 @@ public class XStreamUnmarshallerTest {
|
||||
@Before
|
||||
public void creteUnmarshaller() throws Exception {
|
||||
unmarshaller = new XStreamMarshaller();
|
||||
Properties aliases = new Properties();
|
||||
aliases.setProperty("flight", AnnotatedFlight.class.getName());
|
||||
Map<String, Class> aliases = new HashMap<String, Class>();
|
||||
aliases.put("flight", AnnotatedFlight.class);
|
||||
unmarshaller.setAliases(aliases);
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.oxm.xstream;
|
||||
|
||||
import com.thoughtworks.xstream.io.StreamException;
|
||||
import com.thoughtworks.xstream.mapper.CannotResolveClassException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class XStreamUtilsTest extends TestCase {
|
||||
|
||||
public void testConvertStreamException() {
|
||||
assertTrue("Invalid exception conversion", XStreamUtils.convertXStreamException(
|
||||
new StreamException(new Exception()), true) instanceof XStreamMarshallingFailureException);
|
||||
assertTrue("Invalid exception conversion", XStreamUtils.convertXStreamException(
|
||||
new StreamException(new Exception()), false) instanceof XStreamUnmarshallingFailureException);
|
||||
}
|
||||
|
||||
public void testConvertCannotResolveClassException() {
|
||||
assertTrue("Invalid exception conversion", XStreamUtils.convertXStreamException(
|
||||
new CannotResolveClassException(""), true) instanceof XStreamMarshallingFailureException);
|
||||
assertTrue("Invalid exception conversion", XStreamUtils.convertXStreamException(
|
||||
new CannotResolveClassException(""), false) instanceof XStreamUnmarshallingFailureException);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user