Skip to content

Commit db046b4

Browse files
authored
chore!: remove setConfiguration from VaadinSession (#21938)
1 parent 87d5aa4 commit db046b4

16 files changed

+60
-83
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,12 @@ private VaadinSession createAndRegisterSession(VaadinRequest request) {
12031203
// Initial WebBrowser data comes from the request
12041204
session.setBrowser(new WebBrowser(request));
12051205

1206-
session.setConfiguration(getDeploymentConfiguration());
1206+
SessionLockCheckStrategy sessionLockCheckStrategy = getDeploymentConfiguration()
1207+
.isProductionMode()
1208+
? getDeploymentConfiguration()
1209+
.getSessionLockCheckStrategy()
1210+
: SessionLockCheckStrategy.THROW;
1211+
assert sessionLockCheckStrategy != null;
12071212

12081213
// Initial locale comes from the request
12091214
if (getInstantiator().getI18NProvider() != null) {

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

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ public class VaadinSession implements HttpSessionBindingListener, Serializable {
8383

8484
final List<SessionDestroyListener> destroyListeners = new CopyOnWriteArrayList<>();
8585

86-
/**
87-
* Configuration for the session.
88-
*/
89-
private DeploymentConfiguration configuration;
90-
9186
/**
9287
* Default locale of the session.
9388
*/
@@ -350,38 +345,14 @@ private void refreshLock() {
350345
}
351346

352347
/**
353-
* @deprecated with no replacement. There should only be one
354-
* DeploymentConfiguration per VaadinService, no
355-
* VaadinSession-specific instances.
356-
*/
357-
@Deprecated(since = "24.8", forRemoval = true)
358-
public void setConfiguration(DeploymentConfiguration configuration) {
359-
checkHasLock();
360-
if (configuration == null) {
361-
throw new IllegalArgumentException("Can not set to null");
362-
}
363-
checkSetConfiguration();
364-
this.configuration = configuration;
365-
366-
sessionLockCheckStrategy = configuration.isProductionMode()
367-
? configuration.getSessionLockCheckStrategy()
368-
: SessionLockCheckStrategy.THROW;
369-
assert sessionLockCheckStrategy != null;
370-
}
371-
372-
protected void checkSetConfiguration() {
373-
assert this.configuration == null
374-
: "Configuration can only be set once";
375-
}
376-
377-
/**
378-
* Gets the configuration for this session.
348+
* Gets the configuration for this session. Delegates the call to
349+
* {@link VaadinService#getDeploymentConfiguration()}.
379350
*
380351
* @return the deployment configuration
381352
*/
382353
public DeploymentConfiguration getConfiguration() {
383354
checkHasLock();
384-
return configuration;
355+
return service.getDeploymentConfiguration();
385356
}
386357

387358
/**

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ private static void initUI(UI ui, String initialLocation,
8282
public VaadinContext getContext() {
8383
return new MockVaadinContext();
8484
}
85+
86+
@Override
87+
public DeploymentConfiguration getDeploymentConfiguration() {
88+
if (super.getDeploymentConfiguration() != null) {
89+
return super.getDeploymentConfiguration();
90+
} else {
91+
DeploymentConfiguration config = Mockito
92+
.mock(DeploymentConfiguration.class);
93+
Mockito.when(config.isProductionMode()).thenReturn(false);
94+
setConfiguration(config);
95+
return config;
96+
}
97+
}
8598
};
8699
service.setCurrentInstances(request, response);
87100

@@ -94,8 +107,6 @@ public VaadinContext getContext() {
94107
Mockito.when(config.getProjectFolder()).thenReturn(new File("./"));
95108
Mockito.when(config.getBuildFolder()).thenReturn("build");
96109

97-
session.lock();
98-
session.setConfiguration(config);
99110
((MockVaadinServletService) service).setConfiguration(config);
100111
CurrentInstance.set(VaadinSession.class, session);
101112

@@ -114,8 +125,6 @@ public VaadinContext getContext() {
114125
ui.getInternals().getRouter().initializeUI(ui,
115126
UITest.requestToLocation(request));
116127

117-
session.unlock();
118-
119128
if (statusCodeCaptor != null) {
120129
Mockito.verify(response).setStatus(statusCodeCaptor.capture());
121130
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ public VaadinContext getContext() {
248248
Mockito.when(config.getBuildFolder()).thenReturn("build");
249249

250250
session.lock();
251-
session.setConfiguration(config);
252251
((MockVaadinServletService) service).setConfiguration(config);
253252
ui.getInternals().setSession(session);
254253

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ public void init() {
118118

119119
vaadinService = new MockVaadinServletService();
120120
internals = new UIInternals(ui);
121+
MockDeploymentConfiguration config = new MockDeploymentConfiguration();
122+
Mockito.when(vaadinService.getDeploymentConfiguration())
123+
.thenReturn(config);
121124
AlwaysLockedVaadinSession session = new AlwaysLockedVaadinSession(
122125
vaadinService);
123-
session.setConfiguration(Mockito.mock(DeploymentConfiguration.class));
124126
internals.setSession(session);
125127
Mockito.when(ui.getSession()).thenReturn(session);
126128
}

flow-server/src/test/java/com/vaadin/flow/hotswap/HotswapperTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,16 +1375,12 @@ private VaadinSession createMockVaadinSession() {
13751375
WrappedSession wrappedSession = Mockito.mock(WrappedSession.class);
13761376
when(wrappedSession.getId()).thenReturn(UUID.randomUUID().toString());
13771377

1378-
MockVaadinSession session = new MockVaadinSession(service) {
1378+
return new MockVaadinSession(service) {
13791379
@Override
13801380
public WrappedSession getSession() {
13811381
return wrappedSession;
13821382
}
13831383
};
1384-
session.getLockInstance().lock();
1385-
session.setConfiguration(service.getDeploymentConfiguration());
1386-
session.getLockInstance().unlock();
1387-
return session;
13881384
}
13891385

13901386
private String[] toClassNameArray(Collection<Class<?>> classes) {

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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,6 @@ public void init() throws NoSuchFieldException, SecurityException,
18421842
super.init();
18431843
ui = new RouterTestMockUI(router);
18441844
ui.getSession().lock();
1845-
ui.getSession().setConfiguration(configuration);
18461845

18471846
VaadinService.setCurrent(service);
18481847

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,7 @@ public VaadinContext getContext() {
223223
};
224224

225225
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
226-
session.setConfiguration(new MockDeploymentConfiguration());
227226

228-
MockUI ui = new MockUI(session);
229-
return ui;
227+
return new MockUI(session);
230228
}
231229
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ public void handle_preserveOnRefreshAndWindowNameKnown_componentIsCachedRetrieve
394394

395395
// given a locked session
396396
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
397-
session.setConfiguration(new MockDeploymentConfiguration());
398397

399398
// given a UI that contain a window name ROOT.123
400399
MockUI ui1 = new MockUI(session);
@@ -463,7 +462,6 @@ public void handle_preserveOnRefresh_refreshIsFlaggedInEvent() {
463462

464463
// given a locked session
465464
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
466-
session.setConfiguration(new MockDeploymentConfiguration());
467465

468466
// given a UI that contain a window name ROOT.123
469467
MockUI ui = new MockUI(session);
@@ -516,7 +514,6 @@ public void handle_preserveOnRefresh_otherUIChildrenAreMoved() {
516514

517515
// given a locked session
518516
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
519-
session.setConfiguration(new MockDeploymentConfiguration());
520517

521518
// given a NavigationStateRenderer mapping to PreservedView
522519
NavigationStateRenderer renderer = new NavigationStateRenderer(
@@ -562,7 +559,6 @@ public void handle_preserveOnRefreshView_routerLayoutIsPreserved_oldUiIsClosed()
562559

563560
// given a locked session
564561
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
565-
session.setConfiguration(new MockDeploymentConfiguration());
566562

567563
// given a NavigationStateRenderer mapping to PreservedNestedView
568564
router = session.getService().getRouter();
@@ -615,7 +611,6 @@ public void handle_preserveOnRefresh_sameUI_uiIsNotClosed_childrenAreNotRemoved(
615611

616612
// given a locked session
617613
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
618-
session.setConfiguration(new MockDeploymentConfiguration());
619614

620615
// given a NavigationStateRenderer mapping to PreservedView
621616
NavigationStateRenderer renderer = new NavigationStateRenderer(
@@ -671,7 +666,6 @@ public void handle_preserveOnRefreshView_refreshCurrentRouteRecreatesComponents(
671666

672667
// given a locked session
673668
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
674-
session.setConfiguration(new MockDeploymentConfiguration());
675669

676670
// given a NavigationStateRenderer mapping to PreservedNestedView
677671
router = session.getService().getRouter();
@@ -729,7 +723,6 @@ public void handle_normalView_refreshCurrentRouteRecreatesComponents() {
729723

730724
// given a locked session
731725
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
732-
session.setConfiguration(new MockDeploymentConfiguration());
733726

734727
// given a NavigationStateRenderer mapping to PreservedNestedView
735728
router = session.getService().getRouter();
@@ -779,7 +772,6 @@ public void handle_clientNavigation_withMatchingFlowRoute() {
779772

780773
// given a locked session
781774
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
782-
session.setConfiguration(new MockDeploymentConfiguration());
783775

784776
// given a NavigationStateRenderer mapping to PreservedNestedView
785777
router = session.getService().getRouter();
@@ -828,7 +820,6 @@ public void handle_refreshRoute_modalComponentsDetached() {
828820

829821
// given a locked session
830822
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
831-
session.setConfiguration(new MockDeploymentConfiguration());
832823

833824
// given a NavigationStateRenderer mapping to PreservedNestedView
834825
router = session.getService().getRouter();
@@ -908,7 +899,6 @@ public void handle_variousInputs_checkPushStateShouldBeCalledOrNot() {
908899
// When using react router we have the sever do the update in all cases
909900
// to control the correct timing for url updates
910901
configuration.setReactEnabled(false);
911-
session.setConfiguration(configuration);
912902

913903
// given a NavigationStateRenderer mapping to RegularView
914904
new NavigationStateBuilder(router).withTarget(RegularView.class)

0 commit comments

Comments
 (0)