1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
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, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.util.resource.impl;
17  
18  import java.io.InputStream;
19  import java.net.URL;
20  
21  import junit.framework.TestCase;
22  
23  import org.seasar.uruma.util.resource.ResourceHandler;
24  
25  /**
26   * {@link FileResourceTraverser} のためのテストクラスです。<br />
27   * 
28   * @author y-komori
29   */
30  public class FileResourceTraverserTest extends TestCase {
31      /**
32       * {@link FileResourceTraverser#traverse(URL, URL, ResourceHandler)}
33       * メソッドのテストです。<br />
34       */
35      public void testTraverse() {
36          FileResourceTraverser traverser = new FileResourceTraverser();
37          URL rootUrl = getClass().getResource("/");
38          URL originUrl = getClass().getResource("/org/seasar/uruma/util");
39  
40          try {
41              traverser.traverse(rootUrl, originUrl, new TestResourceHandler());
42              assertTrue(true);
43          } catch (Exception ex) {
44              ex.printStackTrace();
45              fail(ex.getMessage());
46          }
47  
48          try {
49              traverser.traverse(null, originUrl, new TestResourceHandler());
50              assertTrue(true);
51          } catch (Exception ex) {
52              ex.printStackTrace();
53              fail(ex.getMessage());
54          }
55      }
56  
57      private class TestResourceHandler implements ResourceHandler {
58          public void handle(final String rootPath, final String path,
59                  final InputStream is) {
60              if (rootPath == null || path == null || is == null) {
61                  fail();
62              }
63          }
64      }
65  }