View Javadoc

1   /*
2    * $Id: ComponentTest.java 651946 2008-04-27 13:41:38Z apetrelli $
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  
22  package org.apache.struts2.views.jsp.ui;
23  
24  import org.apache.struts2.TestAction;
25  import org.apache.struts2.views.jsp.AbstractUITagTest;
26  
27  
28  /***
29   */
30  public class ComponentTest extends AbstractUITagTest {
31  
32      /***
33       * Test that id attribute is evaludated against the Ognl Stack.
34       * @throws Exception
35       */
36      public void testIdIsEvaluatedAgainstStack1() throws Exception {
37          TestAction testAction = (TestAction) action;
38          testAction.setFoo("myFooValue");
39  
40          TextFieldTag tag = new TextFieldTag();
41          tag.setPageContext(pageContext);
42          tag.setLabel("mylabel");
43          tag.setName("myname");
44          tag.setValue("foo");
45          tag.setId("%{foo}");
46  
47          tag.doStartTag();
48          tag.doEndTag();
49  
50          verify(ComponentTag.class.getResource("Component-2.txt"));
51      }
52  
53      public void testIdIsEvaludatedAgainstStack2() throws Exception {
54          TestAction testAction = (TestAction) action;
55          testAction.setFoo("myFooValue");
56  
57          TextFieldTag tag = new TextFieldTag();
58          tag.setPageContext(pageContext);
59          tag.setLabel("mylabel");
60          tag.setName("myname");
61          tag.setValue("foo");
62          tag.setId("foo");
63  
64          tag.doStartTag();
65          tag.doEndTag();
66  
67          verify(ComponentTag.class.getResource("Component-3.txt"));
68      }
69  
70  
71      /***
72       * Note -- this test uses empty.vm, so it's basically clear
73       */
74      public void testSimple() throws Exception {
75          TestAction testAction = (TestAction) action;
76          testAction.setFoo("bar");
77  
78          ComponentTag tag = new ComponentTag();
79          tag.setPageContext(pageContext);
80          tag.setLabel("mylabel");
81          tag.setName("myname");
82          tag.setValue("foo");
83  
84          tag.doStartTag();
85          tag.doEndTag();
86  
87          verify(ComponentTag.class.getResource("Component-1.txt"));
88      }
89  
90      /***
91       * executes a component test passing in a custom parameter. it also executes calling a custom template using an
92       * absolute reference.
93       */
94      public void testWithParam() throws Exception {
95          TestAction testAction = (TestAction) action;
96          testAction.setFoo("bar");
97  
98          ComponentTag tag = new ComponentTag();
99          tag.setPageContext(pageContext);
100         tag.setLabel("mylabel");
101         tag.setName("myname");
102         tag.setValue("foo");
103         tag.setTheme("test");
104         tag.setTemplate("Component");
105 
106         tag.doStartTag();
107         tag.getComponent().addParameter("hello", "world");
108         tag.getComponent().addParameter("argle", "bargle");
109         tag.getComponent().addParameter("glip", "glop");
110         tag.getComponent().addParameter("array", new String[]{"a", "b", "c"});
111         tag.getComponent().addParameter("obj", tag);
112         tag.doEndTag();
113 
114         //        System.out.println(writer);
115         verify(ComponentTag.class.getResource("Component-param.txt"));
116     }
117 }