001: /*
002: * $Id: ComponentTest.java 471756 2006-11-06 15:01:43Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.jsp.ui;
022:
023: import org.apache.struts2.TestAction;
024: import org.apache.struts2.views.jsp.AbstractUITagTest;
025:
026: /**
027: */
028: public class ComponentTest extends AbstractUITagTest {
029:
030: /**
031: * Test that id attribute is evaludated against the Ognl Stack.
032: * @throws Exception
033: */
034: public void testIdIsEvaluatedAgainstStack1() throws Exception {
035: TestAction testAction = (TestAction) action;
036: testAction.setFoo("myFooValue");
037:
038: TextFieldTag tag = new TextFieldTag();
039: tag.setPageContext(pageContext);
040: tag.setLabel("mylabel");
041: tag.setName("myname");
042: tag.setValue("foo");
043: tag.setId("%{foo}");
044:
045: tag.doStartTag();
046: tag.doEndTag();
047:
048: verify(ComponentTag.class.getResource("Component-2.txt"));
049: }
050:
051: public void testIdIsEvaludatedAgainstStack2() throws Exception {
052: TestAction testAction = (TestAction) action;
053: testAction.setFoo("myFooValue");
054:
055: TextFieldTag tag = new TextFieldTag();
056: tag.setPageContext(pageContext);
057: tag.setLabel("mylabel");
058: tag.setName("myname");
059: tag.setValue("foo");
060: tag.setId("foo");
061:
062: tag.doStartTag();
063: tag.doEndTag();
064:
065: verify(ComponentTag.class.getResource("Component-3.txt"));
066: }
067:
068: /**
069: * Note -- this test uses empty.vm, so it's basically clear
070: */
071: public void testSimple() throws Exception {
072: TestAction testAction = (TestAction) action;
073: testAction.setFoo("bar");
074:
075: ComponentTag tag = new ComponentTag();
076: tag.setPageContext(pageContext);
077: tag.setLabel("mylabel");
078: tag.setName("myname");
079: tag.setValue("foo");
080:
081: tag.doStartTag();
082: tag.doEndTag();
083:
084: verify(ComponentTag.class.getResource("Component-1.txt"));
085: }
086:
087: /**
088: * executes a component test passing in a custom parameter. it also executes calling a custom template using an
089: * absolute reference.
090: */
091: public void testWithParam() throws Exception {
092: TestAction testAction = (TestAction) action;
093: testAction.setFoo("bar");
094:
095: ComponentTag tag = new ComponentTag();
096: tag.setPageContext(pageContext);
097: tag.setLabel("mylabel");
098: tag.setName("myname");
099: tag.setValue("foo");
100: tag.setTheme("test");
101: tag.setTemplate("Component");
102:
103: tag.doStartTag();
104: tag.getComponent().addParameter("hello", "world");
105: tag.getComponent().addParameter("argle", "bargle");
106: tag.getComponent().addParameter("glip", "glop");
107: tag.getComponent().addParameter("array",
108: new String[] { "a", "b", "c" });
109: tag.getComponent().addParameter("obj", tag);
110: tag.doEndTag();
111:
112: // System.out.println(writer);
113: verify(ComponentTag.class.getResource("Component-param.txt"));
114: }
115: }
|