IndexHtmlRequestHandlerTest.java (vaadin-flow-4.0.7) | : | IndexHtmlRequestHandlerTest.java (vaadin-flow-4.0.8) | ||
---|---|---|---|---|
skipping to change at line 40 | skipping to change at line 40 | |||
import org.jsoup.Jsoup; | import org.jsoup.Jsoup; | |||
import org.jsoup.internal.StringUtil; | import org.jsoup.internal.StringUtil; | |||
import org.jsoup.nodes.Document; | import org.jsoup.nodes.Document; | |||
import org.jsoup.select.Elements; | import org.jsoup.select.Elements; | |||
import org.junit.After; | import org.junit.After; | |||
import org.junit.Assert; | import org.junit.Assert; | |||
import org.junit.Before; | import org.junit.Before; | |||
import org.junit.Rule; | import org.junit.Rule; | |||
import org.junit.Test; | import org.junit.Test; | |||
import org.junit.rules.TemporaryFolder; | import org.junit.rules.TemporaryFolder; | |||
import org.mockito.ArgumentCaptor; | ||||
import org.mockito.Mockito; | import org.mockito.Mockito; | |||
import com.vaadin.flow.component.UI; | import com.vaadin.flow.component.UI; | |||
import com.vaadin.flow.component.internal.JavaScriptBootstrapUI; | import com.vaadin.flow.component.internal.JavaScriptBootstrapUI; | |||
import com.vaadin.flow.internal.UsageStatistics; | import com.vaadin.flow.internal.UsageStatistics; | |||
import com.vaadin.flow.server.AppShellRegistry; | import com.vaadin.flow.server.AppShellRegistry; | |||
import com.vaadin.flow.server.DevModeHandler; | import com.vaadin.flow.server.DevModeHandler; | |||
import com.vaadin.flow.server.MockServletServiceSessionSetup; | import com.vaadin.flow.server.MockServletServiceSessionSetup; | |||
import com.vaadin.flow.server.VaadinRequest; | ||||
import com.vaadin.flow.server.VaadinResponse; | import com.vaadin.flow.server.VaadinResponse; | |||
import com.vaadin.flow.server.VaadinServletRequest; | import com.vaadin.flow.server.VaadinServletRequest; | |||
import com.vaadin.flow.server.VaadinSession; | import com.vaadin.flow.server.VaadinSession; | |||
import com.vaadin.flow.server.frontend.FrontendUtils; | import com.vaadin.flow.server.frontend.FrontendUtils; | |||
import com.vaadin.flow.server.startup.VaadinAppShellInitializerTest.AppShellWith PWA; | import com.vaadin.flow.server.startup.VaadinAppShellInitializerTest.AppShellWith PWA; | |||
import com.vaadin.flow.server.startup.VaadinAppShellInitializerTest.MyAppShellWi thConfigurator; | import com.vaadin.flow.server.startup.VaadinAppShellInitializerTest.MyAppShellWi thConfigurator; | |||
import com.vaadin.tests.util.MockDeploymentConfiguration; | import com.vaadin.tests.util.MockDeploymentConfiguration; | |||
import elemental.json.Json; | import elemental.json.Json; | |||
import elemental.json.JsonObject; | import elemental.json.JsonObject; | |||
import static com.vaadin.flow.component.internal.JavaScriptBootstrapUI.SERVER_RO UTING; | import static com.vaadin.flow.component.internal.JavaScriptBootstrapUI.SERVER_RO UTING; | |||
import static com.vaadin.flow.server.DevModeHandlerTest.createStubWebpackTcpList ener; | import static com.vaadin.flow.server.DevModeHandlerTest.createStubWebpackTcpList ener; | |||
import static com.vaadin.flow.server.frontend.NodeUpdateTestUtil.createStubWebpa ckServer; | import static com.vaadin.flow.server.frontend.NodeUpdateTestUtil.createStubWebpa ckServer; | |||
import static org.junit.Assert.assertEquals; | import static org.junit.Assert.assertEquals; | |||
import static org.mockito.Mockito.verify; | ||||
public class IndexHtmlRequestHandlerTest { | public class IndexHtmlRequestHandlerTest { | |||
private MockServletServiceSessionSetup mocks; | private MockServletServiceSessionSetup mocks; | |||
private MockServletServiceSessionSetup.TestVaadinServletService service; | private MockServletServiceSessionSetup.TestVaadinServletService service; | |||
private VaadinSession session; | private VaadinSession session; | |||
private IndexHtmlRequestHandler indexHtmlRequestHandler; | private IndexHtmlRequestHandler indexHtmlRequestHandler; | |||
private VaadinResponse response; | private VaadinResponse response; | |||
private ByteArrayOutputStream responseOutput; | private ByteArrayOutputStream responseOutput; | |||
private MockDeploymentConfiguration deploymentConfiguration; | private MockDeploymentConfiguration deploymentConfiguration; | |||
private HttpServer httpServer; | private HttpServer httpServer; | |||
skipping to change at line 310 | skipping to change at line 313 | |||
scripts.get(0).childNode(0).toString()); | scripts.get(0).childNode(0).toString()); | |||
Assert.assertEquals("", scripts.get(0).attr("initial")); | Assert.assertEquals("", scripts.get(0).attr("initial")); | |||
Assert.assertNull(UI.getCurrent()); | Assert.assertNull(UI.getCurrent()); | |||
} | } | |||
@Test | @Test | |||
public void should_getter_UI_return_not_empty_when_includeInitialBootstrapUi dl() | public void should_getter_UI_return_not_empty_when_includeInitialBootstrapUi dl() | |||
throws IOException { | throws IOException { | |||
deploymentConfiguration.setEagerServerLoad(true); | deploymentConfiguration.setEagerServerLoad(true); | |||
VaadinRequest request = createVaadinRequest("/"); | ||||
indexHtmlRequestHandler.synchronizedHandleRequest(session, | indexHtmlRequestHandler.synchronizedHandleRequest(session, | |||
createVaadinRequest("/"), response); | ||||
Assert.assertNotNull( | request, response); | |||
indexHtmlRequestHandler.getIndexHtmlResponse().getUI()); | ||||
ArgumentCaptor<IndexHtmlResponse> captor = | ||||
ArgumentCaptor.forClass(IndexHtmlResponse.class); | ||||
verify(request.getService()).modifyIndexHtmlResponse(captor.capture()); | ||||
Assert.assertNotNull(captor.getValue().getUI()); | ||||
} | } | |||
@Test | @Test | |||
public void should_getter_UI_return_empty_when_not_includeInitialBootstrapUi dl() | public void should_getter_UI_return_empty_when_not_includeInitialBootstrapUi dl() | |||
throws IOException { | throws IOException { | |||
VaadinRequest request = createVaadinRequest("/"); | ||||
indexHtmlRequestHandler.synchronizedHandleRequest(session, | indexHtmlRequestHandler.synchronizedHandleRequest(session, | |||
createVaadinRequest("/"), response); | request, response); | |||
ArgumentCaptor<IndexHtmlResponse> captor = | ||||
ArgumentCaptor.forClass(IndexHtmlResponse.class); | ||||
verify(request.getService()).modifyIndexHtmlResponse(captor.capture()); | ||||
Assert.assertEquals(Optional.empty(), | Assert.assertEquals(Optional.empty(), captor.getValue().getUI()); | |||
indexHtmlRequestHandler.getIndexHtmlResponse().getUI()); | ||||
} | } | |||
@Test | @Test | |||
public void should_include_token_in_dom_when_return_not_null_csrfToken_in_se ssion() | public void should_include_token_in_dom_when_return_not_null_csrfToken_in_se ssion() | |||
throws IOException { | throws IOException { | |||
Mockito.when(session.getCsrfToken()).thenReturn("foo"); | Mockito.when(session.getCsrfToken()).thenReturn("foo"); | |||
indexHtmlRequestHandler.synchronizedHandleRequest(session, | indexHtmlRequestHandler.synchronizedHandleRequest(session, | |||
createVaadinRequest("/"), response); | createVaadinRequest("/"), response); | |||
String indexHtml = responseOutput | String indexHtml = responseOutput | |||
skipping to change at line 598 | skipping to change at line 614 | |||
httpServer = null; | httpServer = null; | |||
} | } | |||
DevModeHandler handler = DevModeHandler.getDevModeHandler(); | DevModeHandler handler = DevModeHandler.getDevModeHandler(); | |||
if (handler != null) { | if (handler != null) { | |||
handler.stop(); | handler.stop(); | |||
} | } | |||
} | } | |||
private VaadinServletRequest createVaadinRequest(String pathInfo) { | private VaadinServletRequest createVaadinRequest(String pathInfo) { | |||
HttpServletRequest request = createRequest(pathInfo); | HttpServletRequest request = createRequest(pathInfo); | |||
return new VaadinServletRequest(request, service); | return new VaadinServletRequest(request, Mockito.spy(service)); | |||
} | } | |||
private HttpServletRequest createRequest(String pathInfo) { | private HttpServletRequest createRequest(String pathInfo) { | |||
HttpServletRequest request = Mockito.mock(HttpServletRequest.class); | HttpServletRequest request = Mockito.mock(HttpServletRequest.class); | |||
Mockito.doAnswer(invocation -> "").when(request).getServletPath(); | Mockito.doAnswer(invocation -> "").when(request).getServletPath(); | |||
Mockito.doAnswer(invocation -> pathInfo).when(request).getPathInfo(); | Mockito.doAnswer(invocation -> pathInfo).when(request).getPathInfo(); | |||
Mockito.doAnswer(invocation -> new StringBuffer(pathInfo)).when(request) | Mockito.doAnswer(invocation -> new StringBuffer(pathInfo)).when(request) | |||
.getRequestURL(); | .getRequestURL(); | |||
return request; | return request; | |||
} | } | |||
End of changes. 10 change blocks. | ||||
7 lines changed or deleted | 23 lines changed or added |