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