valuebindingtest.java

来自「一个使用struts+hibernate+spring开发的完的网站源代码。」· Java 代码 · 共 644 行 · 第 1/2 页

JAVA
644
字号
        vb = _application.createValueBinding("#{testmap['\\\\]false[']}");        r = vb.getValue(_facesContext);        assertEquals("_FALSE_", r);        // Now check for error conditions        try        {            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]}");            assertTrue(false);        }        catch (ReferenceSyntaxException e)        {            //System.out.println(e.getMessage());            // we expect this        }        try        {            vb = _application                .createValueBinding("#{testmap.map.list[4].map.list[][1][0][0]}");            assertTrue(false);        }        catch (ReferenceSyntaxException e)        {            //System.out.println(e.getMessage());            // we expect this        }        try        {            vb = _application                .createValueBinding("#{testmap.map.list[4].map.list.[4][1][0][0]}");            assertTrue(false);        }        catch (ReferenceSyntaxException e)        {            //System.out.println(e.getMessage());            // we expect this        }        try        {            vb = _application                .createValueBinding("#{testmap.map.list[4].map..list[4][1][0][0]}");            assertTrue(false);        }        catch (ReferenceSyntaxException e)        {            //System.out.println(e.getMessage());            // we expect this        }        try        {            vb = _application                .createValueBinding("#{.testmap.map.list[4].map.list[4][1][0][0]}");            assertTrue(false);        }        catch (ReferenceSyntaxException e)        {            //System.out.println(e.getMessage());            // we expect this        }        try        {            vb = _application                .createValueBinding("#{testmap.map.list[4].map.list[4[1][0]['0']}");            assertTrue(false);        }        catch (ReferenceSyntaxException e)        {            //System.out.println(e.getMessage());            // we expect this        }        try        {            vb = _application                .createValueBinding("#{testmap.map.list[4].map.list[4][1][0].[0]}");            assertTrue(false);        }        catch (ReferenceSyntaxException e)        {            //System.out.println(e.getMessage());            // we expect this        }    }    public void testMixedExpressions()    {        ValueBinding vb;        Object r;        vb = _application            .createValueBinding("This is one #{testmap[\"o\"]['obj']}");        r = vb.getValue(_facesContext);        assertEquals("This is one OBJECT", r);        vb = _application            .createValueBinding("#{ testmap [ \"o\" ] [ 'obj' ] } is the One.");        r = vb.getValue(_facesContext);        assertEquals("OBJECT is the One.", r);        vb = _application.createValueBinding("Is it really #{testmap.true_}?");        r = vb.getValue(_facesContext);        assertEquals("Is it really TRUE_?", r);        vb = _application            .createValueBinding("#{testmap . true_} or #{testmap.false_}, that's the question!");        r = vb.getValue(_facesContext);        assertEquals("TRUE_ or FALSE_, that's the question!", r);        vb = _application            .createValueBinding("What? #{testmap . true_} or #{testmap.false_}, that's the question!");        r = vb.getValue(_facesContext);        assertEquals("What? TRUE_ or FALSE_, that's the question!", r);        vb = _application            .createValueBinding("What? ${ #{testmap . true_} or #{testmap.false_}, that's the question! }");        r = vb.getValue(_facesContext);        assertEquals("What? ${ TRUE_ or FALSE_, that's the question! }", r);        vb = _application            .createValueBinding("#{ '#{' } What? ${ #{true ? '${' : \"#{\\\\\"} #{testmap . true_} or #{testmap.false_}, that's the question! }");        r = vb.getValue(_facesContext);        assertEquals("#{ What? ${ ${ TRUE_ or FALSE_, that's the question! }",            r);//        // Test '\' as escape for #{//        vb     = _application.createValueBinding("\\#{ \\\\\\#{ What? ${ \\\\#{false ? '${' : \"#{\\\\\"} #{testmap . true_} or #{testmap.false_}, that's the question! }");//        r = vb.getValue(_facesContext);//        assertEquals("#{ \\#{ What? ${ \\\\#{\\ TRUE_ or FALSE_, that's the question! }", r);    }    public void testIsReadOnly() throws Exception    {        ValueBinding vb;        vb = _application.createValueBinding("#{'constant literal'}");        assertTrue(vb.isReadOnly(_facesContext));        vb = _application.createValueBinding("#{cookie}");        assertTrue(vb.isReadOnly(_facesContext));        vb = _application.createValueBinding("#{requestScope}");        assertTrue(vb.isReadOnly(_facesContext));        vb = _application.createValueBinding("#{a.name}");        assertTrue(vb.isReadOnly(_facesContext));        vb = _application.createValueBinding("#{theA.theB.name}");        assertFalse(vb.isReadOnly(_facesContext));        vb = _application.createValueBinding("#{testmap}");        assertFalse(vb.isReadOnly(_facesContext));        vb = _application.createValueBinding("#{testmap.f}");        assertFalse(vb.isReadOnly(_facesContext));        vb = _application.createValueBinding("#{ testmap  [  0  ]  [  0  ]}");        assertFalse(vb.isReadOnly(_facesContext));        vb = _application.createValueBinding("#{true ? cookie : max}");        assertTrue(vb.isReadOnly(_facesContext));        vb = _application.createValueBinding("#{false ? cookie : max}");        assertFalse(vb.isReadOnly(_facesContext));        //-----------------------------------------------------        // Read-only of nonexistent object (e.g., one whose base is null)        vb = _application.createValueBinding("#{nonExistentValueBlahBlahBlah}");        assertFalse(vb.isReadOnly(_facesContext));        vb = _application            .createValueBinding("#{nonExistingValueBlahBlahBlah.blah}");        assertFalse(vb.isReadOnly(_facesContext));        vb = _application            .createValueBinding("#{nonExistingValueBlahBlahBlah.blah.blah}");        assertFalse(vb.isReadOnly(_facesContext));    }    public void testGetType() throws Exception    {        ValueBinding vb;        //-----------------------------------------------------        // Literal expression        vb = _application.createValueBinding("#{'constant literal'}");        assertSame(String.class, vb.getType(_facesContext));        vb = _application.createValueBinding("#{false && true}");        assertSame(Boolean.class, vb.getType(_facesContext));        vb = _application            .createValueBinding("#{applicationScope.bean == null}");        assertSame(Boolean.class, vb.getType(_facesContext));        // REVISIT: Should getType of implicit object throw an error,        //          return null, or Object.class, or the appropriate Map class?        vb = _application.createValueBinding("#{cookie}");        assertTrue(Map.class.isAssignableFrom(vb.getType(_facesContext)));        vb = _application.createValueBinding("#{requestScope}");        assertTrue(Map.class.isAssignableFrom(vb.getType(_facesContext)));        vb = _application.createValueBinding("#{true ? cookie : max}");        assertTrue(Map.class.isAssignableFrom(vb.getType(_facesContext)));        // REVISIT: should unknown bean name return type null or Object.class?        vb = _application.createValueBinding("#{false ? cookie : max}");        assertSame(Object.class, vb.getType(_facesContext));        //-----------------------------------------------------        // Specific types        vb = _application.createValueBinding("#{a.name}");        assertSame(A.NAME.getClass(), vb.getType(_facesContext));        vb = _application.createValueBinding("#{theA.theB.name}");        assertSame(B.NAME.getClass(), vb.getType(_facesContext));        vb = _application.createValueBinding("#{testmap}");        assertSame(_m.getClass(), vb.getType(_facesContext));        vb = _application.createValueBinding("#{testmap.f}");        assertSame(Boolean.class, vb.getType(_facesContext));        vb = _application.createValueBinding("#{ testmap  [  0  ]  [  1  ]}");        // Object.class is the _a0 Array Component Type!        assertSame(Object.class, vb.getType(_facesContext));        //-----------------------------------------------------        // Type of nonexistent object (e.g., one whose base is null)        vb = _application.createValueBinding("#{nonExistentValueBlahBlahBlah}");        assertSame(Object.class, vb.getType(_facesContext));        vb = _application            .createValueBinding("#{nonExistingValueBlahBlahBlah.blah}");        assertSame(null, vb.getType(_facesContext));        vb = _application            .createValueBinding("#{nonExistingValueBlahBlahBlah.blah.blah}");        assertSame(null, vb.getType(_facesContext));    }    public void testManagedBean() throws Exception    {        ValueBinding vb;        vb = _application.createValueBinding("#{testBean_B.name}");        assertEquals("testName", vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_B.int}");        assertEquals(new Integer(1), vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_B.double}");        assertEquals(new Double(1.1), vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_B.integer}");        assertEquals(new Integer(2), vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_B.double2}");        assertEquals(new Double(2.2), vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_B1.double2}");        assertEquals(new Double(2.2), vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_B2.name}");        assertEquals(B.NAME, vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_B2.int}");        assertEquals(new Integer(-1), vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_B2.double}");        assertEquals(new Double(-1.1), vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_B2.integer}");        assertEquals(new Integer(-2), vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_B2.double2}");        assertEquals(new Double(-2.2), vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_E.a}");        assertEquals("foo", vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_E.b}");        assertEquals("bar", vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_E.a}#{testBean_E.b}");        assertEquals("foobar", vb.getValue(_facesContext));        vb = _application.createValueBinding("#{testBean_E.c['foo']}");        assertEquals("bar", vb.getValue(_facesContext));        vb = _application.createValueBinding("#{!empty testBean_E.d}");        assertFalse("false", Boolean.getBoolean(vb.getValue(_facesContext)            .toString()));    }    public void testEL() throws Exception    {        ValueBinding vb;        vb = _application            .createValueBinding("#{facesContext.application.defaultRenderKitId}");        assertEquals("HTML_BASIC", vb.getValue(_facesContext));        //vb = _application.createValueBinding("#{facesContext.viewRoot.renderKitId}");        //assertEquals("HTML_BASIC", vb.getValue(_facesContext));        //vb = _application.createValueBinding("#{facesContext.viewRoot.viewId}");        //assertNotNull(vb.getValue(_facesContext));    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?