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 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 }