You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConnectorResourceHandlerTest.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package com.vaadin.server;
  2. import static org.junit.Assert.assertTrue;
  3. import java.io.IOException;
  4. import org.easymock.EasyMock;
  5. import org.easymock.IMocksControl;
  6. import org.junit.Before;
  7. import org.junit.Test;
  8. import com.vaadin.ui.Button;
  9. import com.vaadin.ui.UI;
  10. public class ConnectorResourceHandlerTest {
  11. VaadinRequest request;
  12. VaadinResponse response;
  13. VaadinSession session;
  14. UI ui;
  15. @Before
  16. public void setUp() {
  17. IMocksControl control = EasyMock.createNiceControl();
  18. request = control.createMock(VaadinRequest.class);
  19. response = control.createMock(VaadinResponse.class);
  20. DeploymentConfiguration dc = control
  21. .createMock(DeploymentConfiguration.class);
  22. VaadinService service = control.createMock(VaadinService.class);
  23. EasyMock.expect(request.getPathInfo())
  24. .andReturn("/APP/connector/0/1/2");
  25. EasyMock.expect(request.getParameter("v-loc"))
  26. .andReturn("http://localhost/");
  27. control.replay();
  28. session = new MockVaadinSession(service);
  29. ui = new UI() {
  30. @Override
  31. protected void init(VaadinRequest request) {
  32. }
  33. };
  34. session.lock();
  35. try {
  36. session.setConfiguration(dc);
  37. session.setCommunicationManager(
  38. new LegacyCommunicationManager(session));
  39. ui.setSession(session);
  40. ui.doInit(request, 0, "");
  41. session.addUI(ui);
  42. } finally {
  43. session.unlock();
  44. }
  45. }
  46. @Test
  47. public void testErrorHandling() throws IOException {
  48. ErrorHandler errorHandler = EasyMock.createMock(ErrorHandler.class);
  49. errorHandler.error(EasyMock.anyObject(ErrorEvent.class));
  50. EasyMock.replay(errorHandler);
  51. Button button = new Button() {
  52. @Override
  53. public boolean handleConnectorRequest(VaadinRequest request,
  54. VaadinResponse response, String path) {
  55. throw new RuntimeException();
  56. }
  57. };
  58. button.setErrorHandler(errorHandler);
  59. session.lock();
  60. try {
  61. ui.setContent(button);
  62. } finally {
  63. session.unlock();
  64. }
  65. ConnectorResourceHandler handler = new ConnectorResourceHandler();
  66. assertTrue(handler.handleRequest(session, request, response));
  67. EasyMock.verify(errorHandler);
  68. }
  69. }