01: /*
02: * $Id: TokenTagTest.java 471756 2006-11-06 15:01:43Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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 javax.servlet.jsp.JspException;
24:
25: import org.apache.struts2.util.TokenHelper;
26: import org.apache.struts2.views.jsp.AbstractUITagTest;
27:
28: /**
29: * TokenTagTest
30: *
31: */
32: public class TokenTagTest extends AbstractUITagTest {
33:
34: public void testDefaultName() {
35: String tokenName = TokenHelper.DEFAULT_TOKEN_NAME;
36: TokenTag tag = new TokenTag();
37: doTokenTest(tokenName, tag);
38: }
39:
40: public void testMultipleTagsWithSameName() {
41: String tokenName = "sameName";
42: TokenTag tag = new TokenTag();
43: tag.setName(tokenName);
44:
45: String token = doTokenTest(tokenName, tag);
46:
47: TokenTag anotherTag = new TokenTag();
48: anotherTag.setName(tokenName);
49:
50: String anotherToken = doTokenTest(tokenName, anotherTag);
51: assertEquals(token, anotherToken);
52: }
53:
54: /**
55: * WW-480
56: */
57: public void testNotFindableName() {
58: String tokenName = "foo";
59: TokenTag tag = new TokenTag();
60: tag.setName(tokenName);
61: doTokenTest(tokenName, tag);
62:
63: String s = writer.toString();
64: assertTrue(s
65: .indexOf("name=\"" + TokenHelper.DEFAULT_TOKEN_NAME) > -1);
66: assertTrue(s.indexOf("value=\"" + tokenName + "\"") > -1);
67: assertTrue(s.indexOf("name=\"" + tokenName + "\"") > -1);
68:
69: //System.out.println(s);
70: }
71:
72: public void testSuppliedName() {
73: String tokenName = "my.very.long.token.name";
74: TokenTag tag = new TokenTag();
75: tag.setName(tokenName);
76: doTokenTest(tokenName, tag);
77: }
78:
79: private String doTokenTest(String tokenName, TokenTag tag) {
80: tag.setPageContext(pageContext);
81:
82: String token = null;
83:
84: try {
85: tag.doStartTag();
86: tag.doEndTag();
87:
88: token = (String) context.get(tokenName);
89: assertNotNull(token);
90: assertEquals(token, pageContext.getSession().getAttribute(
91: tokenName));
92: } catch (JspException e) {
93: e.printStackTrace();
94: fail();
95: }
96:
97: return token;
98: }
99: }
|