11package org .springframework .ws .soap .client .core ;
22
33import java .io .IOException ;
4-
54import javax .xml .soap .MessageFactory ;
65import javax .xml .soap .SOAPConstants ;
76import javax .xml .soap .SOAPException ;
87
9- import org .junit .Assert ;
108import org .junit .Before ;
119import org .junit .Test ;
10+
1211import org .springframework .ws .soap .SoapVersion ;
1312import org .springframework .ws .soap .saaj .SaajSoapMessage ;
1413import org .springframework .ws .soap .saaj .SaajSoapMessageFactory ;
1514import org .springframework .ws .soap .support .SoapUtils ;
1615import org .springframework .ws .transport .TransportConstants ;
1716
17+ import static org .hamcrest .CoreMatchers .*;
18+ import static org .hamcrest .core .Is .is ;
19+ import static org .junit .Assert .*;
20+
1821public class SaajSoapActionCallbackTest {
1922
2023 private SaajSoapMessageFactory saaj11Factory = new SaajSoapMessageFactory ();
2124
2225 private SaajSoapMessageFactory saaj12Factory = new SaajSoapMessageFactory ();
2326
2427 @ Before
25- public void init () throws SOAPException
26- {
28+ public void init () throws SOAPException {
2729 MessageFactory messageFactory11 = MessageFactory .newInstance (SOAPConstants .SOAP_1_1_PROTOCOL );
2830
2931 saaj11Factory .setSoapVersion (SoapVersion .SOAP_11 );
@@ -37,63 +39,66 @@ public void init() throws SOAPException
3739 }
3840
3941 @ Test
40- public void noSoapAction11 () throws IOException
41- {
42+ public void noSoapAction11ShouldProduceEmptySoapActionHeader () throws IOException {
4243 SaajSoapMessage message = saaj11Factory .createWebServiceMessage ();
4344 String [] soapActionHeaders = message .getSaajMessage ().getMimeHeaders ().getHeader (TransportConstants .HEADER_SOAP_ACTION );
44- Assert .assertEquals ("\" \" " , soapActionHeaders [0 ]);
45+
46+ assertThat (soapActionHeaders .length , is (1 ));
47+ assertThat (soapActionHeaders [0 ], is ("\" \" " ));
4548 }
4649
4750 @ Test
48- public void soapAction11 () throws IOException
49- {
51+ public void soapAction11ShouldProduceSoapActionHeader () throws IOException {
5052 SaajSoapMessage message = saaj11Factory .createWebServiceMessage ();
5153 SoapActionCallback callback = new SoapActionCallback ("testAction" );
5254 callback .doWithMessage (message );
5355 String [] soapActionHeaders = message .getSaajMessage ().getMimeHeaders ().getHeader (TransportConstants .HEADER_SOAP_ACTION );
54- Assert .assertEquals ("\" testAction\" " , soapActionHeaders [0 ]);
56+
57+ assertThat (soapActionHeaders .length , is (1 ));
58+ assertThat (soapActionHeaders [0 ], is ("\" testAction\" " ));
5559 }
5660
5761 @ Test
58- public void emptySoapAction11 () throws IOException
59- {
62+ public void emptySoapAction11 () throws IOException {
6063 SaajSoapMessage message = saaj11Factory .createWebServiceMessage ();
6164 SoapActionCallback callback = new SoapActionCallback (null );
6265 callback .doWithMessage (message );
6366 String [] soapActionHeaders = message .getSaajMessage ().getMimeHeaders ().getHeader (TransportConstants .HEADER_SOAP_ACTION );
64- Assert .assertEquals ("\" \" " , soapActionHeaders [0 ]);
67+
68+ assertThat (soapActionHeaders .length , is (1 ));
69+ assertThat (soapActionHeaders [0 ], is ("\" \" " ));
6570 }
6671
6772 @ Test
68- public void noSoapAction12 () throws IOException
69- {
73+ public void noSoapAction12 () throws IOException {
7074 SaajSoapMessage message = saaj12Factory .createWebServiceMessage ();
7175 String [] soapActionHeaders = message .getSaajMessage ().getMimeHeaders ().getHeader (TransportConstants .HEADER_SOAP_ACTION );
72- Assert .assertNull (soapActionHeaders );
76+
77+ assertThat (soapActionHeaders , is (nullValue ()));
7378 }
7479
7580 @ Test
76- public void soapAction12 () throws IOException
77- {
81+ public void soapAction12ShouldProduceNoSoapActionHeader () throws IOException {
7882 SaajSoapMessage message = saaj12Factory .createWebServiceMessage ();
7983 SoapActionCallback callback = new SoapActionCallback ("testAction" );
8084 callback .doWithMessage (message );
8185 String [] soapActionHeaders = message .getSaajMessage ().getMimeHeaders ().getHeader (TransportConstants .HEADER_SOAP_ACTION );
82- Assert .assertNull (soapActionHeaders );
8386 String [] contentTypes = message .getSaajMessage ().getMimeHeaders ().getHeader (TransportConstants .HEADER_CONTENT_TYPE );
84- Assert .assertEquals ("\" testAction\" " , SoapUtils .extractActionFromContentType (contentTypes [0 ]));
87+
88+ assertThat (soapActionHeaders , is (nullValue ()));
89+ assertThat (SoapUtils .extractActionFromContentType (contentTypes [0 ]), is ("\" testAction\" " ));
8590 }
8691
8792 @ Test
88- public void emptySoapAction12 () throws IOException
89- {
93+ public void emptySoapAction12ShouldProduceNoSoapActionHeader () throws IOException {
9094 SaajSoapMessage message = saaj12Factory .createWebServiceMessage ();
9195 SoapActionCallback callback = new SoapActionCallback (null );
9296 callback .doWithMessage (message );
9397 String [] soapActionHeaders = message .getSaajMessage ().getMimeHeaders ().getHeader (TransportConstants .HEADER_SOAP_ACTION );
94- Assert .assertNull (soapActionHeaders );
9598 String [] contentTypes = message .getSaajMessage ().getMimeHeaders ().getHeader (TransportConstants .HEADER_CONTENT_TYPE );
96- Assert .assertEquals ("\" \" " , SoapUtils .extractActionFromContentType (contentTypes [0 ]));
99+
100+ assertThat (soapActionHeaders , is (nullValue ()));
101+ assertThat (SoapUtils .extractActionFromContentType (contentTypes [0 ]), is ("\" \" " ));
97102 }
98103
99104}
0 commit comments