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.soap.support;
18  
19  import org.junit.Assert;
20  import org.junit.Test;
21  
22  public class SoapUtilsTest {
23  
24      @Test
25      public void testExtractActionFromContentType() throws Exception {
26          String soapAction = "http://springframework.org/spring-ws/Action";
27  
28          String contentType = "application/soap+xml; action=" + soapAction;
29          String result = SoapUtils.extractActionFromContentType(contentType);
30          Assert.assertEquals("Invalid SOAP action", soapAction, result);
31  
32          contentType = "application/soap+xml; action   = " + soapAction;
33          result = SoapUtils.extractActionFromContentType(contentType);
34          Assert.assertEquals("Invalid SOAP action", soapAction, result);
35  
36          contentType = "application/soap+xml; action=" + soapAction + " ; charset=UTF-8";
37          result = SoapUtils.extractActionFromContentType(contentType);
38          Assert.assertEquals("Invalid SOAP action", soapAction, result);
39  
40          contentType = "application/soap+xml; charset=UTF-8; action=" + soapAction;
41          result = SoapUtils.extractActionFromContentType(contentType);
42          Assert.assertEquals("Invalid SOAP action", soapAction, result);
43      }
44  
45      @Test
46      public void testEscapeAction() throws Exception {
47          String result = SoapUtils.escapeAction("action");
48          Assert.assertEquals("Invalid SOAP action", "\"action\"", result);
49  
50          result = SoapUtils.escapeAction("\"action\"");
51          Assert.assertEquals("Invalid SOAP action", "\"action\"", result);
52  
53          result = SoapUtils.escapeAction("");
54          Assert.assertEquals("Invalid SOAP action", "\"\"", result);
55  
56          result = SoapUtils.escapeAction(null);
57          Assert.assertEquals("Invalid SOAP action", "\"\"", result);
58  
59      }
60  
61      @Test
62      public void testSetActionInContentType() throws Exception {
63          String soapAction = "http://springframework.org/spring-ws/Action";
64          String contentType = "application/soap+xml";
65  
66          String result = SoapUtils.setActionInContentType(contentType, soapAction);
67          Assert.assertEquals("Invalid SOAP action", soapAction, SoapUtils.extractActionFromContentType(result));
68  
69          String anotherSoapAction = "http://springframework.org/spring-ws/AnotherAction";
70          String contentTypeWithAction = "application/soap+xml; action=http://springframework.org/spring-ws/Action";
71          result = SoapUtils.setActionInContentType(contentTypeWithAction, anotherSoapAction);
72          Assert.assertEquals("Invalid SOAP action", anotherSoapAction, SoapUtils.extractActionFromContentType(result));
73  
74      }
75  
76  }