?? servlettestbase.java
字號(hào):
package org.rapla;
import java.io.File;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import junit.framework.TestCase;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
import org.rapla.components.util.IOUtil;
import org.rapla.framework.RaplaContext;
import org.rapla.framework.RaplaLocale;
public abstract class ServletTestBase extends TestCase
{
MainServlet mainServlet = new MainServlet();
Server jettyServer;
final public static String WEBAPP_FOLDER_NAME = RaplaTestCase.TEST_FOLDER_NAME + "/webapp";
final public static String WEBAPP_INF_FOLDER_NAME = WEBAPP_FOLDER_NAME + "/WEB-INF";
public ServletTestBase( String name )
{
super( name );
new File("temp").mkdir();
File testFolder =new File(RaplaTestCase.TEST_FOLDER_NAME);
testFolder.mkdir();
}
protected void setUp() throws Exception
{
super.setUp();
mainServlet.setServerId( getStorageName() );
new File(WEBAPP_FOLDER_NAME).mkdir();
new File(WEBAPP_INF_FOLDER_NAME).mkdir();
IOUtil.copy( "test-src/test.xconf", WEBAPP_INF_FOLDER_NAME + "/raplaserver.xconf" );
IOUtil.copy( "test-src/test.xlog", WEBAPP_INF_FOLDER_NAME + "/raplaserver.xlog" );
IOUtil.copy( "test-src/testdefault.xml", WEBAPP_INF_FOLDER_NAME + "/test.xml" );
IOUtil.copy( "webapp/WEB-INF/web.xml", WEBAPP_INF_FOLDER_NAME + "/web.xml" );
jettyServer =new Server(8051);
jettyServer.setAttribute( "org.mortbay.jetty.Request.maxFormContentSize",new Integer(64000000) );
Context context = new Context( jettyServer,"/",Context.SESSIONS );
context.setResourceBase( WEBAPP_FOLDER_NAME );
context.addServlet( new ServletHolder(mainServlet), "/*" );
jettyServer.start();
URL server = new URL("http://127.0.0.1:8051/rapla/ping");
HttpURLConnection connection = (HttpURLConnection)server.openConnection();
int timeout = 10000;
int interval = 200;
for ( int i=0;i<timeout / interval;i++)
{
try
{
connection.connect();
}
catch (ConnectException ex) {
Thread.sleep(interval);
}
}
}
protected RaplaContext getContext()
{
return mainServlet.getContext();
}
protected RaplaLocale getRaplaLocale() throws Exception {
return (RaplaLocale) getContext().lookup(RaplaLocale.ROLE);
}
protected void tearDown() throws Exception
{
jettyServer.stop();
super.tearDown();
}
protected String getStorageName() {
return "storage-file";
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -