Skip to content

Commit 8f7b4b2

Browse files
committedDec 15, 2023
#18318 Remove deployment conf field from VaadinSession
1 parent cdfde35 commit 8f7b4b2

19 files changed

+89
-98
lines changed
 

‎flow-server/src/main/java/com/vaadin/flow/server/VaadinService.java

-2
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,6 @@ private VaadinSession createAndRegisterSession(VaadinRequest request) {
936936
// Initial WebBrowser data comes from the request
937937
session.setBrowser(new WebBrowser(request));
938938

939-
session.setConfiguration(getDeploymentConfiguration());
940-
941939
// Initial locale comes from the request
942940
if (getInstantiator().getI18NProvider() != null) {
943941
setLocale(request, session);

‎flow-server/src/main/java/com/vaadin/flow/server/VaadinSession.java

+17-27
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
7878

7979
volatile boolean sessionClosedExplicitly = false;
8080

81-
/**
82-
* Configuration for the session.
83-
*/
84-
private DeploymentConfiguration configuration;
85-
8681
/**
8782
* Default locale of the session.
8883
*/
@@ -145,6 +140,14 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
145140
*/
146141
public VaadinSession(VaadinService service) {
147142
this.service = service;
143+
144+
if (service != null) {
145+
sessionLockCheckStrategy = getConfiguration().isProductionMode()
146+
? getConfiguration().getSessionLockCheckStrategy()
147+
: SessionLockCheckStrategy.THROW;
148+
assert sessionLockCheckStrategy != null;
149+
}
150+
148151
resourceRegistry = createStreamResourceRegistry();
149152
}
150153

@@ -344,33 +347,14 @@ private void refreshLock() {
344347
lock = service.getSessionLock(session);
345348
}
346349

347-
public void setConfiguration(DeploymentConfiguration configuration) {
348-
checkHasLock();
349-
if (configuration == null) {
350-
throw new IllegalArgumentException("Can not set to null");
351-
}
352-
checkSetConfiguration();
353-
this.configuration = configuration;
354-
355-
sessionLockCheckStrategy = configuration.isProductionMode()
356-
? configuration.getSessionLockCheckStrategy()
357-
: SessionLockCheckStrategy.THROW;
358-
assert sessionLockCheckStrategy != null;
359-
}
360-
361-
protected void checkSetConfiguration() {
362-
assert this.configuration == null
363-
: "Configuration can only be set once";
364-
}
365-
366350
/**
367-
* Gets the configuration for this session.
351+
* Gets the deployment configuration. Delegates the call to
352+
* {@link VaadinService#getDeploymentConfiguration()}
368353
*
369354
* @return the deployment configuration
370355
*/
371356
public DeploymentConfiguration getConfiguration() {
372-
checkHasLock();
373-
return configuration;
357+
return service.getDeploymentConfiguration();
374358
}
375359

376360
/**
@@ -1117,6 +1101,12 @@ public void refreshTransients(WrappedSession wrappedSession,
11171101
VaadinService vaadinService) {
11181102
session = wrappedSession;
11191103
service = vaadinService;
1104+
1105+
sessionLockCheckStrategy = getConfiguration().isProductionMode()
1106+
? getConfiguration().getSessionLockCheckStrategy()
1107+
: SessionLockCheckStrategy.THROW;
1108+
assert sessionLockCheckStrategy != null;
1109+
11201110
refreshLock();
11211111
}
11221112

‎flow-server/src/test/java/com/vaadin/flow/component/InvalidUrlTest.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,19 @@ private static void initUI(UI ui, String initialLocation,
8080
public VaadinContext getContext() {
8181
return new MockVaadinContext();
8282
}
83+
84+
@Override
85+
public DeploymentConfiguration getDeploymentConfiguration() {
86+
DeploymentConfiguration config = Mockito
87+
.mock(DeploymentConfiguration.class);
88+
Mockito.when(config.isProductionMode()).thenReturn(false);
89+
return config;
90+
}
8391
};
8492
service.setCurrentInstances(request, response);
8593

8694
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
8795

88-
DeploymentConfiguration config = Mockito
89-
.mock(DeploymentConfiguration.class);
90-
Mockito.when(config.isProductionMode()).thenReturn(false);
91-
92-
session.lock();
93-
session.setConfiguration(config);
94-
9596
ui.getInternals().setSession(session);
9697

9798
RouteConfiguration routeConfiguration = RouteConfiguration

‎flow-server/src/test/java/com/vaadin/flow/component/LocationObserverTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ private static VaadinSession createMockSession(Router router) {
7171
MockVaadinServletService service = new MockVaadinServletService();
7272
service.setRouter(router);
7373

74-
VaadinSession session = new AlwaysLockedVaadinSession(service);
75-
session.setConfiguration(service.getDeploymentConfiguration());
76-
return session;
74+
return new AlwaysLockedVaadinSession(service);
7775
}
7876

7977
@Override

‎flow-server/src/test/java/com/vaadin/flow/component/UITest.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,19 @@ private static void initUI(UI ui, String initialLocation,
230230
public VaadinContext getContext() {
231231
return new MockVaadinContext();
232232
}
233+
234+
@Override
235+
public DeploymentConfiguration getDeploymentConfiguration() {
236+
DeploymentConfiguration config = Mockito
237+
.mock(DeploymentConfiguration.class);
238+
Mockito.when(config.isProductionMode()).thenReturn(false);
239+
return config;
240+
}
233241
};
234242
service.setCurrentInstances(request, response);
235243

236244
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
237-
238-
DeploymentConfiguration config = Mockito
239-
.mock(DeploymentConfiguration.class);
240-
Mockito.when(config.isProductionMode()).thenReturn(false);
241-
242245
session.lock();
243-
session.setConfiguration(config);
244-
245246
ui.getInternals().setSession(session);
246247

247248
RouteConfiguration routeConfiguration = RouteConfiguration

‎flow-server/src/test/java/com/vaadin/flow/component/internal/UIInternalsTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.vaadin.flow.shared.Registration;
4040
import com.vaadin.flow.shared.communication.PushMode;
4141
import com.vaadin.tests.util.AlwaysLockedVaadinSession;
42+
import com.vaadin.tests.util.MockDeploymentConfiguration;
4243

4344
public class UIInternalsTest {
4445

@@ -118,6 +119,10 @@ public void init() {
118119
Element body = new Element("body");
119120
Mockito.when(ui.getElement()).thenReturn(body);
120121

122+
MockDeploymentConfiguration config = new MockDeploymentConfiguration();
123+
Mockito.when(vaadinService.getDeploymentConfiguration())
124+
.thenReturn(config);
125+
121126
internals = new UIInternals(ui);
122127
AlwaysLockedVaadinSession session = new AlwaysLockedVaadinSession(
123128
vaadinService);

‎flow-server/src/test/java/com/vaadin/flow/component/webcomponent/WebComponentWrapperTest.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.junit.Assert;
2424
import org.junit.Before;
2525
import org.junit.Test;
26+
import org.mockito.Mockito;
2627

2728
import com.vaadin.flow.component.Component;
2829
import com.vaadin.flow.component.Tag;
@@ -36,6 +37,7 @@
3637
import com.vaadin.flow.server.VaadinSession;
3738
import com.vaadin.flow.server.webcomponent.WebComponentBinding;
3839
import com.vaadin.tests.util.AlwaysLockedVaadinSession;
40+
import com.vaadin.tests.util.MockDeploymentConfiguration;
3941

4042
import elemental.json.Json;
4143
import static org.mockito.Mockito.mock;
@@ -242,9 +244,13 @@ private static WebComponentUI constructWebComponentUI(
242244
Element body = new Element("body");
243245
when(ui.getElement()).thenReturn(body);
244246

247+
VaadinService vaadinService = Mockito.mock(VaadinService.class);
248+
MockDeploymentConfiguration config = new MockDeploymentConfiguration();
249+
Mockito.when(vaadinService.getDeploymentConfiguration())
250+
.thenReturn(config);
251+
245252
UIInternals internals = new UIInternals(ui);
246-
internals.setSession(
247-
new AlwaysLockedVaadinSession(mock(VaadinService.class)));
253+
internals.setSession(new AlwaysLockedVaadinSession(vaadinService));
248254
when(ui.getInternals()).thenReturn(internals);
249255

250256
Component parent = new Parent();

‎flow-server/src/test/java/com/vaadin/flow/router/RouteConfigurationTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.vaadin.flow.server.VaadinServletService;
3232
import com.vaadin.flow.server.VaadinSession;
3333
import com.vaadin.flow.server.startup.ApplicationRouteRegistry;
34+
import com.vaadin.tests.util.MockDeploymentConfiguration;
3435

3536
@NotThreadSafe
3637
public class RouteConfigurationTest {
@@ -50,6 +51,9 @@ public void init() {
5051
vaadinService = Mockito.mock(MockService.class);
5152
Mockito.when(vaadinService.getRouteRegistry()).thenReturn(registry);
5253
Mockito.when(vaadinService.getContext()).thenReturn(vaadinContext);
54+
MockDeploymentConfiguration config = new MockDeploymentConfiguration();
55+
Mockito.when(vaadinService.getDeploymentConfiguration())
56+
.thenReturn(config);
5357

5458
VaadinService.setCurrent(vaadinService);
5559

‎flow-server/src/test/java/com/vaadin/flow/router/RouterConfigurationUrlResolvingTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public void init() throws NoSuchFieldException, IllegalAccessException {
5252
super.init();
5353
ui = new RouterTestMockUI(router);
5454
ui.getSession().lock();
55-
ui.getSession().setConfiguration(configuration);
5655

5756
VaadinService.setCurrent(service);
5857

‎flow-server/src/test/java/com/vaadin/flow/router/RouterTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,6 @@ public void init() throws NoSuchFieldException, SecurityException,
18251825
super.init();
18261826
ui = new RouterTestMockUI(router);
18271827
ui.getSession().lock();
1828-
ui.getSession().setConfiguration(configuration);
18291828

18301829
VaadinService.setCurrent(service);
18311830

‎flow-server/src/test/java/com/vaadin/flow/router/internal/ErrorStateRendererTest.java

-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import com.vaadin.flow.server.VaadinContext;
4747
import com.vaadin.flow.server.startup.ApplicationRouteRegistry;
4848
import com.vaadin.tests.util.AlwaysLockedVaadinSession;
49-
import com.vaadin.tests.util.MockDeploymentConfiguration;
5049
import com.vaadin.tests.util.MockUI;
5150

5251
import elemental.json.Json;
@@ -221,7 +220,6 @@ public VaadinContext getContext() {
221220
};
222221

223222
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
224-
session.setConfiguration(new MockDeploymentConfiguration());
225223

226224
MockUI ui = new MockUI(session);
227225
return ui;

‎flow-server/src/test/java/com/vaadin/flow/router/internal/NavigationStateRendererTest.java

-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
import com.vaadin.flow.server.ServiceException;
6969
import com.vaadin.flow.server.startup.ApplicationRouteRegistry;
7070
import com.vaadin.tests.util.AlwaysLockedVaadinSession;
71-
import com.vaadin.tests.util.MockDeploymentConfiguration;
7271
import com.vaadin.tests.util.MockUI;
7372

7473
import elemental.json.Json;
@@ -287,7 +286,6 @@ public void handle_preserveOnRefreshAndWindowNameKnown_componentIsCachedRetrieve
287286

288287
// given a locked session
289288
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
290-
session.setConfiguration(new MockDeploymentConfiguration());
291289

292290
// given a UI that contain a window name ROOT.123
293291
MockUI ui1 = new MockUI(session);
@@ -356,7 +354,6 @@ public void handle_preserveOnRefresh_refreshIsFlaggedInEvent() {
356354

357355
// given a locked session
358356
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
359-
session.setConfiguration(new MockDeploymentConfiguration());
360357

361358
// given a UI that contain a window name ROOT.123
362359
MockUI ui = new MockUI(session);
@@ -409,7 +406,6 @@ public void handle_preserveOnRefresh_otherUIChildrenAreMoved() {
409406

410407
// given a locked session
411408
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
412-
session.setConfiguration(new MockDeploymentConfiguration());
413409

414410
// given a NavigationStateRenderer mapping to PreservedView
415411
NavigationStateRenderer renderer = new NavigationStateRenderer(
@@ -456,7 +452,6 @@ public void handle_preserveOnRefreshView_routerLayoutIsPreserved_oldUiIsClosed()
456452

457453
// given a locked session
458454
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
459-
session.setConfiguration(new MockDeploymentConfiguration());
460455

461456
// given a NavigationStateRenderer mapping to PreservedNestedView
462457
Router router = session.getService().getRouter();
@@ -510,7 +505,6 @@ public void handle_preserveOnRefresh_sameUI_uiIsNotClosed_childrenAreNotRemoved(
510505

511506
// given a locked session
512507
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
513-
session.setConfiguration(new MockDeploymentConfiguration());
514508

515509
// given a NavigationStateRenderer mapping to PreservedView
516510
NavigationStateRenderer renderer = new NavigationStateRenderer(
@@ -582,7 +576,6 @@ public void handle_variousInputs_checkPushStateShouldBeCalledOrNot() {
582576

583577
// given a locked session
584578
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
585-
session.setConfiguration(new MockDeploymentConfiguration());
586579

587580
// given a NavigationStateRenderer mapping to RegularView
588581
new NavigationStateBuilder(router).withTarget(RegularView.class)

‎flow-server/src/test/java/com/vaadin/flow/server/CustomUIClassLoaderTest.java

-13
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.vaadin.flow.component.UI;
1111
import com.vaadin.flow.function.DeploymentConfiguration;
1212
import com.vaadin.flow.server.startup.ApplicationConfiguration;
13-
import com.vaadin.tests.util.AlwaysLockedVaadinSession;
1413

1514
import org.junit.Test;
1615
import org.mockito.Mockito;
@@ -52,9 +51,6 @@ protected synchronized Class<?> loadClass(String name, boolean resolve)
5251
*/
5352
@Test
5453
public void testWithDefaultClassLoader() throws Exception {
55-
VaadinSession application = createStubApplication();
56-
application.setConfiguration(createConfigurationMock());
57-
5854
Class<? extends UI> uiClass = BootstrapHandler
5955
.getUIClass(createRequestMock(getClass().getClassLoader()));
6056

@@ -113,13 +109,4 @@ public void testWithClassLoader() throws Exception {
113109
loggingClassLoader.requestedClasses.get(0));
114110

115111
}
116-
117-
private VaadinSession createStubApplication() {
118-
return new AlwaysLockedVaadinSession(new MockVaadinServletService()) {
119-
@Override
120-
public DeploymentConfiguration getConfiguration() {
121-
return createConfigurationMock();
122-
}
123-
};
124-
}
125112
}

‎flow-server/src/test/java/com/vaadin/flow/server/ErrorHandlerUtilTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.vaadin.flow.router.RouterLayout;
4545
import com.vaadin.flow.server.startup.ApplicationRouteRegistry;
4646
import com.vaadin.tests.util.AlwaysLockedVaadinSession;
47+
import com.vaadin.tests.util.MockDeploymentConfiguration;
4748

4849
@NotThreadSafe
4950
public class ErrorHandlerUtilTest {
@@ -129,6 +130,10 @@ public void init() {
129130
Mockito.when(ui.getUI()).thenReturn(Optional.of(ui));
130131
Mockito.when(ui.getInternals()).thenReturn(internals);
131132

133+
MockDeploymentConfiguration config = new MockDeploymentConfiguration();
134+
Mockito.when(vaadinService.getDeploymentConfiguration())
135+
.thenReturn(config);
136+
132137
session = new AlwaysLockedVaadinSession(vaadinService);
133138
VaadinContext context = new MockVaadinContext();
134139
Mockito.when(vaadinService.getContext()).thenReturn(context);

‎flow-server/src/test/java/com/vaadin/flow/server/SessionRouteRegistryTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.vaadin.flow.component.Component;
3232
import com.vaadin.flow.component.HtmlContainer;
3333
import com.vaadin.flow.component.Tag;
34+
import com.vaadin.flow.function.DeploymentConfiguration;
3435
import com.vaadin.flow.internal.CurrentInstance;
3536
import com.vaadin.flow.router.BeforeEnterEvent;
3637
import com.vaadin.flow.router.BeforeEvent;
@@ -50,6 +51,7 @@
5051
import com.vaadin.flow.server.startup.ApplicationConfiguration;
5152
import com.vaadin.flow.server.startup.ApplicationRouteRegistry;
5253
import com.vaadin.flow.shared.Registration;
54+
import com.vaadin.tests.util.MockDeploymentConfiguration;
5355

5456
public class SessionRouteRegistryTest {
5557

@@ -76,6 +78,11 @@ public void init() {
7678
Mockito.when(applicationConfiguration.isProductionMode())
7779
.thenReturn(true);
7880

81+
MockDeploymentConfiguration config = new MockDeploymentConfiguration();
82+
config.setProductionMode(true);
83+
Mockito.when(vaadinService.getDeploymentConfiguration())
84+
.thenReturn(config);
85+
7986
VaadinService.setCurrent(vaadinService);
8087

8188
session = new MockVaadinSession(vaadinService) {
@@ -1239,5 +1246,10 @@ protected Lock getSessionLock(WrappedSession wrappedSession) {
12391246
protected RouteRegistry getRouteRegistry() {
12401247
return appRegistry;
12411248
}
1249+
1250+
@Override
1251+
public DeploymentConfiguration getDeploymentConfiguration() {
1252+
return new MockDeploymentConfiguration();
1253+
}
12421254
}
12431255
}

0 commit comments

Comments
 (0)
Please sign in to comment.