KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > strutsel > taglib > bean > TestELSizeTag


1 /*
2  * $Id: TestELSizeTag.java 54933 2004-10-16 17:04:52Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.strutsel.taglib.bean;
20
21 import junit.framework.Test;
22 import junit.framework.TestSuite;
23 import javax.servlet.ServletException JavaDoc;
24 import javax.servlet.jsp.JspException JavaDoc;
25 import org.apache.cactus.JspTestCase;
26 import org.apache.strutsel.taglib.utils.TestFormBean;
27
28 public class TestELSizeTag extends JspTestCase
29 {
30     protected ELSizeTag elSizeTag = null;
31
32     public TestELSizeTag(String JavaDoc theName) {
33         super(theName);
34     }
35
36     public static void main(String JavaDoc[] args) {
37         junit.awtui.TestRunner.main(
38                 new String JavaDoc[] { TestELSizeTag.class.getName() });
39     }
40
41     public static Test suite() {
42         return new TestSuite(TestELSizeTag.class);
43     }
44
45     public void setUp() {
46         elSizeTag = new ELSizeTag();
47         elSizeTag.setPageContext(pageContext);
48     }
49
50     public void tearDown() {
51         elSizeTag = null;
52     }
53
54     public void testPlain()
55         throws ServletException JavaDoc, JspException JavaDoc {
56         TestFormBean formBean = new TestFormBean();
57         formBean.setArrayProperty(new String JavaDoc[] {"abc", "def", "ghi"});
58         pageContext.setAttribute("testFormBean", formBean);
59
60         elSizeTag.setIdExpr("sizeVar");
61         elSizeTag.setNameExpr("testFormBean");
62         elSizeTag.setPropertyExpr("arrayProperty");
63
64         int startTagReturn = elSizeTag.doStartTag();
65
66         Object JavaDoc object = pageContext.getAttribute("sizeVar");
67         if (object != null) {
68             if (object instanceof Integer JavaDoc) {
69                 if (((Integer JavaDoc) object).intValue() != 3) {
70                     fail("Size variable \"sizeVar\" is not equal to 3.");
71                 }
72             }
73             else {
74                 fail("Size variable \"sizeVar\" is not an Integer object.");
75             }
76         }
77         else {
78             fail("Size variable \"sizeVar\" not in page context.");
79         }
80     }
81
82     public void testCollectionProperty()
83         throws ServletException JavaDoc, JspException JavaDoc {
84
85         TestFormBean formBean = new TestFormBean();
86         formBean.setArrayProperty(new String JavaDoc[] {"abc", "def", "ghi"});
87         pageContext.setAttribute("testFormBean", formBean);
88
89         elSizeTag.setIdExpr("sizeVar");
90         elSizeTag.setCollectionExpr("${" + "testFormBean.arrayProperty" + "}");
91
92         int startTagReturn = elSizeTag.doStartTag();
93
94         System.out.println("collection[" + elSizeTag.getCollection() + "]");
95
96         Object JavaDoc object = pageContext.getAttribute("sizeVar");
97         if (object != null) {
98             if (object instanceof Integer JavaDoc) {
99                 if (((Integer JavaDoc) object).intValue() != 3) {
100                     fail("Size variable \"sizeVar\" is not equal to 3.");
101                 }
102             }
103             else {
104                 fail("Size variable \"sizeVar\" is not an Integer object.");
105             }
106         }
107         else {
108             fail("Size variable \"sizeVar\" not in page context.");
109         }
110     }
111 }
112
Popular Tags