View Javadoc

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