Package net.sf.jruby.rails.asyncweb.service

Source Code of net.sf.jruby.rails.asyncweb.service.RailsDispatchServiceTest

package net.sf.jruby.rails.asyncweb.service;

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;

import org.jruby.RubyException;
import org.jruby.exceptions.RaiseException;

public class RailsDispatchServiceTest extends TestCase {

    private RailsDispatchService service = null;

    protected void setUp() throws Exception {
        try {
            RailsConfig config = new RailsConfig();

            config.setRailsRoot("src/test/rails");
            config.addLoadPath("src/main/ruby");

            service = new RailsDispatchService();
            service.setRailsConfig(config);

            service.start();

        } catch (RaiseException e) {
            printJRubyBacktrace(e);
        }
    }

    protected void tearDown() throws Exception {
        service.stop();
    }

    public void testRun() throws Exception {
        try {
            MockHttpRequest request = new MockHttpRequest();
            MockHttpResponse response = new MockHttpResponse();

            request.setHttpResponse(response);

            request.setParameterString("");
            request.setRequestURI("/functional_test/get");

            request.setHeader("Host", "localhost");
            request.setHeader("Accept", "text/html, text/plain, text/sgml, */*;q=0.01");
            request.setHeader("Accept-Encoding", "gzip, compress");
            request.setHeader("Accept-Language", "ja, en");

            service.handleRequest(request);

            assertEquals(200, response.getStatus().getCode());
            assertEquals("OK", response.getReason());
            assertEquals("text/html", response.getContentType());
            assertEquals("Hello, World.", response.getOutputAsText());

        } catch (RaiseException e) {
            printJRubyBacktrace(e);
        }
    }

    private void printJRubyBacktrace(RaiseException e) throws RaiseException {
        RubyException rubyexp = e.getException();
        System.err.println(rubyexp.message.toString());
        rubyexp.printBacktrace(System.err);

        throw e;
    }
}
TOP

Related Classes of net.sf.jruby.rails.asyncweb.service.RailsDispatchServiceTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.