001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.views.jsp.ui;
006:
007: import com.opensymphony.webwork.views.jsp.ui.ComponentTag;
008: import com.opensymphony.webwork.views.jsp.ui.TextFieldTag;
009:
010: import com.opensymphony.webwork.TestAction;
011: import com.opensymphony.webwork.views.jsp.AbstractUITagTest;
012:
013: /**
014: * @author Matt Ho <a href="mailto:matt@enginegreen.com"><matt@enginegreen.com></a>
015: * @author tm_jee
016: * @version $Id: ComponentTest.java 2638 2006-07-08 06:06:02Z tmjee $
017: */
018: public class ComponentTest extends AbstractUITagTest {
019:
020: /**
021: * Test that id attribute is evaludated against the Ognl Stack.
022: * @throws Exception
023: */
024: public void testIdIsEvaluatedAgainstStack1() throws Exception {
025: TestAction testAction = (TestAction) action;
026: testAction.setFoo("myFooValue");
027:
028: TextFieldTag tag = new TextFieldTag();
029: tag.setPageContext(pageContext);
030: tag.setLabel("mylabel");
031: tag.setName("myname");
032: tag.setValue("foo");
033: tag.setId("%{foo}");
034:
035: tag.doStartTag();
036: tag.doEndTag();
037:
038: verify(ComponentTag.class.getResource("Component-2.txt"));
039: }
040:
041: public void testIdIsEvaludatedAgainstStack2() throws Exception {
042: TestAction testAction = (TestAction) action;
043: testAction.setFoo("myFooValue");
044:
045: TextFieldTag tag = new TextFieldTag();
046: tag.setPageContext(pageContext);
047: tag.setLabel("mylabel");
048: tag.setName("myname");
049: tag.setValue("foo");
050: tag.setId("foo");
051:
052: tag.doStartTag();
053: tag.doEndTag();
054:
055: verify(ComponentTag.class.getResource("Component-3.txt"));
056: }
057:
058: /**
059: * Note -- this test uses empty.ftl, so it's basically clear
060: */
061: public void testSimple() throws Exception {
062: TestAction testAction = (TestAction) action;
063: testAction.setFoo("bar");
064:
065: ComponentTag tag = new ComponentTag();
066: tag.setPageContext(pageContext);
067: tag.setLabel("mylabel");
068: tag.setName("myname");
069: tag.setValue("foo");
070:
071: tag.doStartTag();
072: tag.doEndTag();
073:
074: verify(ComponentTag.class.getResource("Component-1.txt"));
075: }
076:
077: /**
078: * executes a component test passing in a custom parameter. it also executes calling a custom template using an
079: * absolute reference.
080: */
081: public void testWithParam() throws Exception {
082: TestAction testAction = (TestAction) action;
083: testAction.setFoo("bar");
084:
085: ComponentTag tag = new ComponentTag();
086: tag.setPageContext(pageContext);
087: tag.setLabel("mylabel");
088: tag.setName("myname");
089: tag.setValue("foo");
090: tag.setTheme("test");
091: tag.setTemplate("Component");
092:
093: tag.doStartTag();
094: tag.getComponent().addParameter("hello", "world");
095: tag.getComponent().addParameter("argle", "bargle");
096: tag.getComponent().addParameter("glip", "glop");
097: tag.getComponent().addParameter("array",
098: new String[] { "a", "b", "c" });
099: tag.getComponent().addParameter("obj", tag);
100: tag.doEndTag();
101:
102: // System.out.println(writer);
103: verify(ComponentTag.class.getResource("Component-param.txt"));
104: }
105: }
|