1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.transport.http;
18
19 import javax.servlet.http.HttpServletResponse;
20
21 import org.custommonkey.xmlunit.XMLTestCase;
22
23 import org.springframework.core.io.ClassPathResource;
24 import org.springframework.core.io.Resource;
25 import org.springframework.mock.web.MockHttpServletRequest;
26 import org.springframework.mock.web.MockHttpServletResponse;
27 import org.springframework.util.FileCopyUtils;
28 import org.springframework.xml.xsd.SimpleXsdSchema;
29
30 public class XsdSchemaHandlerAdapterTest extends XMLTestCase {
31
32 private XsdSchemaHandlerAdapter adapter;
33
34 private MockHttpServletRequest request;
35
36 private MockHttpServletResponse response;
37
38 protected void setUp() throws Exception {
39 adapter = new XsdSchemaHandlerAdapter();
40 request = new MockHttpServletRequest();
41 response = new MockHttpServletResponse();
42 }
43
44 public void testGetLastModified() throws Exception {
45 Resource single = new ClassPathResource("single.xsd", getClass());
46 SimpleXsdSchema schema = new SimpleXsdSchema(single);
47 schema.afterPropertiesSet();
48 long lastModified = single.getFile().lastModified();
49 assertEquals("Invalid last modified", lastModified, adapter.getLastModified(null, schema));
50 }
51
52 public void testHandleGet() throws Exception {
53 request.setMethod(HttpTransportConstants.METHOD_GET);
54 Resource single = new ClassPathResource("single.xsd", getClass());
55 SimpleXsdSchema schema = new SimpleXsdSchema(single);
56 schema.afterPropertiesSet();
57 adapter.handle(request, response, schema);
58 String expected = new String(FileCopyUtils.copyToByteArray(single.getFile()));
59 assertXMLEqual(expected, response.getContentAsString());
60 }
61
62 public void testHandleNonGet() throws Exception {
63 request.setMethod(HttpTransportConstants.METHOD_POST);
64 adapter.handle(request, response, null);
65 assertEquals("METHOD_NOT_ALLOWED expected", HttpServletResponse.SC_METHOD_NOT_ALLOWED, response.getStatus());
66 }
67 }