Mark Castor tests as deprecated

Issue: SPR-16219

(cherry picked from commit 85984f3)
This commit is contained in:
Juergen Hoeller 2018-02-25 14:29:28 +01:00
parent d5f358c33c
commit f9754f92f4
3 changed files with 25 additions and 69 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 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.
@ -20,32 +20,25 @@ import java.io.StringWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamResult;
import org.custommonkey.xmlunit.NamespaceContext;
import org.custommonkey.xmlunit.SimpleNamespaceContext;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
import org.custommonkey.xmlunit.XpathEngine;
import org.junit.Test;
import org.mockito.InOrder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.springframework.core.io.ClassPathResource;
import org.springframework.oxm.AbstractMarshallerTests;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import static org.custommonkey.xmlunit.XMLAssert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**
@ -55,6 +48,7 @@ import static org.mockito.Mockito.*;
* @author Jakub Narloch
* @author Sam Brannen
*/
@Deprecated
public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshaller> {
/**
@ -163,14 +157,14 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
public void suppressNamespacesTrue() throws Exception {
marshaller.setSuppressNamespaces(true);
String result = marshalFlights();
assertXMLEqual("Marshaller wrote invalid result", SUPPRESSED_NAMESPACE_EXPECTED_STRING, result);
XMLAssert.assertXMLEqual("Marshaller wrote invalid result", SUPPRESSED_NAMESPACE_EXPECTED_STRING, result);
}
@Test
public void suppressNamespacesFalse() throws Exception {
marshaller.setSuppressNamespaces(false);
String result = marshalFlights();
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
XMLAssert.assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
}
@Test
@ -179,7 +173,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
marshaller.setSuppressXsiType(true);
marshaller.setRootElement("objects");
String result = marshal(Arrays.asList(castorObject));
assertXMLEqual("Marshaller wrote invalid result", SUPPRESSED_XSI_EXPECTED_STRING, result);
XMLAssert.assertXMLEqual("Marshaller wrote invalid result", SUPPRESSED_XSI_EXPECTED_STRING, result);
}
@Test
@ -188,14 +182,14 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
marshaller.setSuppressXsiType(false);
marshaller.setRootElement("objects");
String result = marshal(Arrays.asList(castorObject));
assertXMLEqual("Marshaller wrote invalid result", XSI_EXPECTED_STRING, result);
XMLAssert.assertXMLEqual("Marshaller wrote invalid result", XSI_EXPECTED_STRING, result);
}
@Test
public void marshalAsDocumentTrue() throws Exception {
marshaller.setMarshalAsDocument(true);
String result = marshalFlights();
assertXMLEqual("Marshaller wrote invalid result", DOCUMENT_EXPECTED_STRING, result);
XMLAssert.assertXMLEqual("Marshaller wrote invalid result", DOCUMENT_EXPECTED_STRING, result);
assertTrue("Result doesn't contain xml declaration.",
result.contains("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
}
@ -204,7 +198,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
public void marshalAsDocumentFalse() throws Exception {
marshaller.setMarshalAsDocument(true);
String result = marshalFlights();
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
XMLAssert.assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
assertFalse("Result contains xml declaration.", result.matches("<\\?\\s*xml"));
}
@ -212,7 +206,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
public void rootElement() throws Exception {
marshaller.setRootElement("canceledFlights");
String result = marshalFlights();
assertXMLEqual("Marshaller wrote invalid result", ROOT_ELEMENT_EXPECTED_STRING, result);
XMLAssert.assertXMLEqual("Marshaller wrote invalid result", ROOT_ELEMENT_EXPECTED_STRING, result);
}
@Test
@ -222,7 +216,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
String result = marshalFlights();
assertXpathEvaluatesTo("The xsi:noNamespaceSchemaLocation hasn't been written or has invalid value.",
noNamespaceSchemaLocation, "/tns:flights/@xsi:noNamespaceSchemaLocation", result);
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
XMLAssert.assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
}
@Test
@ -232,7 +226,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
String result = marshalFlights();
assertXpathEvaluatesTo("The xsi:noNamespaceSchemaLocation hasn't been written or has invalid value.",
schemaLocation, "/tns:flights/@xsi:schemaLocation", result);
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
XMLAssert.assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result);
}
@Test
@ -242,7 +236,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
marshaller.setUseXSITypeAtRoot(true);
marshaller.setRootElement("objects");
String result = marshal(Arrays.asList(castorObject));
assertXMLEqual("Marshaller wrote invalid result", ROOT_WITH_XSI_EXPECTED_STRING, result);
XMLAssert.assertXMLEqual("Marshaller wrote invalid result", ROOT_WITH_XSI_EXPECTED_STRING, result);
}
@Test
@ -252,7 +246,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests<CastorMarshal
marshaller.setUseXSITypeAtRoot(false);
marshaller.setRootElement("objects");
String result = marshal(Arrays.asList(castorObject));
assertXMLEqual("Marshaller wrote invalid result", ROOT_WITHOUT_XSI_EXPECTED_STRING, result);
XMLAssert.assertXMLEqual("Marshaller wrote invalid result", ROOT_WITHOUT_XSI_EXPECTED_STRING, result);
}

View File

@ -25,14 +25,13 @@ import javax.xml.transform.stream.StreamSource;
import org.junit.Ignore;
import org.junit.Test;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.oxm.AbstractUnmarshallerTests;
import org.springframework.oxm.MarshallingException;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
@ -41,6 +40,7 @@ import static org.junit.Assert.*;
* @author Jakub Narloch
* @author Sam Brannen
*/
@Deprecated
public class CastorUnmarshallerTests extends AbstractUnmarshallerTests<CastorMarshaller> {
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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,13 +16,10 @@
package org.springframework.oxm.config;
import org.apache.xmlbeans.XmlOptions;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.oxm.castor.CastorMarshaller;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import static org.junit.Assert.*;
@ -34,7 +31,6 @@ import static org.junit.Assert.*;
* @author Jakub Narloch
* @author Sam Brannen
*/
@SuppressWarnings("deprecation")
public class OxmNamespaceHandlerTests {
private final ApplicationContext applicationContext =
@ -42,49 +38,15 @@ public class OxmNamespaceHandlerTests {
@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 {
public void jaxb2ContextPathMarshaller() {
Jaxb2Marshaller jaxb2Marshaller = applicationContext.getBean("jaxb2ContextPathMarshaller", Jaxb2Marshaller.class);
assertNotNull(jaxb2Marshaller);
}
@Test
public void jaxb2ClassesToBeBoundMarshaller() throws Exception {
public void jaxb2ClassesToBeBoundMarshaller() {
Jaxb2Marshaller jaxb2Marshaller = applicationContext.getBean("jaxb2ClassesMarshaller", Jaxb2Marshaller.class);
assertNotNull(jaxb2Marshaller);
}
@Test
public void castorEncodingMarshaller() throws Exception {
CastorMarshaller castorMarshaller = applicationContext.getBean("castorEncodingMarshaller", CastorMarshaller.class);
assertNotNull(castorMarshaller);
}
@Test
public void castorTargetClassMarshaller() throws Exception {
CastorMarshaller castorMarshaller = applicationContext.getBean("castorTargetClassMarshaller", CastorMarshaller.class);
assertNotNull(castorMarshaller);
}
@Test
public void castorTargetPackageMarshaller() throws Exception {
CastorMarshaller castorMarshaller = applicationContext.getBean("castorTargetPackageMarshaller", CastorMarshaller.class);
assertNotNull(castorMarshaller);
}
@Test
public void castorMappingLocationMarshaller() throws Exception {
CastorMarshaller castorMarshaller = applicationContext.getBean("castorMappingLocationMarshaller", CastorMarshaller.class);
assertNotNull(castorMarshaller);
}
}