PageRenderTime 764ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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