// Test event queuing and dequeuing during broadcasting public void testEventBroadcasting() { // Register a listener that will conditionally queue a new event UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); root.addFacesListener(new TestListener("t", "2", "4")); TestListener.trace(null); // Queue some events, including the trigger one TestEvent event = new TestEvent(root, "1"); event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES); root.queueEvent(event); event = new TestEvent(root, "2"); event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES); root.queueEvent(event); event = new TestEvent(root, "3"); event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES); root.queueEvent(event); // Simulate the Apply Request Values phase root.processDecodes(facesContext); // Validate the results (expect 4th event to also be queued) String expected = "/t/1/t/2/t/3/t/4"; assertEquals(expected, TestListener.trace()); }
private void checkEventQueueing(PhaseId phaseId) { // NOTE: Current semantics for ANY_PHASE listeners is that // the event should be delivered exactly once, so the existence // of such a listener does not cause the event to remain queued. // Therefore, the expected string is the same as for any // phase-specific listener, and it should get matched after // Apply Request Values processing since that is first phase // for which events are fired // Register an event listener for the specified phase id UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); TestEvent event = null; TestListener listener = new TestListener("t"); root.addFacesListener(listener); // Queue some events to be processed event = new TestEvent(root, "1"); event.setPhaseId(phaseId); root.queueEvent(event); event = new TestEvent(root, "2"); event.setPhaseId(phaseId); root.queueEvent(event); String expected = "/t/1/t/2"; // Fire off the relevant lifecycle methods and check expected results TestListener.trace(null); assertEquals("", TestListener.trace()); root.processDecodes(facesContext); if (PhaseId.APPLY_REQUEST_VALUES.equals(phaseId) || PhaseId.ANY_PHASE.equals(phaseId)) { assertEquals(expected, TestListener.trace()); } else { assertEquals("", TestListener.trace()); } root.processValidators(facesContext); if (PhaseId.PROCESS_VALIDATIONS.equals(phaseId) || PhaseId.APPLY_REQUEST_VALUES.equals(phaseId) || PhaseId.APPLY_REQUEST_VALUES.equals(phaseId) || PhaseId.ANY_PHASE.equals(phaseId)) { assertEquals(expected, TestListener.trace()); } else { assertEquals("", TestListener.trace()); } root.processUpdates(facesContext); if (PhaseId.UPDATE_MODEL_VALUES.equals(phaseId) || PhaseId.PROCESS_VALIDATIONS.equals(phaseId) || PhaseId.APPLY_REQUEST_VALUES.equals(phaseId) || PhaseId.ANY_PHASE.equals(phaseId)) { assertEquals(expected, TestListener.trace()); } else { assertEquals("", TestListener.trace()); } root.processApplication(facesContext); assertEquals(expected, TestListener.trace()); }
// Test AbortProcessingException support public void testAbortProcessingException() { // Register three listeners, with the second one set to abort UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null); facesContext.setViewRoot(root); root.addFacesListener(new TestListener("a", false)); root.addFacesListener(new TestListener("b", true)); root.addFacesListener(new TestListener("c", false)); // Queue two event and check the results TestListener.trace(null); TestEvent event1 = new TestEvent(root, "1"); event1.setPhaseId(PhaseId.APPLY_REQUEST_VALUES); root.queueEvent(event1); TestEvent event2 = new TestEvent(root, "2"); event2.setPhaseId(PhaseId.APPLY_REQUEST_VALUES); root.queueEvent(event2); root.processDecodes(facesContext); assertEquals("/a/1/b/1/a/2/b/2", TestListener.trace()); }