?? testsizetag.java
字號:
/*
* $Id: TestSizeTag.java 54929 2004-10-16 16:38:42Z germuska $
*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.struts.taglib.bean;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.jsp.PageContext;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.cactus.WebResponse;
import org.apache.struts.taglib.SimpleBeanForTesting;
import org.apache.struts.taglib.TaglibTestBase;
/**
* Suite of unit tests for the
* <code>org.apache.struts.taglib.bean.SizeTag</code> class.
*
*/
public class TestSizeTag extends TaglibTestBase {
protected final static String TEST_VAL = "Test Value";
protected final static String REQUEST_KEY = "REQUEST_KEY";
private String [] strings = { TEST_VAL, TEST_VAL, TEST_VAL };
private Collection collection = new ArrayList();
private Map map = new HashMap();
/**
* Defines the testcase name for JUnit.
*
* @param theName the testcase's name.
*/
public TestSizeTag(String theName) {
super(theName);
}
/**
* Start the tests.
*
* @param theArgs the arguments. Not used
*/
public static void main(String[] theArgs) {
junit.awtui.TestRunner.main(new String[] {TestSizeTag.class.getName()});
}
/**
* @return a test suite (<code>TestSuite</code>) that includes all methods
* starting with "test"
*/
public static Test suite() {
// All methods starting with "test" will be executed in the test suite.
return new TestSuite(TestSizeTag.class);
}
public void setUp() {
for (int i = 0; i < 3; i++) {
collection.add(TEST_VAL + i);
}
for (int i = 0; i < 3; i++) {
map.put(REQUEST_KEY + i, TEST_VAL + i);
}
}
private void formatAndTest(String compare, String output) {
//fix for introduced carriage return / line feeds
output = replace(output,"\r","");
output = replace(output,"\n","");
output = output.trim();
//System.out.println("Testing [" + compare + "] == [" + output + "]");
assertEquals(compare, output);
}
// Array
public void testSizeTagNameArrayNoScope() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNameArrayNoScope");
request.setAttribute(REQUEST_KEY, strings);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNameArrayNoScope(WebResponse response){
formatAndTest("3", response.getText());
}
public void testSizeTagNameArrayApplicationScope() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNameArrayApplicationScope");
pageContext.setAttribute(REQUEST_KEY, strings, PageContext.APPLICATION_SCOPE);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNameArrayApplicationScope(WebResponse response){
formatAndTest("3", response.getText());
}
public void testSizeTagNameArraySessionScope() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNameArraySessionScope");
pageContext.setAttribute(REQUEST_KEY, strings, PageContext.SESSION_SCOPE);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNameArraySessionScope(WebResponse response){
formatAndTest("3", response.getText());
}
public void testSizeTagNameArrayRequestScope() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNameArrayRequestScope");
pageContext.setAttribute(REQUEST_KEY, strings, PageContext.REQUEST_SCOPE);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNameArrayRequestScope(WebResponse response){
formatAndTest("3", response.getText());
}
public void testSizeTagNamePropertyArrayNoScope() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNamePropertyArrayNoScope");
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
sbft.setArray(strings);
pageContext.setAttribute(REQUEST_KEY, sbft, PageContext.APPLICATION_SCOPE);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNamePropertyArrayNoScope(WebResponse response){
formatAndTest("3", response.getText());
}
public void testSizeTagNamePropertyArrayApplicationScope() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNamePropertyArrayApplicationScope");
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
sbft.setArray(strings);
pageContext.setAttribute(REQUEST_KEY, sbft, PageContext.APPLICATION_SCOPE);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNamePropertyArrayApplicationScope(WebResponse response){
formatAndTest("3", response.getText());
}
public void testSizeTagNamePropertyArraySessionScope() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNamePropertyArraySessionScope");
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
sbft.setArray(strings);
pageContext.setAttribute(REQUEST_KEY, sbft, PageContext.SESSION_SCOPE);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNamePropertyArraySessionScope(WebResponse response){
formatAndTest("3", response.getText());
}
public void testSizeTagNamePropertyArrayRequestScope() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNamePropertyArrayRequestScope");
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
sbft.setArray(strings);
pageContext.setAttribute(REQUEST_KEY, sbft, PageContext.REQUEST_SCOPE);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNamePropertyArrayRequestScope(WebResponse response){
formatAndTest("3", response.getText());
}
public void testSizeTagNamePropertyArrayNoScopeNested() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNamePropertyArrayNoScopeNested");
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
SimpleBeanForTesting sbft2 = new SimpleBeanForTesting();
sbft.setArray(strings);
sbft2.setNestedObject(sbft);
pageContext.setAttribute(REQUEST_KEY, sbft2, PageContext.APPLICATION_SCOPE);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNamePropertyArrayNoScopeNested(WebResponse response){
formatAndTest("3", response.getText());
}
public void testSizeTagNamePropertyArrayApplicationScopeNested() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNamePropertyArrayApplicationScopeNested");
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
SimpleBeanForTesting sbft2 = new SimpleBeanForTesting();
sbft.setArray(strings);
sbft2.setNestedObject(sbft);
pageContext.setAttribute(REQUEST_KEY, sbft2, PageContext.APPLICATION_SCOPE);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNamePropertyArrayApplicationScopeNested(WebResponse response){
formatAndTest("3", response.getText());
}
public void testSizeTagNamePropertyArraySessionScopeNested() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNamePropertyArraySessionScopeNested");
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
SimpleBeanForTesting sbft2 = new SimpleBeanForTesting();
sbft.setArray(strings);
sbft2.setNestedObject(sbft);
pageContext.setAttribute(REQUEST_KEY, sbft2, PageContext.SESSION_SCOPE);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNamePropertyArraySessionScopeNested(WebResponse response){
formatAndTest("3", response.getText());
}
public void testSizeTagNamePropertyArrayRequestScopeNested() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNamePropertyArrayRequestScopeNested");
SimpleBeanForTesting sbft = new SimpleBeanForTesting();
SimpleBeanForTesting sbft2 = new SimpleBeanForTesting();
sbft.setArray(strings);
sbft2.setNestedObject(sbft);
pageContext.setAttribute(REQUEST_KEY, sbft2, PageContext.REQUEST_SCOPE);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNamePropertyArrayRequestScopeNested(WebResponse response){
formatAndTest("3", response.getText());
}
// Collection
public void testSizeTagNameCollectionNoScope() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNameCollectionNoScope");
request.setAttribute(REQUEST_KEY, collection);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNameCollectionNoScope(WebResponse response){
formatAndTest("3", response.getText());
}
public void testSizeTagNameCollectionApplicationScope() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNameCollectionApplicationScope");
pageContext.setAttribute(REQUEST_KEY, collection, PageContext.APPLICATION_SCOPE);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
}
public void endSizeTagNameCollectionApplicationScope(WebResponse response){
formatAndTest("3", response.getText());
}
public void testSizeTagNameCollectionSessionScope() throws IOException, ServletException{
request.setAttribute("runTest", "testSizeTagNameCollectionSessionScope");
pageContext.setAttribute(REQUEST_KEY, collection, PageContext.SESSION_SCOPE);
pageContext.forward("/test/org/apache/struts/taglib/bean/TestSizeTag.jsp");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -