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