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  package com.fatwire.gst.foundation.controller.action;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNull;
20  
21  import org.junit.Test;
22  
23  import COM.FutureTense.Interfaces.ICS;
24  import COM.FutureTense.Util.ftMessage;
25  
26  import com.fatwire.gst.foundation.controller.annotation.Bind;
27  import com.fatwire.gst.foundation.test.MockICS;
28  
29  public class AnnotationBinderTest {
30  
31      class MyObject {
32          @Bind
33          String pagename;
34          @Bind
35          long cid;
36          @Bind
37          Long tid;
38          @Bind
39          String c;
40          @Bind("foo")
41          String bar;
42  
43      }
44  
45      @Test
46      public void testBind_csvar() {
47          MyObject o = new MyObject();
48          ICS ics = new MockICS() {
49  
50              @Override
51              public String GetVar(String key) {
52                  if (ftMessage.PageName.equals(key)) {
53                      return "hello";
54                  } else if ("cid".equals(key)) {
55                      return "12345678901234";
56                  } else if ("tid".equals(key)) {
57                      return "22345678901234";
58                  } else if ("foo".equals(key)) {
59                      return "oof";
60  
61                  }
62                  return null;
63              }
64  
65          };
66          AnnotationBinder.bind(o, ics);
67          assertEquals("hello", o.pagename);
68          assertEquals(12345678901234L, o.cid);
69          assertEquals(new Long(22345678901234L), o.tid);
70          assertNull(o.c);
71          assertEquals("oof", o.bar);
72      }
73  
74  }