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 java.util.Date;
20 import javax.xml.parsers.DocumentBuilderFactory;
21 import javax.xml.parsers.DocumentBuilder;
22 import javax.xml.transform.dom.DOMSource;
23 import javax.xml.transform.stream.StreamSource;
24
25 import junit.framework.*;
26
27 import org.springframework.ws.transport.http.LastModifiedHelper;
28 import org.springframework.core.io.Resource;
29 import org.springframework.core.io.ClassPathResource;
30 import org.springframework.xml.transform.ResourceSource;
31
32 import org.w3c.dom.Document;
33
34 public class LastModifiedHelperTest extends TestCase {
35
36 private Resource resource;
37
38 private long expected;
39
40 protected void setUp() throws Exception {
41 resource = new ClassPathResource("single.xsd", getClass());
42 expected = resource.lastModified();
43 }
44
45 public void testSaxSource() throws Exception {
46 long result = LastModifiedHelper.getLastModified(new ResourceSource(resource));
47 assertEquals("Invalid last modified", expected, result);
48 }
49
50 public void testDomSource() throws Exception {
51 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
52 documentBuilderFactory.setNamespaceAware(true);
53 DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
54 Document document = documentBuilder.parse(resource.getFile());
55 long result = LastModifiedHelper.getLastModified(new DOMSource(document));
56 assertEquals("Invalid last modified", expected, result);
57 }
58
59 public void testStreamSource() throws Exception {
60 long result = LastModifiedHelper.getLastModified(new StreamSource(resource.getFile()));
61 assertEquals("Invalid last modified", expected, result);
62 }
63 }