Search in sources :

Example 31 with UIViewRoot

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;
}
Also used : UIViewRoot(javax.faces.component.UIViewRoot) ObjectFactory(org.springframework.beans.factory.ObjectFactory) RequestContextHolder(org.springframework.web.context.request.RequestContextHolder) PreDestroyViewMapEvent(javax.faces.event.PreDestroyViewMapEvent) FacesContext(javax.faces.context.FacesContext) BeanFactory(org.springframework.beans.factory.BeanFactory) RequiredArgsConstructor(lombok.RequiredArgsConstructor) NonNull(org.springframework.lang.NonNull) RequestAttributes(org.springframework.web.context.request.RequestAttributes) Scope(org.springframework.beans.factory.config.Scope) UIViewRoot(javax.faces.component.UIViewRoot)

Example 32 with UIViewRoot

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);
}
Also used : UIViewRoot(javax.faces.component.UIViewRoot) Test(org.junit.Test)

Example 33 with UIViewRoot

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());
}
Also used : PreDestroyViewMapEvent(javax.faces.event.PreDestroyViewMapEvent) UIViewRoot(javax.faces.component.UIViewRoot) Test(org.junit.Test)

Example 34 with UIViewRoot

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);
}
Also used : FacesContext(javax.faces.context.FacesContext) UIComponent(javax.faces.component.UIComponent) UIViewRoot(javax.faces.component.UIViewRoot) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 35 with UIViewRoot

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);
}
Also used : Locale(java.util.Locale) FacesContext(javax.faces.context.FacesContext) UIViewRoot(javax.faces.component.UIViewRoot) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

UIViewRoot (javax.faces.component.UIViewRoot)41 FacesContext (javax.faces.context.FacesContext)18 Test (org.junit.Test)10 ViewHandler (javax.faces.application.ViewHandler)8 Locale (java.util.Locale)6 ResourceBundle (java.util.ResourceBundle)4 Application (javax.faces.application.Application)3 UIComponent (javax.faces.component.UIComponent)3 ViewConfigDescriptor (org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Map (java.util.Map)2 ExternalContext (javax.faces.context.ExternalContext)2 FacesContextFactory (javax.faces.context.FacesContextFactory)2 PreDestroyViewMapEvent (javax.faces.event.PreDestroyViewMapEvent)2 LifecycleFactory (javax.faces.lifecycle.LifecycleFactory)2 ServletContext (javax.servlet.ServletContext)2 NonNull (org.springframework.lang.NonNull)2 Handler (com.sun.jsftemplating.annotation.Handler)1 ModuleException (it.vige.rubia.ModuleException)1 ToHTMLConfig (it.vige.rubia.format.render.bbcodehtml.ToHTMLConfig)1