1 /*
2 * Copyright 2011 FatWire Corporation. All Rights Reserved.
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 com.fatwire.gst.foundation.controller.annotation;
18
19 import java.lang.reflect.InvocationTargetException;
20 import java.lang.reflect.Method;
21
22 import junit.framework.TestCase;
23 import COM.FutureTense.Interfaces.ICS;
24
25 import com.fatwire.gst.foundation.test.MockICS;
26
27 public class ControllerMappingResolverTest extends TestCase {
28
29 static class Foo {
30 int i = 0;
31
32 @IcsVariable(var = { "cmd=login", "cmd=logout" })
33 public void doSomething(final ICS ics) {
34 i++;
35
36 }
37 }
38
39 public void testFindControllerMethod() throws IllegalArgumentException, IllegalAccessException,
40 InvocationTargetException {
41 final ControllerMappingResolver resolver = new ControllerMappingResolver();
42 final Foo foo = new Foo();
43 final ICS ics = new MockICS() {
44
45 /*
46 * (non-Javadoc)
47 *
48 * @see
49 * com.fatwire.gst.foundation.facade.uri.MockICS#GetVar(java.lang
50 * .String)
51 */
52 @Override
53 public String GetVar(final String name) {
54 if ("cmd".equals(name)) {
55 return "login";
56 }
57 return null;
58 }
59
60 };
61 final Method m = resolver.findControllerMethod(ics, foo);
62 m.invoke(foo, new Object[] { ics });
63 assertEquals(1, foo.i);
64 }
65
66 }