View Javadoc

1   /*
2    * $Id: ComponentTest.java 471756 2006-11-06 15:01:43Z husted $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.struts2.views.jsp.ui;
22  
23  import org.apache.struts2.TestAction;
24  import org.apache.struts2.views.jsp.AbstractUITagTest;
25  
26  
27  /***
28   */
29  public class ComponentTest extends AbstractUITagTest {
30  
31      /***
32       * Test that id attribute is evaludated against the Ognl Stack.
33       * @throws Exception
34       */
35      public void testIdIsEvaluatedAgainstStack1() throws Exception {
36          TestAction testAction = (TestAction) action;
37          testAction.setFoo("myFooValue");
38  
39          TextFieldTag tag = new TextFieldTag();
40          tag.setPageContext(pageContext);
41          tag.setLabel("mylabel");
42          tag.setName("myname");
43          tag.setValue("foo");
44          tag.setId("%{foo}");
45  
46          tag.doStartTag();
47          tag.doEndTag();
48  
49          verify(ComponentTag.class.getResource("Component-2.txt"));
50      }
51  
52      public void testIdIsEvaludatedAgainstStack2() throws Exception {
53          TestAction testAction = (TestAction) action;
54          testAction.setFoo("myFooValue");
55  
56          TextFieldTag tag = new TextFieldTag();
57          tag.setPageContext(pageContext);
58          tag.setLabel("mylabel");
59          tag.setName("myname");
60          tag.setValue("foo");
61          tag.setId("foo");
62  
63          tag.doStartTag();
64          tag.doEndTag();
65  
66          verify(ComponentTag.class.getResource("Component-3.txt"));
67      }
68  
69  
70      /***
71       * Note -- this test uses empty.vm, so it's basically clear
72       */
73      public void testSimple() throws Exception {
74          TestAction testAction = (TestAction) action;
75          testAction.setFoo("bar");
76  
77          ComponentTag tag = new ComponentTag();
78          tag.setPageContext(pageContext);
79          tag.setLabel("mylabel");
80          tag.setName("myname");
81          tag.setValue("foo");
82  
83          tag.doStartTag();
84          tag.doEndTag();
85  
86          verify(ComponentTag.class.getResource("Component-1.txt"));
87      }
88  
89      /***
90       * executes a component test passing in a custom parameter. it also executes calling a custom template using an
91       * absolute reference.
92       */
93      public void testWithParam() throws Exception {
94          TestAction testAction = (TestAction) action;
95          testAction.setFoo("bar");
96  
97          ComponentTag tag = new ComponentTag();
98          tag.setPageContext(pageContext);
99          tag.setLabel("mylabel");
100         tag.setName("myname");
101         tag.setValue("foo");
102         tag.setTheme("test");
103         tag.setTemplate("Component");
104 
105         tag.doStartTag();
106         tag.getComponent().addParameter("hello", "world");
107         tag.getComponent().addParameter("argle", "bargle");
108         tag.getComponent().addParameter("glip", "glop");
109         tag.getComponent().addParameter("array", new String[]{"a", "b", "c"});
110         tag.getComponent().addParameter("obj", tag);
111         tag.doEndTag();
112 
113         //        System.out.println(writer);
114         verify(ComponentTag.class.getResource("Component-param.txt"));
115     }
116 }