📄 valuebindingtest.java
字号:
/* * Copyright 2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.myfaces.el;import java.util.Map;import javax.faces.el.ReferenceSyntaxException;import javax.faces.el.ValueBinding;/** * @author Manfred Geiler (latest modification by $Author: matze $) * @author Anton Koinov * @version $Revision: 1.30 $ $Date: 2004/10/13 11:50:59 $ * * $Log: ValueBindingTest.java,v $ * Revision 1.30 2004/10/13 11:50:59 matze * renamed packages to org.apache * * Revision 1.29 2004/09/28 19:08:26 dave0000 * commented some non-working testcases * * Revision 1.28 2004/09/27 03:12:54 dave0000 * *** empty log message *** * * Revision 1.26 2004/09/08 07:43:52 mwessendorf * added TestCase * * Revision 1.25 2004/09/06 16:21:10 mwessendorf * added TestCase * * Revision 1.24 2004/09/02 08:40:18 mwessendorf * added TestCase for bug #1018239 * * Revision 1.23 2004/09/01 18:25:19 mwessendorf * added TestCase * * Revision 1.22 2004/07/27 06:46:59 dave0000 * cleanup/arange testcases, remove duplicates * * Revision 1.21 2004/07/27 06:28:34 dave0000 * fix issue with getType of literal expressions (and other improvements) * * Revision 1.20 2004/07/01 22:00:55 mwessendorf * ASF switch * * Revision 1.19 2004/05/11 04:24:12 dave0000 * Bug 943166: add value coercion to ManagedBeanConfigurator * * Revision 1.18 2004/05/10 05:30:15 dave0000 * Fix issue with setting Managed Bean to a wrong scope * * Revision 1.17 2004/04/07 03:54:07 dave0000 * fix testcases to match removed trim() on expression string * * Revision 1.16 2004/03/30 07:38:11 dave0000 * implement mixed string-reference expressions */public class ValueBindingTest extends ELBaseTest{ //~ Constructors ------------------------------------------------------------------------------- public ValueBindingTest(String name) { super(name); } //~ Methods ------------------------------------------------------------------------------------ public void testGetValueWithLongName1() throws Exception { Object v; ValueBinding vb = _application.createValueBinding("#{theA}"); v = vb.getValue(_facesContext); assertTrue(v == _theA); } public void testGetValueWithLongName2() throws Exception { Object v; v = _application.createValueBinding("#{theA.name}").getValue( _facesContext); assertEquals(A.NAME, v); } public void testGetValueWithLongName3() throws Exception { Object v; v = _application.createValueBinding("#{theA.theB.name}").getValue( _facesContext); assertEquals(B.NAME, v); } public void testGetValueWithLongName4() throws Exception { Object v; v = _application.createValueBinding("#{theA.theB.theC.name}").getValue( _facesContext); assertEquals(C.DEFAULT_NAME, v); } public void testGetValueWithShortName1() throws Exception { Object v; v = _application.createValueBinding("#{a}").getValue(_facesContext); assertTrue(v == _a); } public void testGetValueWithShortName2() throws Exception { Object v; v = _application.createValueBinding("#{a.name}") .getValue(_facesContext); assertEquals(A.NAME, v); } public void testGetValueWithShortName3() throws Exception { Object v; v = _application.createValueBinding("#{a.b.name}").getValue( _facesContext); assertEquals(B.NAME, v); } public void testGetValueWithShortName4() throws Exception { Object v; v = _application.createValueBinding("#{a.b.c.name}").getValue( _facesContext); assertEquals(C.DEFAULT_NAME, v); } public void testGetValue() throws Exception { ValueBinding vb; Object r; vb = _application.createValueBinding("#{testmap}"); r = vb.getValue(_facesContext); assertEquals(_m, r); vb = _application.createValueBinding("#{true ? testmap : testmap.f}"); r = vb.getValue(_facesContext); assertEquals(_m, r); vb = _application.createValueBinding("#{testmap.f}"); r = vb.getValue(_facesContext); assertFalse(((Boolean) r).booleanValue()); vb = _application.createValueBinding("#{false ? testmap : testmap.f}"); r = vb.getValue(_facesContext); assertFalse(((Boolean) r).booleanValue()); vb = _application.createValueBinding("#{testmap.t}"); r = vb.getValue(_facesContext); assertTrue(((Boolean) r).booleanValue()); vb = _application.createValueBinding("#{testmap[\"o\"]['obj']}"); r = vb.getValue(_facesContext); assertEquals("OBJECT", r); vb = _application .createValueBinding("#{ testmap [ \"o\" ] [ 'obj' ] }"); r = vb.getValue(_facesContext); assertEquals("OBJECT", r); vb = _application.createValueBinding("#{testmap.true_}"); r = vb.getValue(_facesContext); assertEquals("TRUE_", r); vb = _application.createValueBinding("#{ testmap . true_ }"); r = vb.getValue(_facesContext); assertEquals("TRUE_", r); vb = _application.createValueBinding("#{testmap[\"true_\"]}"); r = vb.getValue(_facesContext); assertEquals("TRUE_", r); vb = _application.createValueBinding("#{testmap['true_']}"); r = vb.getValue(_facesContext); assertEquals("TRUE_", r); vb = _application.createValueBinding("#{testmap[testmap.t]}"); r = vb.getValue(_facesContext); assertEquals("TRUE", r); vb = _application .createValueBinding("#{ testmap [ testmap . t ] }"); r = vb.getValue(_facesContext); assertEquals("TRUE", r); vb = _application.createValueBinding("#{testmap.false_}"); r = vb.getValue(_facesContext); assertEquals("FALSE_", r); vb = _application.createValueBinding("#{testmap[testmap.f]}"); r = vb.getValue(_facesContext); assertEquals("FALSE", r); vb = _application.createValueBinding("#{testmap['map']}"); r = vb.getValue(_facesContext); assertEquals(_m, r); vb = _application.createValueBinding("#{testmap[\"David's\"]}"); r = vb.getValue(_facesContext); assertEquals(_m, r); vb = _application.createValueBinding("#{testmap['David\\'s']}"); r = vb.getValue(_facesContext); assertEquals(_m, r); vb = _application.createValueBinding("#{testmap['my]bracket[']}"); r = vb.getValue(_facesContext); assertEquals(_m, r); vb = _application.createValueBinding("#{testmap[\"my]bracket[\"]}"); r = vb.getValue(_facesContext); assertEquals(_m, r); vb = _application.createValueBinding("#{testmap[\"my\\\\]bracket[\"]}"); r = vb.getValue(_facesContext); assertEquals(_m, r); vb = _application.createValueBinding("#{testmap[0][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application.createValueBinding("#{ testmap [ 0 ] [ 0 ]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application.createValueBinding("#{testmap.o0.obj[0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application.createValueBinding("#{testmap.o1.obj[0][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application.createValueBinding("#{testmap.list[0][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application.createValueBinding("#{testmap.list[1][0]}"); r = vb.getValue(_facesContext); assertEquals(_a0, r); vb = _application.createValueBinding("#{testmap.list[4][0][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application.createValueBinding("#{testmap.list[4][1][0][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application .createValueBinding("#{testmap.list[4].list[1][0][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application .createValueBinding("#{testmap.map.map.list[4].list[4][1][0][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application .createValueBinding("#{testmap.map.list[4].map.list[4][1][0][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application .createValueBinding("#{testmap.list[4][testmap.list[4][0][0]][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application .createValueBinding("#{testmap.list[4][1][0][testmap.list[4][0][0]]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application .createValueBinding("#{testmap.list[4].list[testmap.list[4][1][0][testmap.list[4][0][1]]][0][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application .createValueBinding("#{testmap.map.map.list[4].list[4][1][testmap.list[4].list[testmap.list[4][1][0][testmap.list[4][0][testmap.t]]][0][0]][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application .createValueBinding("#{testmap['my]bracket[']['map'].list[4]['map'][\"list\"][4][1][testmap.map.map.list[4].list[4][1][testmap.list[4].list[testmap.list[4][1][testmap.f][testmap['list'][4][0][1]]][0][0]][0]][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application .createValueBinding("#{testmap['my]bracket[']['map'].list[4]['map'][\"list\"][4][1][testmap.map.map.list[4].list[4][1][testmap.list[4].list[testmap.list[4][1][testmap.f][testmap['list'][4][0][1]]][0][0]][0]][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application .createValueBinding("#{testmap['my\\\\]bracket[']['map'].list[4]['map'][\"list\"][4][1][testmap.map.map.list[4].list[4][1][testmap.list[4].list[testmap.list[4][1][testmap.f][testmap['list'][4][0][1]]][0][0]][0]][0]}"); r = vb.getValue(_facesContext); assertEquals(new Integer(0), r); vb = _application.createValueBinding("#{testmap[\"\\\\]true[\"]}"); r = vb.getValue(_facesContext); assertEquals("_TRUE_", r);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -