1   /*
2    * Copyright 2008 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }