1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.extensions.webscripts;
20
21 import java.io.IOException;
22
23 import junit.framework.TestCase;
24
25 import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
26 import org.springframework.extensions.webscripts.TestWebScriptServer.Request;
27 import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
28
29
30
31
32
33
34 public class WebScriptExceptionTest extends TestCase
35 {
36 private static final String URL_EXCEPTION = "/test/exception?a=1";
37
38 private static final TestWebScriptServer TEST_SERVER = TestWebScriptServer.getTestServer();
39
40
41
42
43
44
45
46 public void testScriptStatusTemplate() throws Exception
47 {
48 String res = "Failed /alfresco/service/test/exception - args 1";
49 sendRequest(new GetRequest(URL_EXCEPTION), 500, res);
50 }
51
52
53
54
55
56
57
58
59 private Response sendRequest(Request req, int expectedStatus, String expectedResponse) throws IOException
60 {
61 System.out.println();
62 System.out.println("* Request: " + req.getMethod() + " " + req.getFullUri() + (req.getBody() == null ? "" : "\n" + req.getBody()));
63
64 Response res = TEST_SERVER.submitRequest(req);
65
66 System.out.println();
67 System.out.println("* Response: " + res.getStatus() + " " + req.getMethod() + " " + req.getFullUri() + "\n" + res.getContentAsString());
68 if (expectedStatus > 0)
69 {
70 assertEquals("Unexpected status code", expectedStatus, res.getStatus());
71 }
72 if (expectedResponse != null)
73 {
74 assertEquals("Unexpected response", expectedResponse, res.getContentAsString());
75 }
76 return res;
77 }
78 }