Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove instance field from singleton IndexHtmlRequestHandler #9475

Merged
merged 2 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@
*/
public class IndexHtmlRequestHandler extends JavaScriptBootstrapHandler {

private transient IndexHtmlResponse indexHtmlResponse;

@Override
public boolean synchronizedHandleRequest(VaadinSession session,
VaadinRequest request, VaadinResponse response) throws IOException {
DeploymentConfiguration config = session.getConfiguration();
IndexHtmlResponse indexHtmlResponse;

Document indexDocument = config.isProductionMode()
? getCachedIndexHtmlDocument(request.getService())
Expand Down Expand Up @@ -271,7 +270,4 @@ private static Logger getLogger() {
return LoggerFactory.getLogger(IndexHtmlRequestHandler.class);
}

protected IndexHtmlResponse getIndexHtmlResponse() {
return this.indexHtmlResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

import com.vaadin.flow.component.UI;
Expand All @@ -45,6 +46,7 @@
import com.vaadin.flow.server.AppShellRegistry;
import com.vaadin.flow.server.DevModeHandler;
import com.vaadin.flow.server.MockServletServiceSessionSetup;
import com.vaadin.flow.server.VaadinRequest;
import com.vaadin.flow.server.VaadinResponse;
import com.vaadin.flow.server.VaadinServletRequest;
import com.vaadin.flow.server.VaadinServletService;
Expand All @@ -61,6 +63,7 @@
import static com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR;
import static com.vaadin.flow.server.frontend.NodeUpdateTestUtil.createStubWebpackServer;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;

public class IndexHtmlRequestHandlerTest {
private MockServletServiceSessionSetup mocks;
Expand Down Expand Up @@ -344,21 +347,34 @@ public void should_getter_UI_return_not_empty_when_includeInitialBootstrapUidl()
throws IOException {
deploymentConfiguration.setEagerServerLoad(true);

indexHtmlRequestHandler.synchronizedHandleRequest(session,
createVaadinRequest("/"), response);
VaadinRequest request = createVaadinRequest("/");

Assert.assertNotNull(
indexHtmlRequestHandler.getIndexHtmlResponse().getUI());
indexHtmlRequestHandler.synchronizedHandleRequest(session,

request, response);

ArgumentCaptor<IndexHtmlResponse> captor =
ArgumentCaptor.forClass(IndexHtmlResponse.class);

verify(request.getService()).modifyIndexHtmlResponse(captor.capture());

Assert.assertNotNull(captor.getValue().getUI());
}

@Test
public void should_getter_UI_return_empty_when_not_includeInitialBootstrapUidl()
throws IOException {
indexHtmlRequestHandler.synchronizedHandleRequest(session,
createVaadinRequest("/"), response);
VaadinRequest request = createVaadinRequest("/");

Assert.assertEquals(Optional.empty(),
indexHtmlRequestHandler.getIndexHtmlResponse().getUI());
indexHtmlRequestHandler.synchronizedHandleRequest(session,
request, response);

ArgumentCaptor<IndexHtmlResponse> captor =
ArgumentCaptor.forClass(IndexHtmlResponse.class);

verify(request.getService()).modifyIndexHtmlResponse(captor.capture());

Assert.assertEquals(Optional.empty(), captor.getValue().getUI());
}

@Test
Expand Down Expand Up @@ -632,7 +648,7 @@ public void tearDown() throws Exception {

private VaadinServletRequest createVaadinRequest(String pathInfo) {
HttpServletRequest request = createRequest(pathInfo);
return new VaadinServletRequest(request, service);
return new VaadinServletRequest(request, Mockito.spy(service));
}

private HttpServletRequest createRequest(String pathInfo) {
Expand Down