1 18 19 package org.apache.strutsel.taglib.bean; 20 21 import junit.framework.Test; 22 import junit.framework.TestSuite; 23 import javax.servlet.ServletException ; 24 import javax.servlet.jsp.JspException ; 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 theName) { 33 super(theName); 34 } 35 36 public static void main(String [] args) { 37 junit.awtui.TestRunner.main( 38 new String [] { 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 , JspException { 56 TestFormBean formBean = new TestFormBean(); 57 formBean.setArrayProperty(new String [] {"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 object = pageContext.getAttribute("sizeVar"); 67 if (object != null) { 68 if (object instanceof Integer ) { 69 if (((Integer ) 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 , JspException { 84 85 TestFormBean formBean = new TestFormBean(); 86 formBean.setArrayProperty(new String [] {"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 object = pageContext.getAttribute("sizeVar"); 97 if (object != null) { 98 if (object instanceof Integer ) { 99 if (((Integer ) 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 |