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.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server;
  17. import java.io.IOException;
  18. import org.easymock.EasyMock;
  19. import org.easymock.IMocksControl;
  20. import org.junit.Assert;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23. import com.vaadin.ui.Button;
  24. import com.vaadin.ui.UI;
  25. public class ConnectorResourceHandlerTest {
  26. VaadinRequest request;
  27. VaadinResponse response;
  28. VaadinSession session;
  29. UI ui;
  30. @Before
  31. public void setUp() {
  32. IMocksControl control = EasyMock.createNiceControl();
  33. request = control.createMock(VaadinRequest.class);
  34. response = control.createMock(VaadinResponse.class);
  35. VaadinService service = control.createMock(VaadinService.class);
  36. EasyMock.expect(request.getPathInfo())
  37. .andReturn("/APP/connector/0/1/2");
  38. control.replay();
  39. session = new MockVaadinSession(service);
  40. ui = new UI() {
  41. @Override
  42. protected void init(VaadinRequest request) {
  43. }
  44. };
  45. ui.doInit(request, 0, "");
  46. session.lock();
  47. try {
  48. session.setCommunicationManager(new LegacyCommunicationManager(
  49. session));
  50. ui.setSession(session);
  51. session.addUI(ui);
  52. } finally {
  53. session.unlock();
  54. }
  55. }
  56. @Test
  57. public void testErrorHandling() throws IOException {
  58. ErrorHandler errorHandler = EasyMock.createMock(ErrorHandler.class);
  59. errorHandler.error(EasyMock.anyObject(ErrorEvent.class));
  60. EasyMock.replay(errorHandler);
  61. Button button = new Button() {
  62. @Override
  63. public boolean handleConnectorRequest(VaadinRequest request,
  64. VaadinResponse response, String path) {
  65. throw new RuntimeException();
  66. }
  67. };
  68. button.setErrorHandler(errorHandler);
  69. session.lock();
  70. try {
  71. ui.setContent(button);
  72. } finally {
  73. session.unlock();
  74. }
  75. ConnectorResourceHandler handler = new ConnectorResourceHandler();
  76. Assert.assertTrue(handler.handleRequest(session, request, response));
  77. EasyMock.verify(errorHandler);
  78. }
  79. }