View Javadoc
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  /**
28   * @deprecated - WCS 12c supports its own native controller infrastructure
29   */
30  public class ControllerMappingResolverTest extends TestCase {
31  
32      static class Foo {
33          int i = 0;
34  
35          @IcsVariable(var = { "cmd=login", "cmd=logout" })
36          public void doSomething(final ICS ics) {
37              i++;
38  
39          }
40      }
41  
42      public void testFindControllerMethod() throws IllegalArgumentException, IllegalAccessException,
43              InvocationTargetException {
44          final ControllerMappingResolver resolver = new ControllerMappingResolver();
45          final Foo foo = new Foo();
46          final ICS ics = new MockICS() {
47  
48              /*
49               * (non-Javadoc)
50               * 
51               * @see
52               * com.fatwire.gst.foundation.facade.uri.MockICS#GetVar(java.lang
53               * .String)
54               */
55              @Override
56              public String GetVar(final String name) {
57                  if ("cmd".equals(name)) {
58                      return "login";
59                  }
60                  return null;
61              }
62  
63          };
64          final Method m = resolver.findControllerMethod(ics, foo);
65          m.invoke(foo, new Object[] { ics });
66          assertEquals(1, foo.i);
67      }
68  
69  }