use of com.vaadin.flow.server.UIInitEvent in project flow by vaadin.
the class VaadinRouteScopeTest method refresh_uiWithTheSameWindowName_beanInScopeIsDestroyedAfterRefresh.
@Test
public void refresh_uiWithTheSameWindowName_beanInScopeIsDestroyedAfterRefresh() {
UI ui = mockUI();
UI anotherUI = makeAnotherUI(ui);
ExtendedClientDetails details = Mockito.mock(ExtendedClientDetails.class);
Mockito.when(details.getWindowName()).thenReturn("bar");
ui.getInternals().setExtendedClientDetails(details);
anotherUI.getInternals().setExtendedClientDetails(details);
ui.getSession().addUI(ui);
ui.getSession().addUI(anotherUI);
mockServletContext(ui);
VaadinRouteScope scope = initScope(ui);
AtomicInteger count = new AtomicInteger();
scope.registerDestructionCallback("foo", () -> count.getAndIncrement());
scope.uiInit(new UIInitEvent(ui, ui.getSession().getService()));
navigateTo(ui, new NavigationTarget());
putObjectIntoScope(scope);
// close the first UI
ui.getSession().removeUI(ui);
// the bean is not removed since there is a "preserved" UI
Assert.assertEquals(0, count.get());
UI.setCurrent(anotherUI);
scope = initScope(anotherUI);
// the bean is not removed since there is a "preserved" UI
Assert.assertEquals(0, count.get());
navigateTo(anotherUI, new AnotherNavigationTarget());
// the bean is removed since navigation away from it's owner navigation
// target
Assert.assertEquals(1, count.get());
}
use of com.vaadin.flow.server.UIInitEvent in project flow by vaadin.
the class VaadinRouteScopeTest method initScope.
private VaadinRouteScope initScope(UI ui) {
VaadinRouteScope scope = getScope();
scope.getBeanStore();
scope.uiInit(new UIInitEvent(ui, ui.getSession().getService()));
return scope;
}
use of com.vaadin.flow.server.UIInitEvent in project flow by vaadin.
the class VaadinRouteScopeTest method detachUI_uiWithDifferentWindowName_beanInScopeIsDestroyedwhenUIIsDetached.
@Test
public void detachUI_uiWithDifferentWindowName_beanInScopeIsDestroyedwhenUIIsDetached() {
UI ui = mockUI();
UI anotherUI = makeAnotherUI(ui);
ExtendedClientDetails details = Mockito.mock(ExtendedClientDetails.class);
Mockito.when(details.getWindowName()).thenReturn("bar");
ui.getInternals().setExtendedClientDetails(details);
ui.getSession().addUI(ui);
ui.getSession().addUI(anotherUI);
mockServletContext(ui);
VaadinRouteScope scope = initScope(ui);
AtomicInteger count = new AtomicInteger();
scope.registerDestructionCallback("foo", () -> count.getAndIncrement());
scope.uiInit(new UIInitEvent(ui, ui.getSession().getService()));
navigateTo(ui, new NavigationTarget());
putObjectIntoScope(scope);
// close the first UI
ui.getSession().removeUI(ui);
// the bean is removed since there is no UI with the window name "bar"
// present.
Assert.assertEquals(1, count.get());
count.set(0);
UI.setCurrent(anotherUI);
scope = initScope(anotherUI);
navigateTo(anotherUI, new AnotherNavigationTarget());
// the bean is not removed since it's already has been removed when the
// first UI is detached.
Assert.assertEquals(0, count.get());
}
Aggregations