1   /*
2    * Copyright 2005-2010 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.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  }