PageRenderTime 17ms CodeModel.GetById 2ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 1ms

/gwtrpccommlayer/src/test/java/com/googlecode/gwtrpccommlayer/client/impl/GwtRpcServiceImplTest.java

https://code.google.com/p/gwtrpccommlayer/
Java | 121 lines | 87 code | 23 blank | 11 comment | 0 complexity | c8482ed355573401f77c8ff713e7b6d4 MD5 | raw file
  1package com.googlecode.gwtrpccommlayer.client.impl;
  2
  3import com.google.gwt.user.client.rpc.AsyncCallback;
  4import com.google.inject.Guice;
  5import com.google.inject.Injector;
  6import com.google.inject.internal.Preconditions;
  7import com.google.inject.servlet.GuiceFilter;
  8import com.google.inject.servlet.GuiceServletContextListener;
  9import com.google.inject.servlet.ServletModule;
 10import com.googlecode.gwtrpccommlayer.client.GwtRpcService;
 11import com.googlecode.gwtrpccommlayer.client.Module;
 12import junit.framework.Assert;
 13import org.apache.http.cookie.Cookie;
 14import org.eclipse.jetty.server.Server;
 15import org.eclipse.jetty.servlet.DefaultServlet;
 16import org.eclipse.jetty.servlet.ServletContextHandler;
 17import org.junit.Before;
 18import org.junit.Test;
 19
 20import java.net.URL;
 21import java.util.List;
 22import java.util.Set;
 23import java.util.TreeSet;
 24
 25import static org.mockito.Mockito.mock;
 26
 27/**
 28 * Created by IntelliJ IDEA.
 29 * User: dan
 30 * Date: 11/3/10
 31 * Time: 2:32 PM
 32 */
 33public class GwtRpcServiceImplTest {
 34    Injector injector;
 35    private int PORT = 9099;
 36
 37
 38    @Before
 39    public void setUp() throws Exception {
 40        injector = Guice.createInjector(new Module());
 41
 42    }
 43
 44
 45    @Test
 46    public void integration() throws Exception {
 47               Server server = new Server(PORT);
 48        ServletContextHandler handler = new ServletContextHandler(
 49                server,
 50                "/",
 51                ServletContextHandler.SESSIONS);
 52        handler.addServlet(DefaultServlet.class, "/");
 53        handler.addFilter(GuiceFilter.class, "/*", null);
 54        handler.addEventListener(new GuiceServletContextListener() {
 55            @Override
 56            protected Injector getInjector() {
 57                return Guice.createInjector(new ServletModule() {
 58                    @Override
 59                    protected void configureServlets() {
 60                        //need some kind of servlet to report a success
 61                        serve("/*").with(SomeServlet.class);
 62                    }
 63                });
 64            }
 65        });
 66        server.setHandler(handler);
 67        server.start();
 68
 69        GwtRpcService service = injector.getInstance(GwtRpcService.class);
 70        //Create our proxy-based service using GwtRpcService
 71        TestService testService = service.create(new URL("http://localhost:" + PORT), TestService.class);
 72
 73        //Run Synchronous Tests
 74        testService.easy();
 75        try { testService.multipleArgs(null, null); Assert.fail(); } catch(Exception e) { }
 76        String test = "test";
 77        Assert.assertEquals(test, testService.echoSimple(test));
 78
 79        Set<String> set = new TreeSet<String>();
 80        set.add("test");
 81
 82        Assert.assertEquals(set, testService.echoGeneric(set));
 83
 84        //Run Asynchronous Tests
 85        TestServiceAsync serviceAsync = service.create(new URL("http://localhost:" + PORT), TestServiceAsync.class);
 86        serviceAsync.easy(new AsyncCallback<Void>() {
 87            @Override
 88            public void onFailure(Throwable throwable) {
 89                Assert.assertNotNull(throwable);
 90            }
 91
 92            @Override
 93            public void onSuccess(Void aVoid) {
 94                Assert.assertNotNull(aVoid);
 95            }
 96        });
 97
 98        server.stop();
 99    }
100
101    @Test
102    public void testCreate() throws Exception {
103        GwtRpcService service = new GwtRpcServiceImpl();
104
105        URL mockUrl = new URL("http://google.com");
106        TestService testService =service.create(mockUrl, TestService.class);
107        Preconditions.checkNotNull(testService);
108
109        List<Cookie> lstCookies = mock(List.class);
110        testService =service.create(mockUrl, TestService.class, lstCookies);
111        Preconditions.checkNotNull(testService);
112    }
113
114    @Test
115    public void testCreateUsingGuiceOrFactoryMethod() {
116        //GwtRpcService serviceByFactory = GwtRpcService.F
117
118    }
119
120
121}