|
18 | 18 | import com.vaadin.flow.component.UI;
|
19 | 19 | import com.vaadin.flow.di.Instantiator;
|
20 | 20 | import com.vaadin.flow.server.ServiceException;
|
21 |
| -import com.vaadin.flow.server.VaadinRequestInterceptor; |
22 | 21 | import com.vaadin.flow.server.VaadinService;
|
23 | 22 | import com.vaadin.flow.server.VaadinServiceInitListener;
|
| 23 | +import com.vaadin.flow.server.VaadinServletRequest; |
| 24 | +import com.vaadin.flow.server.VaadinServletResponse; |
| 25 | +import com.vaadin.flow.server.VaadinServletService; |
24 | 26 | import com.vaadin.flow.spring.instantiator.SpringInstantiatorTest;
|
25 | 27 | import jakarta.servlet.ServletException;
|
26 | 28 | import org.junit.Assert;
|
27 | 29 | import org.junit.Test;
|
28 |
| -import org.junit.jupiter.api.Assertions; |
29 | 30 | import org.junit.runner.RunWith;
|
30 | 31 | import org.springframework.beans.factory.annotation.Autowired;
|
31 | 32 | import org.springframework.context.ApplicationContext;
|
32 | 33 | import org.springframework.context.annotation.Import;
|
| 34 | +import org.springframework.mock.web.MockHttpServletRequest; |
| 35 | +import org.springframework.mock.web.MockHttpServletResponse; |
33 | 36 | import org.springframework.stereotype.Component;
|
34 | 37 | import org.springframework.test.context.junit4.SpringRunner;
|
35 | 38 |
|
36 |
| -import java.util.List; |
37 | 39 | import java.util.Properties;
|
38 | 40 | import java.util.stream.Stream;
|
39 |
| -import java.util.stream.StreamSupport; |
40 | 41 |
|
41 | 42 | @RunWith(SpringRunner.class)
|
42 | 43 | @Import(TestServletConfiguration.class)
|
@@ -97,19 +98,27 @@ public void uiInitListenerAsSpringBean_listenerIsAutoregisteredAsUIInitiLietnerI
|
97 | 98 |
|
98 | 99 | @Test
|
99 | 100 | public void requestInterceptorsAreRegisteredOnTheService()
|
100 |
| - throws ServletException { |
101 |
| - VaadinService service = SpringInstantiatorTest.getService(context, |
102 |
| - new Properties()); |
| 101 | + throws ServletException, ServiceException { |
| 102 | + VaadinServletService service = (VaadinServletService) SpringInstantiatorTest |
| 103 | + .getService(context, new Properties()); |
| 104 | + VaadinServletRequest request = new VaadinServletRequest( |
| 105 | + new MockHttpServletRequest(), service); |
| 106 | + |
| 107 | + try { |
| 108 | + service.handleRequest(request, new VaadinServletResponse( |
| 109 | + new MockHttpServletResponse(), service)); |
| 110 | + } catch (Exception e) { |
| 111 | + Assert.assertTrue( |
| 112 | + "Exception must be related to missing frontend folder", |
| 113 | + e.getMessage().contains("Unable to find index.html")); |
| 114 | + } |
103 | 115 |
|
104 |
| - List<VaadinRequestInterceptor> interceptors = StreamSupport |
105 |
| - .stream(service.getVaadinRequestInterceptors().spliterator(), |
106 |
| - false) |
107 |
| - .toList(); |
108 |
| - Assertions.assertEquals(1, interceptors.size(), |
109 |
| - "There should be 1 filter"); |
110 |
| - Assertions.assertInstanceOf( |
111 |
| - TestServletConfiguration.MyRequestInterceptor.class, |
112 |
| - interceptors.get(0), "MyFilter should be registered"); |
| 116 | + Assert.assertEquals("Interceptor got called on start", "true", |
| 117 | + request.getAttribute("started")); |
| 118 | + Assert.assertEquals("Interceptor got called on error", "true", |
| 119 | + request.getAttribute("error")); |
| 120 | + Assert.assertEquals("Interceptor got called on stop", "true", |
| 121 | + request.getAttribute("stopped")); |
113 | 122 | }
|
114 | 123 |
|
115 | 124 | }
|
0 commit comments