KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > myfaces > el > MethodBindingTest


1 /*
2  * Copyright 2004 The Apache Software Foundation.
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 org.apache.myfaces.el;
17
18 import javax.faces.el.MethodBinding;
19
20
21 /**
22  * @author Manfred Geiler (latest modification by $Author: matze $)
23  * @author Anton Koinov
24  * @version $Revision: 1.4 $ $Date: 2004/10/13 11:50:59 $
25  */

26 public class MethodBindingTest extends ELBaseTest
27 {
28     //~ Constructors -------------------------------------------------------------------------------
29

30     public MethodBindingTest(String JavaDoc name)
31     {
32         super(name);
33     }
34
35     //~ Methods ------------------------------------------------------------------------------------
36

37     public void testGetType() throws Exception JavaDoc
38     {
39         MethodBinding mb;
40         
41         mb = _application.createMethodBinding("#{a.getName}", new Class JavaDoc[] {});
42         assertSame(String JavaDoc.class, mb.getType(_facesContext));
43
44         mb = _application.createMethodBinding("#{a.getInt}", new Class JavaDoc[] {});
45         assertSame(Integer JavaDoc.class, mb.getType(_facesContext));
46
47         mb = _application.createMethodBinding("#{theA.theB.getName}", new Class JavaDoc[] {});
48         assertSame(String JavaDoc.class, mb.getType(_facesContext));
49
50         mb = _application.createMethodBinding("#{testmap.toString}", new Class JavaDoc[] {});
51         assertSame(String JavaDoc.class, mb.getType(_facesContext));
52
53         mb = _application.createMethodBinding("#{ testmap [ 0 ] [ 1 ] . toString}", new Class JavaDoc[] {});
54         assertSame(String JavaDoc.class, mb.getType(_facesContext));
55
56         mb = _application.createMethodBinding("#{true ? a.getName : a.getInt}", new Class JavaDoc[] {});
57         assertSame(String JavaDoc.class, mb.getType(_facesContext));
58
59         mb = _application.createMethodBinding("#{false ? a.getName : a.getInt}", new Class JavaDoc[] {});
60         assertSame(Integer JavaDoc.class, mb.getType(_facesContext));
61
62         try
63         {
64             mb = _application.createMethodBinding("#{testmap}", new Class JavaDoc[] {});
65             mb.getType(_facesContext);
66             assertTrue(false);
67         }
68         catch (Exception JavaDoc e) {
69             // ignore, error expected
70
}
71     }
72
73     public void testInvoke() throws Exception JavaDoc
74     {
75         MethodBinding mb;
76         
77         mb = _application.createMethodBinding("#{a.getName}", new Class JavaDoc[] {});
78         assertSame(A.NAME, mb.invoke(_facesContext, null));
79
80         mb = _application.createMethodBinding("#{theA.theB.getName}", new Class JavaDoc[] {});
81         assertSame(B.NAME, mb.invoke(_facesContext, null));
82
83         mb = _application.createMethodBinding("#{true ? a.getName : a.getInt}", new Class JavaDoc[] {});
84         assertSame(A.NAME, mb.invoke(_facesContext, null));
85
86         mb = _application.createMethodBinding("#{false ? a.getName : a.getInt}", new Class JavaDoc[] {});
87         assertEquals(new Integer JavaDoc(0), mb.invoke(_facesContext, null));
88
89         mb = _application.createMethodBinding("#{false ? a.getName : true ? a.getInt : zzz}", new Class JavaDoc[] {});
90         assertEquals(new Integer JavaDoc(0), mb.invoke(_facesContext, null));
91     }
92 }
93
Popular Tags