package net.sf.jruby.rails.functional;
import junit.framework.TestCase;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.HttpInternalErrorException;
import com.meterware.httpunit.PostMethodWebRequest;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
public class FunctionalTestStandAlone extends TestCase {
private String baseUrl;
public void testHttpGet() throws Exception {
WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest(baseUrl + "/get");
WebResponse response = conversation.getResponse(request);
assertEquals(200, response.getResponseCode());
assertEquals("Hello, World.", response.getText());
}
public void testHttpGetWithParameter() throws Exception {
WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest(baseUrl + "/get_with_parameter");
request.setParameter("name", "World");
WebResponse response = conversation.getResponse(request);
assertEquals(200, response.getResponseCode());
assertEquals("Hello, World.", response.getText());
}
public void testHttpPostWithParameter() throws Exception {
WebConversation conversation = new WebConversation();
WebRequest request = new PostMethodWebRequest(baseUrl + "/post_with_parameter");
request.setParameter("name", "World");
WebResponse response = conversation.getResponse(request);
assertEquals(200, response.getResponseCode());
assertEquals("Hello, World.", response.getText());
}
public void testInternalServerError() throws Exception {
try {
WebConversation conversation = new WebConversation();
WebRequest request = new PostMethodWebRequest(baseUrl + "/internal_server_error");
conversation.getResponse(request);
fail();
} catch (HttpInternalErrorException e) {
}
}
public void testRedirect() throws Exception {
WebConversation conversation = new WebConversation();
conversation.getClientProperties().setAutoRedirect(false);
WebRequest request = new GetMethodWebRequest(baseUrl + "/redirect");
WebResponse response = conversation.getResponse(request);
assertEquals(302, response.getResponseCode());
assertEquals(baseUrl + "/get", response.getHeaderField("Location"));
}
@Override
protected void setUp() throws Exception {
baseUrl = "http://localhost:3000/functional_test";
}
}