|
|
@ -125,6 +125,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
return flights; |
|
|
|
return flights; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void marshalSaxResult() throws Exception { |
|
|
|
public void marshalSaxResult() throws Exception { |
|
|
|
ContentHandler contentHandler = mock(ContentHandler.class); |
|
|
|
ContentHandler contentHandler = mock(ContentHandler.class); |
|
|
@ -133,12 +134,12 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
InOrder ordered = inOrder(contentHandler); |
|
|
|
InOrder ordered = inOrder(contentHandler); |
|
|
|
ordered.verify(contentHandler).startDocument(); |
|
|
|
ordered.verify(contentHandler).startDocument(); |
|
|
|
ordered.verify(contentHandler).startPrefixMapping("tns", "http://samples.springframework.org/flight"); |
|
|
|
ordered.verify(contentHandler).startPrefixMapping("tns", "http://samples.springframework.org/flight"); |
|
|
|
ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("flights"), |
|
|
|
ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), |
|
|
|
eq("tns:flights"), isA(Attributes.class)); |
|
|
|
eq("flights"), eq("tns:flights"), isA(Attributes.class)); |
|
|
|
ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("flight"), |
|
|
|
ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), |
|
|
|
eq("tns:flight"), isA(Attributes.class)); |
|
|
|
eq("flight"), eq("tns:flight"), isA(Attributes.class)); |
|
|
|
ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), eq("number"), |
|
|
|
ordered.verify(contentHandler).startElement(eq("http://samples.springframework.org/flight"), |
|
|
|
eq("tns:number"), isA(Attributes.class)); |
|
|
|
eq("number"), eq("tns:number"), isA(Attributes.class)); |
|
|
|
ordered.verify(contentHandler).characters(eq(new char[]{'4', '2'}), eq(0), eq(2)); |
|
|
|
ordered.verify(contentHandler).characters(eq(new char[]{'4', '2'}), eq(0), eq(2)); |
|
|
|
ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "number", "tns:number"); |
|
|
|
ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "number", "tns:number"); |
|
|
|
ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "flight", "tns:flight"); |
|
|
|
ordered.verify(contentHandler).endElement("http://samples.springframework.org/flight", "flight", "tns:flight"); |
|
|
@ -170,7 +171,6 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSuppressXsiTypeTrue() throws Exception { |
|
|
|
public void testSuppressXsiTypeTrue() throws Exception { |
|
|
|
CastorObject castorObject = createCastorObject(); |
|
|
|
CastorObject castorObject = createCastorObject(); |
|
|
|
|
|
|
|
|
|
|
|
getCastorMarshaller().setSuppressXsiType(true); |
|
|
|
getCastorMarshaller().setSuppressXsiType(true); |
|
|
|
getCastorMarshaller().setRootElement("objects"); |
|
|
|
getCastorMarshaller().setRootElement("objects"); |
|
|
|
String result = marshal(Arrays.asList(castorObject)); |
|
|
|
String result = marshal(Arrays.asList(castorObject)); |
|
|
@ -180,7 +180,6 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSuppressXsiTypeFalse() throws Exception { |
|
|
|
public void testSuppressXsiTypeFalse() throws Exception { |
|
|
|
CastorObject castorObject = createCastorObject(); |
|
|
|
CastorObject castorObject = createCastorObject(); |
|
|
|
|
|
|
|
|
|
|
|
getCastorMarshaller().setSuppressXsiType(false); |
|
|
|
getCastorMarshaller().setSuppressXsiType(false); |
|
|
|
getCastorMarshaller().setRootElement("objects"); |
|
|
|
getCastorMarshaller().setRootElement("objects"); |
|
|
|
String result = marshal(Arrays.asList(castorObject)); |
|
|
|
String result = marshal(Arrays.asList(castorObject)); |
|
|
@ -189,7 +188,6 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMarshalAsDocumentTrue() throws Exception { |
|
|
|
public void testMarshalAsDocumentTrue() throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
getCastorMarshaller().setMarshalAsDocument(true); |
|
|
|
getCastorMarshaller().setMarshalAsDocument(true); |
|
|
|
String result = marshalFlights(); |
|
|
|
String result = marshalFlights(); |
|
|
|
assertXMLEqual("Marshaller wrote invalid result", DOCUMENT_EXPECTED_STRING, result); |
|
|
|
assertXMLEqual("Marshaller wrote invalid result", DOCUMENT_EXPECTED_STRING, result); |
|
|
@ -199,7 +197,6 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMarshalAsDocumentFalse() throws Exception { |
|
|
|
public void testMarshalAsDocumentFalse() throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
getCastorMarshaller().setMarshalAsDocument(true); |
|
|
|
getCastorMarshaller().setMarshalAsDocument(true); |
|
|
|
String result = marshalFlights(); |
|
|
|
String result = marshalFlights(); |
|
|
|
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result); |
|
|
|
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result); |
|
|
@ -208,7 +205,6 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testRootElement() throws Exception { |
|
|
|
public void testRootElement() throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
getCastorMarshaller().setRootElement("canceledFlights"); |
|
|
|
getCastorMarshaller().setRootElement("canceledFlights"); |
|
|
|
String result = marshalFlights(); |
|
|
|
String result = marshalFlights(); |
|
|
|
assertXMLEqual("Marshaller wrote invalid result", ROOT_ELEMENT_EXPECTED_STRING, result); |
|
|
|
assertXMLEqual("Marshaller wrote invalid result", ROOT_ELEMENT_EXPECTED_STRING, result); |
|
|
@ -217,10 +213,8 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testNoNamespaceSchemaLocation() throws Exception { |
|
|
|
public void testNoNamespaceSchemaLocation() throws Exception { |
|
|
|
String noNamespaceSchemaLocation = "flights.xsd"; |
|
|
|
String noNamespaceSchemaLocation = "flights.xsd"; |
|
|
|
|
|
|
|
|
|
|
|
getCastorMarshaller().setNoNamespaceSchemaLocation(noNamespaceSchemaLocation); |
|
|
|
getCastorMarshaller().setNoNamespaceSchemaLocation(noNamespaceSchemaLocation); |
|
|
|
String result = marshalFlights(); |
|
|
|
String result = marshalFlights(); |
|
|
|
|
|
|
|
|
|
|
|
assertXpathEvaluatesTo("The xsi:noNamespaceSchemaLocation hasn't been written or has invalid value.", |
|
|
|
assertXpathEvaluatesTo("The xsi:noNamespaceSchemaLocation hasn't been written or has invalid value.", |
|
|
|
noNamespaceSchemaLocation, "/tns:flights/@xsi:noNamespaceSchemaLocation", result); |
|
|
|
noNamespaceSchemaLocation, "/tns:flights/@xsi:noNamespaceSchemaLocation", result); |
|
|
|
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result); |
|
|
|
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result); |
|
|
@ -229,10 +223,8 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSchemaLocation() throws Exception { |
|
|
|
public void testSchemaLocation() throws Exception { |
|
|
|
String schemaLocation = "flights.xsd"; |
|
|
|
String schemaLocation = "flights.xsd"; |
|
|
|
|
|
|
|
|
|
|
|
getCastorMarshaller().setSchemaLocation(schemaLocation); |
|
|
|
getCastorMarshaller().setSchemaLocation(schemaLocation); |
|
|
|
String result = marshalFlights(); |
|
|
|
String result = marshalFlights(); |
|
|
|
|
|
|
|
|
|
|
|
assertXpathEvaluatesTo("The xsi:noNamespaceSchemaLocation hasn't been written or has invalid value.", |
|
|
|
assertXpathEvaluatesTo("The xsi:noNamespaceSchemaLocation hasn't been written or has invalid value.", |
|
|
|
schemaLocation, "/tns:flights/@xsi:schemaLocation", result); |
|
|
|
schemaLocation, "/tns:flights/@xsi:schemaLocation", result); |
|
|
|
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result); |
|
|
|
assertXMLEqual("Marshaller wrote invalid result", EXPECTED_STRING, result); |
|
|
@ -241,7 +233,6 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testUseXsiTypeAsRootTrue() throws Exception { |
|
|
|
public void testUseXsiTypeAsRootTrue() throws Exception { |
|
|
|
CastorObject castorObject = createCastorObject(); |
|
|
|
CastorObject castorObject = createCastorObject(); |
|
|
|
|
|
|
|
|
|
|
|
getCastorMarshaller().setSuppressXsiType(false); |
|
|
|
getCastorMarshaller().setSuppressXsiType(false); |
|
|
|
getCastorMarshaller().setUseXSITypeAtRoot(true); |
|
|
|
getCastorMarshaller().setUseXSITypeAtRoot(true); |
|
|
|
getCastorMarshaller().setRootElement("objects"); |
|
|
|
getCastorMarshaller().setRootElement("objects"); |
|
|
@ -252,7 +243,6 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testUseXsiTypeAsRootFalse() throws Exception { |
|
|
|
public void testUseXsiTypeAsRootFalse() throws Exception { |
|
|
|
CastorObject castorObject = createCastorObject(); |
|
|
|
CastorObject castorObject = createCastorObject(); |
|
|
|
|
|
|
|
|
|
|
|
getCastorMarshaller().setSuppressXsiType(false); |
|
|
|
getCastorMarshaller().setSuppressXsiType(false); |
|
|
|
getCastorMarshaller().setUseXSITypeAtRoot(false); |
|
|
|
getCastorMarshaller().setUseXSITypeAtRoot(false); |
|
|
|
getCastorMarshaller().setRootElement("objects"); |
|
|
|
getCastorMarshaller().setRootElement("objects"); |
|
|
@ -260,16 +250,15 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
assertXMLEqual("Marshaller wrote invalid result", ROOT_WITHOUT_XSI_EXPECTED_STRING, result); |
|
|
|
assertXMLEqual("Marshaller wrote invalid result", ROOT_WITHOUT_XSI_EXPECTED_STRING, result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private CastorMarshaller getCastorMarshaller() { |
|
|
|
private CastorMarshaller getCastorMarshaller() { |
|
|
|
return (CastorMarshaller) marshaller; |
|
|
|
return (CastorMarshaller) marshaller; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String marshal(Object object) throws Exception { |
|
|
|
private String marshal(Object object) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
StringWriter writer = new StringWriter(); |
|
|
|
StringWriter writer = new StringWriter(); |
|
|
|
StreamResult result = new StreamResult(writer); |
|
|
|
StreamResult result = new StreamResult(writer); |
|
|
|
getCastorMarshaller().marshal(object, result); |
|
|
|
getCastorMarshaller().marshal(object, result); |
|
|
|
|
|
|
|
|
|
|
|
return writer.toString(); |
|
|
|
return writer.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -278,7 +267,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Asserts the values of xpath expression evaluation is exactly the same as expected value. |
|
|
|
* Assert the values of xpath expression evaluation is exactly the same as expected value. |
|
|
|
* <p>The xpath may contain the xml namespace prefixes, since namespaces from flight example |
|
|
|
* <p>The xpath may contain the xml namespace prefixes, since namespaces from flight example |
|
|
|
* are being registered. |
|
|
|
* are being registered. |
|
|
|
* @param msg the error message that will be used in case of test failure |
|
|
|
* @param msg the error message that will be used in case of test failure |
|
|
@ -302,7 +291,7 @@ public class CastorMarshallerTests extends AbstractMarshallerTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a instance of {@link CastorObject} for testing. |
|
|
|
* Create an instance of {@link CastorObject} for testing. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private CastorObject createCastorObject() { |
|
|
|
private CastorObject createCastorObject() { |
|
|
|
CastorObject castorObject = new CastorObject(); |
|
|
|
CastorObject castorObject = new CastorObject(); |
|
|
|