1   /*
2    * Copyright 2005-2011 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }