package net.sf.jruby.rails.asyncweb.service;
import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.Map;
import org.safehaus.asyncweb.http.ResponseStatus;
import junit.framework.TestCase;
import net.sf.jruby.rails.asyncweb.config.RailsConfig;
import net.sf.jruby.rails.asyncweb.mock.MockHttpRequest;
import net.sf.jruby.rails.asyncweb.mock.MockHttpResponse;
public class RailsFileServiceTest extends TestCase {
private RailsFileService service = null;
public void testHandleRequest() throws Exception {
MockHttpRequest request = new MockHttpRequest();
request.setRequestURI("/robots.txt");
MockHttpResponse response = new MockHttpResponse();
response.setOutputStream(new ByteArrayOutputStream());
request.setHttpResponse(response);
service.handleRequest(request);
assertEquals("text/plain", response.getContentType());
assertEquals(ResponseStatus.OK, response.getStatus());
assertEquals("# robots.txt", response.getOutputAsText());
}
public void testHandleRequestNot() throws Exception {
MockHttpRequest request = new MockHttpRequest();
request.setRequestURI("/robots.txt");
request.setHeader("If-Modified-Since", "Wed, 01 Jan 3000 00:00:00 GMT");
MockHttpResponse response = new MockHttpResponse();
response.setOutputStream(new ByteArrayOutputStream());
request.setHttpResponse(response);
service.handleRequest(request);
assertEquals(ResponseStatus.NOT_MODIFIED, response.getStatus());
assertEquals("", response.getOutputAsText());
}
@Override
protected void setUp() throws Exception {
Map<String, String> types = new HashMap<String, String>();
types.put("txt", "text/plain");
RailsConfig config = new RailsConfig();
config.setRailsRoot("src/test/rails");
service = new RailsFileService();
service.setRailsConfig(config);
service.start();
}
}