View Javadoc

1   /*
2    * $Id: FileTest.java 439747 2006-09-03 09:22:46Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.views.jsp.ui;
19  
20  import java.util.Map;
21  
22  import org.apache.struts2.TestAction;
23  import org.apache.struts2.views.jsp.AbstractUITagTest;
24  
25  
26  /***
27   */
28  public class FileTest extends AbstractUITagTest {
29  
30      public FileTest() {
31      }
32  
33  
34      public void testSimple() throws Exception {
35          TestAction testAction = (TestAction) action;
36          testAction.setFoo("bar");
37  
38          FileTag tag = new FileTag();
39          tag.setPageContext(pageContext);
40          tag.setLabel("mylabel");
41          tag.setName("myname");
42          tag.setAccept("*.txt");
43          tag.setValue("%{foo}");
44          tag.setSize("10");
45          tag.setTitle("mytitle");
46  
47          tag.doStartTag();
48          tag.doEndTag();
49  
50          verify(TextFieldTag.class.getResource("File-1.txt"));
51      }
52  
53      /***
54       * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
55       * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
56       * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
57       *
58       * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
59       *         as key.
60       */
61      protected Map initializedGenericTagTestProperties() {
62          Map result = super.initializedGenericTagTestProperties();
63          new PropertyHolder("accept", "someAccepted").addToMap(result);
64          new PropertyHolder("size", "101").addToMap(result);
65          return result;
66      }
67  
68      public void testGenericSimple() throws Exception {
69          FileTag tag = new FileTag();
70          verifyGenericProperties(tag, "simple", null);
71      }
72  
73      public void testGenericXhtml() throws Exception {
74          FileTag tag = new FileTag();
75          verifyGenericProperties(tag, "xhtml", null);
76      }
77  
78      public void testGenericAjax() throws Exception {
79          FileTag tag = new FileTag();
80          verifyGenericProperties(tag, "ajax", null);
81      }
82  
83  }