1 package org.displaytag.test; 2 3 import java.io.File ; 4 import java.net.URL ; 5 import java.net.URLDecoder ; 6 7 import junit.framework.TestCase; 8 9 import org.apache.commons.lang.ArrayUtils; 10 import org.apache.commons.lang.StringUtils; 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 14 import com.meterware.servletunit.ServletRunner; 15 16 17 22 public abstract class DisplaytagCase extends TestCase 23 { 24 25 28 public static final String CONTEXT = "/context"; 29 30 33 protected final Log log = LogFactory.getLog(getClass()); 34 35 38 protected ServletRunner runner; 39 40 44 public abstract String getJspName(); 45 46 51 public abstract void doTest(String jspName) throws Exception ; 52 53 57 public void test11() throws Exception 58 { 59 doTest("http://localhost" + CONTEXT + "/standard/" + getJspName()); 60 } 61 62 66 public void testEL() throws Exception 67 { 68 doTest("http://localhost" + CONTEXT + "/el/" + getJspName()); 69 } 70 71 74 protected void setUp() throws Exception 75 { 76 ClassLoader classLoader = getClass().getClassLoader(); 78 URL webXmlUrl = classLoader.getResource("WEB-INF/web.xml"); 79 String path = URLDecoder.decode(webXmlUrl.getFile(), "UTF-8"); 80 81 runner = new ServletRunner(new File (path), CONTEXT); 83 log.debug("ServletRunner setup OK"); 84 85 super.setUp(); 86 } 87 88 91 protected void tearDown() throws Exception 92 { 93 runner.shutDown(); 95 96 super.tearDown(); 97 } 98 99 102 public String getName() 103 { 104 return getClass().getName() + "." + super.getName() + " (" + getJspName() + ")"; 105 } 106 107 113 public void assertEqualsIgnoreOrder(String message, String [] expected, String [] actual) 114 { 115 if (expected.length != actual.length) 116 { 117 fail(message 118 + " Wrong number of values, expected " 119 + expected.length 120 + " (" 121 + ArrayUtils.toString(expected) 122 + "), actual " 123 + actual.length 124 + " (" 125 + ArrayUtils.toString(actual) 126 + ")"); 127 } 128 129 outer : for (int j = 0; j < expected.length; j++) 130 { 131 String exp = expected[j]; 132 for (int q = 0; q < actual.length; q++) 133 { 134 if (StringUtils.equals(exp, actual[q])) 135 { 136 continue outer; 137 } 138 } 139 fail(message + " Expected value \"" + exp + "\" not found in actual array: " + ArrayUtils.toString(actual)); 140 } 141 } 142 } | Popular Tags |