View Javadoc

1   /*
2    * $Id: FileTest.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 java.util.Map;
24  
25  import org.apache.struts2.TestAction;
26  import org.apache.struts2.views.jsp.AbstractUITagTest;
27  
28  
29  /***
30   */
31  public class FileTest extends AbstractUITagTest {
32  
33      public FileTest() {
34      }
35  
36  
37      public void testSimple() throws Exception {
38          TestAction testAction = (TestAction) action;
39          testAction.setFoo("bar");
40  
41          FileTag tag = new FileTag();
42          tag.setPageContext(pageContext);
43          tag.setLabel("mylabel");
44          tag.setName("myname");
45          tag.setAccept("*.txt");
46          tag.setValue("%{foo}");
47          tag.setSize("10");
48          tag.setTitle("mytitle");
49  
50          tag.doStartTag();
51          tag.doEndTag();
52  
53          verify(TextFieldTag.class.getResource("File-1.txt"));
54      }
55  
56      /***
57       * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
58       * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
59       * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
60       *
61       * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
62       *         as key.
63       */
64      protected Map initializedGenericTagTestProperties() {
65          Map result = super.initializedGenericTagTestProperties();
66          new PropertyHolder("accept", "someAccepted").addToMap(result);
67          new PropertyHolder("size", "101").addToMap(result);
68          return result;
69      }
70  
71      public void testGenericSimple() throws Exception {
72          FileTag tag = new FileTag();
73          verifyGenericProperties(tag, "simple", null);
74      }
75  
76      public void testGenericXhtml() throws Exception {
77          FileTag tag = new FileTag();
78          verifyGenericProperties(tag, "xhtml", null);
79      }
80  
81      public void testGenericAjax() throws Exception {
82          FileTag tag = new FileTag();
83          verifyGenericProperties(tag, "ajax", null);
84      }
85  
86  }