Remove XMLBeans support

Issue: SPR-13796
This commit is contained in:
Juergen Hoeller
2016-07-04 23:29:29 +02:00
parent 770f0c0661
commit d0aa607200
11 changed files with 8 additions and 879 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@@ -16,8 +16,6 @@
package org.springframework.oxm.config;
import org.apache.xmlbeans.XmlOptions;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
@@ -37,18 +35,9 @@ import static org.junit.Assert.*;
@SuppressWarnings("deprecation")
public class OxmNamespaceHandlerTests {
private final ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"oxmNamespaceHandlerTest.xml", getClass());
private final ApplicationContext applicationContext =
new ClassPathXmlApplicationContext("oxmNamespaceHandlerTest.xml", getClass());
@Test
public void xmlBeansMarshaller() throws Exception {
org.springframework.oxm.xmlbeans.XmlBeansMarshaller marshaller = applicationContext.getBean(
org.springframework.oxm.xmlbeans.XmlBeansMarshaller.class);
XmlOptions options = marshaller.getXmlOptions();
assertNotNull("Options not set", options);
assertTrue("option not set", options.hasOption("SAVE_PRETTY_PRINT"));
assertEquals("option not set", "true", options.get("SAVE_PRETTY_PRINT"));
}
@Test
public void jaxb2ContextPathMarshaller() throws Exception {
@@ -85,4 +74,5 @@ public class OxmNamespaceHandlerTests {
CastorMarshaller castorMarshaller = applicationContext.getBean("castorMappingLocationMarshaller", CastorMarshaller.class);
assertNotNull(castorMarshaller);
}
}
}

View File

@@ -1,68 +0,0 @@
/*
* Copyright 2002-2015 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 java.io.ByteArrayOutputStream;
import javax.xml.transform.stream.StreamResult;
import org.apache.xmlbeans.XmlObject;
import org.junit.Test;
import org.springframework.oxm.AbstractMarshallerTests;
import org.springframework.samples.flight.FlightType;
import org.springframework.samples.flight.FlightsDocument;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma
* @author Sam Brannen
*/
@SuppressWarnings("deprecation")
public class XmlBeansMarshallerTests extends
AbstractMarshallerTests<org.springframework.oxm.xmlbeans.XmlBeansMarshaller> {
@Override
protected XmlBeansMarshaller createMarshaller() throws Exception {
return new XmlBeansMarshaller();
}
@Override
protected Object createFlights() {
FlightsDocument flightsDocument = FlightsDocument.Factory.newInstance();
FlightsDocument.Flights flights = flightsDocument.addNewFlights();
FlightType flightType = flights.addNewFlight();
flightType.setNumber(42L);
return flightsDocument;
}
@Test(expected = ClassCastException.class)
public void marshalNonXmlObject() throws Exception {
marshaller.marshal(new Object(), new StreamResult(new ByteArrayOutputStream()));
}
@Test
public void supports() throws Exception {
assertTrue("XmlBeansMarshaller does not support XmlObject", marshaller.supports(XmlObject.class));
assertFalse("XmlBeansMarshaller supports other objects", marshaller.supports(Object.class));
assertTrue("XmlBeansMarshaller does not support FlightsDocument", marshaller.supports(FlightsDocument.class));
assertTrue("XmlBeansMarshaller does not support Flights", marshaller.supports(FlightsDocument.Flights.class));
assertTrue("XmlBeansMarshaller does not support FlightType", marshaller.supports(FlightType.class));
}
}

View File

@@ -1,97 +0,0 @@
/*
* Copyright 2002-2015 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 java.io.StringReader;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import org.junit.Test;
import org.springframework.oxm.AbstractUnmarshallerTests;
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;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma
*/
@SuppressWarnings("deprecation")
public class XmlBeansUnmarshallerTests extends
AbstractUnmarshallerTests<org.springframework.oxm.xmlbeans.XmlBeansMarshaller> {
@Override
protected XmlBeansMarshaller createUnmarshaller() throws Exception {
return new XmlBeansMarshaller();
}
@Override
protected void testFlights(Object o) {
FlightsDocument flightsDocument = (FlightsDocument) o;
assertNotNull("FlightsDocument is null", flightsDocument);
FlightsDocument.Flights flights = flightsDocument.getFlights();
assertEquals("Invalid amount of flight elements", 1, flights.sizeOfFlightArray());
testFlight(flights.getFlightArray(0));
}
@Override
protected void testFlight(Object o) {
FlightType flight = null;
if (o instanceof FlightType) {
flight = (FlightType) o;
}
else if (o instanceof FlightDocument) {
FlightDocument flightDocument = (FlightDocument) o;
flight = flightDocument.getFlight();
}
assertNotNull("Flight is null", flight);
assertEquals("Number is invalid", 42L, flight.getNumber());
}
@Test
@Override
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
streamReader.nextTag(); // skip to flights
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flights"),
streamReader.getName());
streamReader.nextTag(); // skip to flight
assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flight"),
streamReader.getName());
Source source = StaxUtils.createStaxSource(streamReader);
Object flight = unmarshaller.unmarshal(source);
testFlight(flight);
}
@Test(expected = ValidationFailureException.class)
public void validate() throws Exception {
unmarshaller.setValidating(true);
String invalidInput = "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight><tns:number>abc</tns:number></tns:flight></tns:flights>";
unmarshaller.unmarshal(new StreamSource(new StringReader(invalidInput)));
}
}

View File

@@ -1,42 +0,0 @@
/*
* Copyright 2002-2012 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 java.util.Collections;
import org.apache.xmlbeans.XmlOptions;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma
*/
public class XmlOptionsFactoryBeanTests {
private XmlOptionsFactoryBean factoryBean = new XmlOptionsFactoryBean();
@Test
public void xmlOptionsFactoryBean() throws Exception {
factoryBean.setOptions(Collections.singletonMap(XmlOptions.SAVE_PRETTY_PRINT, Boolean.TRUE));
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));
}
}

View File

@@ -4,17 +4,6 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd">
<!-- XMLBeans -->
<oxm:xmlbeans-marshaller id="xmlBeansMarshaller" options="xmlBeansOptions"/>
<bean id="xmlBeansOptions" class="org.springframework.oxm.xmlbeans.XmlOptionsFactoryBean">
<property name="options">
<props>
<prop key="SAVE_PRETTY_PRINT">true</prop>
</props>
</property>
</bean>
<!-- JAXB2 -->
<oxm:jaxb2-marshaller id="jaxb2ContextPathMarshaller" contextPath="org.springframework.oxm.jaxb.test"/>