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