@ -1,5 +1,5 @@
/ *
/ *
* Copyright 2002 - 2009 the original author or authors .
* Copyright 2002 - 2012 the original author or authors .
*
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -16,13 +16,17 @@
package org.springframework.oxm.jibx ;
package org.springframework.oxm.jibx ;
import static org.junit.Assert.assertEquals ;
import java.io.ByteArrayInputStream ;
import static org.junit.Assert.assertNotNull ;
import org.junit.Ignor e;
import javax.xml.transform.stream.StreamSourc e;
import org.junit.Ignore ;
import org.junit.Test ;
import org.springframework.oxm.AbstractUnmarshallerTests ;
import org.springframework.oxm.AbstractUnmarshallerTests ;
import org.springframework.oxm.Unmarshaller ;
import org.springframework.oxm.Unmarshaller ;
import static org.junit.Assert.* ;
/ * *
/ * *
* @author Arjen Poutsma
* @author Arjen Poutsma
*
*
@ -31,6 +35,10 @@ import org.springframework.oxm.Unmarshaller;
* /
* /
public class JibxUnmarshallerTests extends AbstractUnmarshallerTests {
public class JibxUnmarshallerTests extends AbstractUnmarshallerTests {
protected static final String INPUT_STRING_WITH_SPECIAL_CHARACTERS =
"<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" +
"<tns:flight><tns:airline>Air Liberté</tns:airline><tns:number>42</tns:number></tns:flight></tns:flights>" ;
@Override
@Override
protected Unmarshaller createUnmarshaller ( ) throws Exception {
protected Unmarshaller createUnmarshaller ( ) throws Exception {
JibxMarshaller unmarshaller = new JibxMarshaller ( ) ;
JibxMarshaller unmarshaller = new JibxMarshaller ( ) ;
@ -60,4 +68,17 @@ public class JibxUnmarshallerTests extends AbstractUnmarshallerTests {
// JiBX does not support reading XML fragments, hence the override here
// JiBX does not support reading XML fragments, hence the override here
}
}
@Test
public void unmarshalStreamSourceInputStreamUsingNonDefaultEncoding ( ) throws Exception {
String encoding = "ISO-8859-1" ;
( ( JibxMarshaller ) unmarshaller ) . setEncoding ( encoding ) ;
StreamSource source = new StreamSource ( new ByteArrayInputStream ( INPUT_STRING_WITH_SPECIAL_CHARACTERS . getBytes ( encoding ) ) ) ;
Object flights = unmarshaller . unmarshal ( source ) ;
testFlights ( flights ) ;
FlightType flight = ( ( Flights ) flights ) . getFlight ( 0 ) ;
assertEquals ( "Airline is invalid" , "Air Liberté" , flight . getAirline ( ) ) ;
}
}
}