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.component.factory.desc;
17  
18  import junit.framework.TestCase;
19  
20  import org.seasar.framework.exception.ResourceNotFoundRuntimeException;
21  import org.seasar.framework.exception.SAXRuntimeException;
22  import org.seasar.framework.util.ResourceUtil;
23  
24  /**
25   * {@link ComponentRegistry} のためのテストクラスです。<br />
26   * 
27   * @author y-komori
28   */
29  public class ComponentRegistryTest extends TestCase {
30      /**
31       * 
32       */
33      public void testRegistComponents() {
34          ComponentRegistry registry = new ComponentRegistry();
35          // registry.registComponents();
36      }
37  
38      /**
39       * {@link ComponentRegistry#load(String)} メソッドのテストです。<br />
40       */
41      public void testLoad1() {
42          String path = createPath("1");
43          ComponentRegistry registry = new ComponentRegistry();
44          UrumaComponentDesc desc = registry.load(path);
45          assertNotNull("1", desc);
46          assertEquals("2", "tagName:testTag "
47                  + "tagHandler:org.seasar.uruma.dummy.TagHandler(arg1, arg2) "
48                  + "renderer:org.seasar.uruma.dummy.Renderer(arg1, arg2, arg3)",
49                  desc.toString());
50      }
51  
52      /**
53       * {@link ComponentRegistry#load(String)} メソッドのテストです。<br />
54       */
55      public void testLoad2() {
56          String path = createPath("2");
57          ComponentRegistry registry = new ComponentRegistry();
58          try {
59              registry.load(path);
60              fail();
61          } catch (SAXRuntimeException ex) {
62              assertTrue(true);
63          }
64      }
65  
66      /**
67       * {@link ComponentRegistry#load(String)} メソッドのテストです。<br />
68       */
69      public void testLoad3() {
70          String path = createPath("NG");
71          ComponentRegistry registry = new ComponentRegistry();
72          try {
73              registry.load(path);
74              fail();
75          } catch (ResourceNotFoundRuntimeException ex) {
76              assertTrue(true);
77          }
78      }
79  
80      private String createPath(final String suffix) {
81          return ResourceUtil.convertPath(getClass().getSimpleName() + suffix
82                  + ".ucd", getClass());
83      }
84  }