import java.io.ByteArrayInputStream;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import com.meterware.httpunit.PostMethodWebRequest;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import com.meterware.servletunit.ServletRunner;
import com.meterware.servletunit.ServletUnitClient;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import com.meterware.servletunit.ServletRunner;
import com.meterware.servletunit.ServletUnitClient;
public class HttpUnitTestLoginServlet extends TestCase {
@Before
public void setUp() throws Exception {
super.setUp();
}
public void setUp() throws Exception {
super.setUp();
}
@After
public void tearDown() throws Exception {
super.tearDown();
}
public void tearDown() throws Exception {
super.tearDown();
}
@Test
public void testDoPostHttpServletRequestHttpServletResponse() {
try {
public void testDoPostHttpServletRequestHttpServletResponse() {
try {
// 创建Servlet的运行环境
ServletRunner sr = new ServletRunner();
// 向环境中注册Servlet
sr.registerServlet("LoginServlet", LoginServlet.class.getName());
// 创建访问Servlet的客户端
ServletUnitClient sc = sr.newClient();
// 测试数据
String str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>sa";
ByteArrayInputStream stream = new ByteArrayInputStream(str
.getBytes());
WebRequest request = new PostMethodWebRequest(
" http://localhost/LoginServlet", stream, "text/xml");
// 测试数据
String str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>sa";
ByteArrayInputStream stream = new ByteArrayInputStream(str
.getBytes());
WebRequest request = new PostMethodWebRequest(
" http://localhost/LoginServlet", stream, "text/xml");
// 发送请求
WebResponse response = sc.getResponse(request);
WebResponse response = sc.getResponse(request);
// 判断结果。"testuser:Hello World!"改成自己的期待结果就可以了啊。
Assert.assertTrue(response.getText()
.equals("testuser:Hello World!"));
Assert.assertTrue(response.getText()
.equals("testuser:Hello World!"));
} catch (Exception e) {
e.printStackTrace();
fail("まだ実装されていません");
fail("まだ実装されていません");
}
}
}
}