1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.test.support.matcher;
18
19 import javax.xml.namespace.QName;
20 import javax.xml.soap.MessageFactory;
21 import javax.xml.soap.SOAPMessage;
22
23 import org.springframework.ws.WebServiceMessage;
24 import org.springframework.ws.soap.SoapMessage;
25 import org.springframework.ws.soap.saaj.SaajSoapMessage;
26
27 import org.junit.Before;
28 import org.junit.Test;
29
30 import static org.easymock.EasyMock.createMock;
31
32 public class SoapHeaderMatcherTest {
33
34 private SoapHeaderMatcher matcher;
35
36 private QName expectedHeaderName;
37
38 @Before
39 public void setUp() throws Exception {
40 expectedHeaderName = new QName("http://example.com", "header");
41 matcher = new SoapHeaderMatcher(expectedHeaderName);
42 }
43
44 @Test
45 public void match() throws Exception {
46 MessageFactory messageFactory = MessageFactory.newInstance();
47 SOAPMessage saajMessage = messageFactory.createMessage();
48 saajMessage.getSOAPHeader().addHeaderElement(expectedHeaderName);
49 SoapMessage soapMessage = new SaajSoapMessage(saajMessage);
50
51 matcher.match(soapMessage);
52 }
53
54 @Test(expected = AssertionError.class)
55 public void nonMatch() throws Exception {
56 MessageFactory messageFactory = MessageFactory.newInstance();
57 SOAPMessage saajMessage = messageFactory.createMessage();
58 SoapMessage soapMessage = new SaajSoapMessage(saajMessage);
59
60 matcher.match(soapMessage);
61 }
62
63 @Test(expected = AssertionError.class)
64 public void nonSoap() throws Exception {
65 WebServiceMessage message = createMock(WebServiceMessage.class);
66
67 matcher.match(message);
68 }
69
70 }