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.soap.MessageFactory;
20
21 import org.springframework.ws.WebServiceMessage;
22 import org.springframework.ws.soap.SoapMessage;
23 import org.springframework.ws.soap.saaj.SaajSoapMessage;
24 import org.springframework.xml.transform.StringSource;
25
26 import org.junit.Test;
27
28 import static org.easymock.EasyMock.*;
29
30 public class PayloadDiffMatcherTest {
31
32 @Test
33 public void match() throws Exception {
34 String xml = "<element xmlns='http://example.com'/>";
35 WebServiceMessage message = createMock(WebServiceMessage.class);
36 expect(message.getPayloadSource()).andReturn(new StringSource(xml)).times(2);
37 replay(message);
38
39 PayloadDiffMatcher matcher = new PayloadDiffMatcher(new StringSource(xml));
40 matcher.match(message);
41
42 verify(message);
43 }
44
45 @Test(expected = AssertionError.class)
46 public void nonMatch() throws Exception {
47 String actual = "<element1 xmlns='http://example.com'/>";
48 WebServiceMessage message = createMock(WebServiceMessage.class);
49 expect(message.getPayloadSource()).andReturn(new StringSource(actual)).times(2);
50 replay(message);
51
52 String expected = "<element2 xmlns='http://example.com'/>";
53 PayloadDiffMatcher matcher = new PayloadDiffMatcher(new StringSource(expected));
54 matcher.match(message);
55 }
56
57 @Test(expected = AssertionError.class)
58 public void noPayload() throws Exception {
59 PayloadDiffMatcher matcher = new PayloadDiffMatcher(new StringSource("<message/>"));
60 MessageFactory messageFactory = MessageFactory.newInstance();
61 SoapMessage soapMessage = new SaajSoapMessage(messageFactory.createMessage());
62
63 matcher.createDiff(soapMessage);
64 }
65
66 }