use of javax.faces.component.UIViewRoot in project joinfaces by joinfaces.
the class ViewScope method remove.
@Override
public Object remove(String name) {
UIViewRoot viewRoot = getViewRoot();
Object bean = viewRoot.getViewMap().remove(name);
viewRoot.getViewListenersForEventClass(PreDestroyViewMapEvent.class).stream().filter(systemEventListener -> systemEventListener instanceof DestructionCallbackWrapper).map(systemEventListener -> (DestructionCallbackWrapper) systemEventListener).filter(destructionCallbackWrapper -> destructionCallbackWrapper.getBeanName().equals(name)).findFirst().ifPresent(destructionCallbackWrapper -> {
viewRoot.unsubscribeFromViewEvent(PreDestroyViewMapEvent.class, destructionCallbackWrapper);
getSessionHelper().unregister(destructionCallbackWrapper);
});
return bean;
}
use of javax.faces.component.UIViewRoot in project joinfaces by joinfaces.
the class JsfBeansAutoConfigurationTest method testViewMap.
@Test
public void testViewMap() {
UIViewRoot viewRoot = mock(UIViewRoot.class);
when(this.facesContext.getViewRoot()).thenReturn(viewRoot);
assertThat(this.jsfBeansAutoConfiguration.viewRoot()).isEqualTo(viewRoot);
Map<String, Object> map = Collections.emptyMap();
when(viewRoot.getViewMap()).thenReturn(map);
assertThat(this.jsfBeansAutoConfiguration.viewMap()).isSameAs(map);
}
use of javax.faces.component.UIViewRoot in project joinfaces by joinfaces.
the class ViewScopeTest method testRegisterDestructionCallback.
@Test
public void testRegisterDestructionCallback() {
SessionHelper sessionHelper = mock(SessionHelper.class);
when(this.beanFactory.getBean(SessionHelper.class)).thenReturn(sessionHelper);
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
doCallRealMethod().when(viewRoot).subscribeToViewEvent(any(), any());
doCallRealMethod().when(viewRoot).unsubscribeFromViewEvent(any(), any());
when(viewRoot.getViewListenersForEventClass(any())).thenCallRealMethod();
this.viewScope.registerDestructionCallback(KEY, () -> {
});
verify(viewRoot).subscribeToViewEvent(eq(PreDestroyViewMapEvent.class), any());
when(viewRoot.getListenersForEventClass(PreDestroyViewMapEvent.class)).thenReturn(Collections.singletonList(new DestructionCallbackWrapper(KEY, () -> {
})));
this.viewScope.remove(KEY);
verify(viewRoot).unsubscribeFromViewEvent(eq(PreDestroyViewMapEvent.class), any());
}
use of javax.faces.component.UIViewRoot in project ART-TIME by Artezio.
the class CustomOutputLabelRendererTest method testFindComponentInRoot.
@Test
public void testFindComponentInRoot() throws Exception {
renderer = createMockBuilder(CustomOutputLabelRenderer.class).addMockedMethod("findComponent", UIComponent.class, String.class).createMock();
FacesContext facesContext = createMock(FacesContext.class);
UIComponent component = createMock(UIComponent.class);
UIViewRoot viewRoot = createMock(UIViewRoot.class);
setField(renderer, "facesContext", facesContext);
expect(facesContext.getViewRoot()).andReturn(viewRoot);
expect(renderer.findComponent(viewRoot, "id")).andReturn(component);
replay(facesContext, renderer);
UIComponent actual = renderer.findComponentInRoot("id");
verify(facesContext, renderer);
assertSame(component, actual);
}
use of javax.faces.component.UIViewRoot in project ART-TIME by Artezio.
the class CalendarUtilsTest method testGetLocale_ifFacesContextNotNull.
@Test
public void testGetLocale_ifFacesContextNotNull() {
FacesContext facesContext = createMock(FacesContext.class);
UIViewRoot viewRoot = createMock(UIViewRoot.class);
PowerMock.mockStatic(Locale.class);
PowerMock.mockStatic(FacesContext.class);
expect(FacesContext.getCurrentInstance()).andReturn(facesContext);
expect(facesContext.getViewRoot()).andReturn(viewRoot);
expect(viewRoot.getLocale()).andReturn(Locale.CANADA);
PowerMock.replayAll(FacesContext.class, facesContext, viewRoot);
Locale actual = CalendarUtils.getLocale();
PowerMock.verifyAll();
assertEquals(Locale.CANADA, actual);
}
Aggregations