View Javadoc

1   /*
2    * $Id: AnchorTagTest.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;
22  
23  import java.io.StringWriter;
24  
25  import javax.servlet.jsp.JspException;
26  import javax.servlet.jsp.JspWriter;
27  
28  import org.apache.struts2.views.jsp.ui.AnchorTag;
29  import org.apache.struts2.views.jsp.ui.StrutsBodyContent;
30  
31  
32  /***
33   *
34   */
35  public class AnchorTagTest extends AbstractUITagTest {
36      private StringWriter writer = new StringWriter();
37      private AnchorTag tag;
38  
39      public void testActionURL() {
40          tag.setHref("TestAction.action");
41          try {
42              tag.doStartTag();
43              tag.doEndTag();
44              assertTrue( writer.toString().indexOf("href=\"TestAction.action\"") > -1);
45          } catch (JspException ex) {
46              ex.printStackTrace();
47              fail();
48          }
49      }
50  
51      public void testAddParameters() {
52          tag.setHref("/TestAction.action");
53          String bodyText = "<img src=\"#\"/>";
54          try {
55              StrutsBodyContent bodyContent = new StrutsBodyContent(null);
56              bodyContent.print(bodyText);
57              tag.setBodyContent(bodyContent);
58  
59              tag.doStartTag();
60              tag.doEndTag();
61          } catch (Exception ex) {
62              ex.printStackTrace();
63              fail();
64          }
65      }
66  
67  
68      protected void setUp() throws Exception {
69          super.setUp();
70  
71          request.setScheme("http");
72          request.setServerName("localhost");
73          request.setServerPort(80);
74  
75          tag = new AnchorTag();
76          tag.setPageContext(pageContext);
77          JspWriter jspWriter = new StrutsMockJspWriter(writer);
78          pageContext.setJspWriter(jspWriter);
79      }
80  
81  }