1818import static org .junit .Assert .assertEquals ;
1919import java .lang .reflect .Type ;
2020import java .nio .charset .Charset ;
21+ import java .nio .charset .StandardCharsets ;
2122import java .util .Collection ;
2223import java .util .Collections ;
2324import java .util .Map ;
@@ -45,7 +46,7 @@ public class SOAPCodecTest {
4546 public final ExpectedException thrown = ExpectedException .none ();
4647
4748 @ Test
48- public void encodesSoap () throws Exception {
49+ public void encodesSoap () {
4950 Encoder encoder = new SOAPEncoder .Builder ()
5051 .withJAXBContextFactory (new JAXBContextFactory .Builder ().build ())
5152 .build ();
@@ -89,14 +90,14 @@ class ParameterizedHolder {
8990
9091
9192 @ Test
92- public void encodesSoapWithCustomJAXBMarshallerEncoding () throws Exception {
93+ public void encodesSoapWithCustomJAXBMarshallerEncoding () {
9394 JAXBContextFactory jaxbContextFactory =
9495 new JAXBContextFactory .Builder ().withMarshallerJAXBEncoding ("UTF-16" ).build ();
9596
9697 Encoder encoder = new SOAPEncoder .Builder ()
9798 // .withWriteXmlDeclaration(true)
9899 .withJAXBContextFactory (jaxbContextFactory )
99- .withCharsetEncoding (Charset . forName ( "UTF-16" ) )
100+ .withCharsetEncoding (StandardCharsets . UTF_16 )
100101 .build ();
101102
102103 GetPrice mock = new GetPrice ();
@@ -115,13 +116,13 @@ public void encodesSoapWithCustomJAXBMarshallerEncoding() throws Exception {
115116 "</GetPrice>" +
116117 "</SOAP-ENV:Body>" +
117118 "</SOAP-ENV:Envelope>" ;
118- byte [] utf16Bytes = soapEnvelop .getBytes ("UTF-16LE" );
119+ byte [] utf16Bytes = soapEnvelop .getBytes (StandardCharsets . UTF_16LE );
119120 assertThat (template ).hasBody (utf16Bytes );
120121 }
121122
122123
123124 @ Test
124- public void encodesSoapWithCustomJAXBSchemaLocation () throws Exception {
125+ public void encodesSoapWithCustomJAXBSchemaLocation () {
125126 JAXBContextFactory jaxbContextFactory =
126127 new JAXBContextFactory .Builder ()
127128 .withMarshallerSchemaLocation ("http://apihost http://apihost/schema.xsd" )
@@ -149,7 +150,7 @@ public void encodesSoapWithCustomJAXBSchemaLocation() throws Exception {
149150
150151
151152 @ Test
152- public void encodesSoapWithCustomJAXBNoSchemaLocation () throws Exception {
153+ public void encodesSoapWithCustomJAXBNoSchemaLocation () {
153154 JAXBContextFactory jaxbContextFactory =
154155 new JAXBContextFactory .Builder ()
155156 .withMarshallerNoNamespaceSchemaLocation ("http://apihost/schema.xsd" )
@@ -176,7 +177,7 @@ public void encodesSoapWithCustomJAXBNoSchemaLocation() throws Exception {
176177 }
177178
178179 @ Test
179- public void encodesSoapWithCustomJAXBFormattedOuput () throws Exception {
180+ public void encodesSoapWithCustomJAXBFormattedOuput () {
180181 Encoder encoder = new SOAPEncoder .Builder ().withFormattedOutput (true )
181182 .withJAXBContextFactory (new JAXBContextFactory .Builder ()
182183 .build ())
@@ -232,6 +233,40 @@ public void decodesSoap() throws Exception {
232233 assertEquals (mock , decoder .decode (response , GetPrice .class ));
233234 }
234235
236+ @ Test
237+ public void decodesSoapWithSchemaOnEnvelope () throws Exception {
238+ GetPrice mock = new GetPrice ();
239+ mock .item = new Item ();
240+ mock .item .value = "Apples" ;
241+
242+ String mockSoapEnvelop = "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>"
243+ + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\" http://schemas.xmlsoap.org/soap/envelope/\" "
244+ + "xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\" http://apihost/schema.xsd\" "
245+ + "xmlns:xsd=\" http://www.w3.org/2001/XMLSchema\" >"
246+ + "<SOAP-ENV:Header/>"
247+ + "<SOAP-ENV:Body>"
248+ + "<GetPrice>"
249+ + "<Item xsi:type=\" xsd:string\" >Apples</Item>"
250+ + "</GetPrice>"
251+ + "</SOAP-ENV:Body>"
252+ + "</SOAP-ENV:Envelope>" ;
253+
254+ Response response = Response .builder ()
255+ .status (200 )
256+ .reason ("OK" )
257+ .request (Request .create (HttpMethod .GET , "/api" , Collections .emptyMap (), null , Util .UTF_8 ))
258+ .headers (Collections .emptyMap ())
259+ .body (mockSoapEnvelop , UTF_8 )
260+ .build ();
261+
262+ SOAPDecoder decoder = new SOAPDecoder .Builder ()
263+ .withJAXBContextFactory (new JAXBContextFactory .Builder ().build ())
264+ .useFirstChild ()
265+ .build ();
266+
267+ assertEquals (mock , decoder .decode (response , GetPrice .class ));
268+ }
269+
235270 @ Test
236271 public void decodesSoap1_2Protocol () throws Exception {
237272 GetPrice mock = new GetPrice ();
@@ -281,7 +316,7 @@ class ParameterizedHolder {
281316 .status (200 )
282317 .reason ("OK" )
283318 .request (Request .create (HttpMethod .GET , "/api" , Collections .emptyMap (), null , Util .UTF_8 ))
284- .headers (Collections .< String , Collection < String >> emptyMap ())
319+ .headers (Collections .emptyMap ())
285320 .body ("<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>"
286321 + "<Envelope xmlns=\" http://schemas.xmlsoap.org/soap/envelope/\" >"
287322 + "<Header/>"
@@ -326,7 +361,7 @@ public void decodeAnnotatedParameterizedTypes() throws Exception {
326361 .status (200 )
327362 .reason ("OK" )
328363 .request (Request .create (HttpMethod .GET , "/api" , Collections .emptyMap (), null , Util .UTF_8 ))
329- .headers (Collections .< String , Collection < String >> emptyMap ())
364+ .headers (Collections .emptyMap ())
330365 .body (template .body ())
331366 .build ();
332367
@@ -343,7 +378,7 @@ public void notFoundDecodesToNull() throws Exception {
343378 .status (404 )
344379 .reason ("NOT FOUND" )
345380 .request (Request .create (HttpMethod .GET , "/api" , Collections .emptyMap (), null , Util .UTF_8 ))
346- .headers (Collections .< String , Collection < String >> emptyMap ())
381+ .headers (Collections .emptyMap ())
347382 .build ();
348383 assertThat ((byte []) new JAXBDecoder (new JAXBContextFactory .Builder ().build ())
349384 .decode (response , byte [].class )).isNull ();
0 commit comments