001 // Copyright 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.describe; 016 017 import static org.easymock.EasyMock.expect; 018 019 import org.apache.tapestry.IMarkupWriter; 020 import org.apache.tapestry.event.ReportStatusEvent; 021 import org.apache.tapestry.event.ReportStatusListener; 022 import org.testng.annotations.Test; 023 024 /** 025 * Tests for {@link org.apache.tapestry.describe.ReportStatusHubImpl}. 026 * 027 * @author Howard M. Lewis Ship 028 * @since 4.0 029 */ 030 @Test 031 public class ReportStatusHubTest extends BaseDescribeTestCase 032 { 033 private RootDescriptionReceiverFactory newReceiverFactory(IMarkupWriter writer, 034 RootDescriptionReciever receiver) 035 { 036 RootDescriptionReceiverFactory factory = newReceiverFactory(); 037 038 expect(factory.newRootDescriptionReceiver(writer)).andReturn(receiver); 039 040 return factory; 041 } 042 043 private RootDescriptionReceiverFactory newReceiverFactory() 044 { 045 return newMock(RootDescriptionReceiverFactory.class); 046 } 047 048 private static class ListenerFixture implements ReportStatusListener 049 { 050 051 public void reportStatus(ReportStatusEvent event) 052 { 053 event.title("Listener Invoked"); 054 } 055 056 } 057 058 public void testAddAndFire() 059 { 060 IMarkupWriter writer = newWriter(); 061 RootDescriptionReciever receiver = newRootReceiver(); 062 RootDescriptionReceiverFactory factory = newReceiverFactory(writer, receiver); 063 064 receiver.title("Listener Invoked"); 065 066 receiver.finishUp(); 067 068 replay(); 069 070 ReportStatusHubImpl hub = new ReportStatusHubImpl(); 071 072 hub.setReceiverFactory(factory); 073 074 hub.addReportStatusListener(new ListenerFixture()); 075 076 hub.fireReportStatus(writer); 077 078 verify(); 079 } 080 081 public void testRemove() 082 { 083 IMarkupWriter writer = newWriter(); 084 RootDescriptionReceiverFactory factory = newReceiverFactory(); 085 086 replay(); 087 088 ReportStatusHubImpl hub = new ReportStatusHubImpl(); 089 090 hub.setReceiverFactory(factory); 091 092 ListenerFixture listener = new ListenerFixture(); 093 hub.addReportStatusListener(listener); 094 hub.removeReportStatusListener(listener); 095 096 hub.fireReportStatus(writer); 097 098 verify(); 099 100 } 101 102 private RootDescriptionReciever newRootReceiver() 103 { 104 return newMock(RootDescriptionReciever.class); 105 } 106 }