1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }