1   /*
2    * Copyright 2004-2010 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  
17  package org.seasar.cubby.internal.util;
18  
19  import static org.junit.Assert.assertEquals;
20  
21  import java.lang.reflect.Method;
22  
23  import org.junit.Test;
24  import org.seasar.cubby.action.Path;
25  
26  public class MetaUtilsTest {
27  
28  	@Test
29  	public void getActionPath() throws Exception {
30  		assertEquals("/hoge/m1", MetaUtils.getActionPath(Hoge1Action.class,
31  				Hoge1Action.class.getMethod("m1")));
32  		assertEquals("/hoge/m/m2", MetaUtils.getActionPath(Hoge1Action.class,
33  				Hoge1Action.class.getMethod("m2")));
34  		assertEquals("/hoge/", MetaUtils.getActionPath(Hoge1Action.class,
35  				Hoge1Action.class.getMethod("index")));
36  		assertEquals("/hoge/index2", MetaUtils.getActionPath(Hoge1Action.class,
37  				Hoge1Action.class.getMethod("index2")));
38  		assertEquals("/hoge2/m1", MetaUtils.getActionPath(Hoge2Action.class,
39  				Hoge2Action.class.getMethod("m1")));
40  		assertEquals("/hoge/m2", MetaUtils.getActionPath(Hoge2Action.class,
41  				Hoge2Action.class.getMethod("m2")));
42  		assertEquals("/", MetaUtils.getActionPath(MockAction.class,
43  				MockAction.class.getMethod("index")));
44  		assertEquals("/dummy1", MetaUtils.getActionPath(MockAction.class,
45  				MockAction.class.getMethod("dummy1")));
46  		assertEquals("/dummy2", MetaUtils.getActionPath(MockAction.class,
47  				MockAction.class.getMethod("dummy2")));
48  		assertEquals("/todo/lists", MetaUtils.getActionPath(MockAction.class,
49  				MockAction.class.getMethod("todolist")));
50  		assertEquals("/tasklists", MetaUtils.getActionPath(MockAction.class,
51  				MockAction.class.getMethod("tasklist")));
52  	}
53  
54  	@Test
55  	public void getActionClassName() {
56  		assertEquals("hoge", MetaUtils.getActionDirectory(Hoge1Action.class));
57  		assertEquals("hoge2", MetaUtils.getActionDirectory(Hoge2Action.class));
58  	}
59  
60  	@Test
61  	public void gGetPriority() throws Exception {
62  		Method method = TestGetPriprity.class.getMethod("m1", new Class[0]);
63  		assertEquals(Integer.MAX_VALUE, MetaUtils.getPriority(method));
64  
65  		method = TestGetPriprity.class.getMethod("m2", new Class[0]);
66  		assertEquals(Integer.MAX_VALUE, MetaUtils.getPriority(method));
67  
68  		method = TestGetPriprity.class.getMethod("m3", new Class[0]);
69  		assertEquals(0, MetaUtils.getPriority(method));
70  	}
71  
72  	static class TestGetPriprity {
73  		public void m1() {
74  		}
75  
76  		@Path
77  		public void m2() {
78  
79  		}
80  
81  		@Path(value = "", priority = 0)
82  		public void m3() {
83  
84  		}
85  	}
86  
87  }