PageRenderTime 30ms CodeModel.GetById 20ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/gwtp-extension/src/test/java/com/googlecode/gwtrpccommlayer/gwtp/server/DispatchingPOJOServletTest.java

https://code.google.com/p/gwtrpccommlayer/
Java | 78 lines | 58 code | 12 blank | 8 comment | 0 complexity | 2848e0b81c41eb36f46cb1608a4faed4 MD5 | raw file
 1package com.googlecode.gwtrpccommlayer.gwtp.server;
 2
 3import com.google.gwt.user.client.rpc.AsyncCallback;
 4import com.google.inject.Guice;
 5import com.google.inject.Injector;
 6import com.google.inject.servlet.GuiceFilter;
 7import com.google.inject.servlet.GuiceServletContextListener;
 8import com.googlecode.gwtrpccommlayer.client.GwtRpcService;
 9import com.googlecode.gwtrpccommlayer.gwtp.test.TAction;
10import com.googlecode.gwtrpccommlayer.gwtp.test.THandlerModule;
11import com.gwtplatform.dispatch.client.DispatchServiceAsync;
12import com.gwtplatform.dispatch.shared.ActionImpl;
13import com.gwtplatform.dispatch.shared.Result;
14import org.eclipse.jetty.server.Server;
15import org.eclipse.jetty.servlet.DefaultServlet;
16import org.eclipse.jetty.servlet.ServletContextHandler;
17import org.junit.Assert;
18import org.junit.Test;
19
20import java.net.URL;
21
22/**
23 * Created by IntelliJ IDEA.
24 * User: dan
25 * Date: 11/16/10
26 * Time: 10:04 PM
27 */
28public class DispatchingPOJOServletTest {
29    private Integer PORT = 49222;
30
31    @Test
32    public void test() throws Exception {
33                Injector injector = Guice.createInjector(new com.googlecode.gwtrpccommlayer.client.Module());
34        Server server = new Server(PORT);
35        ServletContextHandler handler = new ServletContextHandler(
36                server,
37                "/",
38                ServletContextHandler.SESSIONS);
39        handler.addServlet(DefaultServlet.class, "/");
40        //FilterHolder filterHolder = new FilterHolder(GuiceFilter.class);
41        handler.addFilter(GuiceFilter.class, "/*", 0);
42        handler.addEventListener(new GuiceServletContextListener() {
43            @Override
44            protected Injector getInjector() {
45                return Guice.createInjector( new THandlerModule(),
46                        new com.googlecode.gwtrpccommlayer.gwtp.server.Module());
47
48            }
49        });
50
51        server.setHandler(handler);
52        server.start();
53
54        GwtRpcService service = injector.getInstance(GwtRpcService.class);
55        //Create our proxy-based service using GwtRpcService
56        DispatchServiceAsync testService = service.create(
57                new URL(
58                        "http://localhost:" + PORT + "/" +
59                                ActionImpl.DEFAULT_SERVICE_NAME),
60                DispatchServiceAsync.class);
61
62        testService.execute("", new TAction(), new AsyncCallback<Result>() {
63            @Override
64            public void onFailure(Throwable caught) {
65                Assert.fail(caught.getMessage());
66            }
67
68            @Override
69            public void onSuccess(Result result) {
70                Assert.assertNotNull(result);
71            }
72        });
73
74
75
76        server.stop();
77    }
78}