UIViewRoot extends UIComponentBase implements UniqueIdVendor { public Map<String, Object> getViewMap() { return getViewMap(true); } UIViewRoot(); @Override boolean isInView(); @Override void setInView(boolean isInView); @Override String getFamily(); String getRenderKitId(); void setRenderKitId(String renderKitId); String getViewId(); void setViewId(String viewId); MethodExpression getBeforePhaseListener(); void setBeforePhaseListener(MethodExpression newBeforePhase); MethodExpression getAfterPhaseListener(); void setAfterPhaseListener(MethodExpression newAfterPhase); void removePhaseListener(PhaseListener toRemove); void addPhaseListener(PhaseListener newPhaseListener); @SuppressWarnings("unchecked") List<PhaseListener> getPhaseListeners(); void addComponentResource(FacesContext context, UIComponent componentResource); void addComponentResource(FacesContext context, UIComponent componentResource, String target); List<UIComponent> getComponentResources(FacesContext context, 
                                                   String target); List<UIComponent> getComponentResources(FacesContext context); void removeComponentResource(FacesContext context, UIComponent componentResource); void removeComponentResource(FacesContext context, UIComponent componentResource, String target); @Override void queueEvent(FacesEvent event); void broadcastEvents(FacesContext context, PhaseId phaseId); @Override void processRestoreState(FacesContext context, Object state); @Override void processEvent(ComponentSystemEvent event); @Override void processDecodes(FacesContext context); void resetValues(FacesContext context, Collection<String> clientIds); @Override void encodeBegin(FacesContext context); @Override void encodeChildren(FacesContext context); @Override void encodeEnd(FacesContext context); @Override boolean getRendersChildren(); @Override void processValidators(FacesContext context); @Override void processUpdates(FacesContext context); void processApplication(FacesContext context); String createUniqueId(); @Override String createUniqueId(FacesContext context, String seed); Locale getLocale(); void setLocale(Locale locale); Map<String, Object> getViewMap(); @SuppressWarnings("unchecked") Map<String, Object> getViewMap(boolean create); void subscribeToViewEvent(Class<? extends SystemEvent> systemEvent,
                                     SystemEventListener listener); void unsubscribeFromViewEvent(Class<? extends SystemEvent> systemEvent,
                                         SystemEventListener listener); List<SystemEventListener> getViewListenersForEventClass(Class<? extends SystemEvent> systemEvent); void restoreViewScopeState(FacesContext context, Object state); @Override Object saveState(FacesContext context); @Override @SuppressWarnings("unchecked") void restoreState(FacesContext context, Object state); static final String METADATA_FACET_NAME; static final String VIEW_PARAMETERS_KEY; static final String COMPONENT_TYPE; static final String COMPONENT_FAMILY; static final String VIEWROOT_PHASE_LISTENER_QUEUES_EXCEPTIONS_PARAM_NAME; static final String UNIQUE_ID_PREFIX; }
@Test public void testViewMapPostConstructViewMapEvent() { FacesContext facesContext = EasyMock.createMock(FacesContext.class); Application application = EasyMock.createMock(Application.class); ExternalContext externalContext = EasyMock.createMock(ExternalContext.class); HttpSession httpSession = EasyMock.createMock(HttpSession.class); setFacesContext(facesContext); expect(facesContext.getExternalContext()).andReturn(externalContext).anyTimes(); expect(externalContext.getApplicationMap()).andReturn(null).anyTimes(); replay(facesContext, externalContext); UIViewRoot viewRoot = new UIViewRoot(); verify(facesContext, externalContext); reset(facesContext, externalContext); expect(facesContext.getApplication()).andReturn(application).anyTimes(); expect(application.getProjectStage()).andReturn(ProjectStage.UnitTest); application.publishEvent(facesContext, PostConstructViewMapEvent.class, UIViewRoot.class, viewRoot); replay(facesContext, application, externalContext, httpSession); Map<String, Object> viewMap = viewRoot.getViewMap(); assertNotNull(viewMap); verify(facesContext, application, externalContext, httpSession); setFacesContext(null); }
@Test public void testViewMapPreDestroyViewMapEvent() { FacesContext facesContext = EasyMock.createMock(FacesContext.class); Application application = EasyMock.createMock(Application.class); ExternalContext externalContext = EasyMock.createMock(ExternalContext.class); HttpSession httpSession = EasyMock.createMock(HttpSession.class); setFacesContext(facesContext); expect(facesContext.getExternalContext()).andReturn(externalContext).anyTimes(); expect(externalContext.getApplicationMap()).andReturn(null).anyTimes(); replay(facesContext, externalContext); UIViewRoot viewRoot = new UIViewRoot(); verify(facesContext, externalContext); reset(facesContext, externalContext); expect(facesContext.getApplication()).andReturn(application).anyTimes(); expect(application.getProjectStage()).andReturn(ProjectStage.UnitTest); application.publishEvent(facesContext, PostConstructViewMapEvent.class, UIViewRoot.class, viewRoot); expect(facesContext.getViewRoot()).andReturn(viewRoot); application.publishEvent(facesContext, PreDestroyViewMapEvent.class, UIViewRoot.class, viewRoot); expect(facesContext.getViewRoot()).andReturn(viewRoot); application.publishEvent(facesContext, PreDestroyViewMapEvent.class, UIViewRoot.class, viewRoot); replay(facesContext, application, externalContext, httpSession); Map<String, Object> viewMap = viewRoot.getViewMap(); assertNotNull(viewMap); viewRoot.getViewMap().clear(); viewRoot.getViewMap().clear(); verify(facesContext, application, externalContext, httpSession); setFacesContext(null); }