1 /* 2 * Created on 21/Jan/04 3 * 4 * To change the template for this generated file go to 5 * Window>Preferences>Java>Code Generation>Code and Comments 6 */ 7 package replica.core; 8 9 import java.util.List; 10 11 import org.springframework.context.support.ClassPathXmlApplicationContext; 12 13 import replica.command.CommandProcessor; 14 import replica.group.Address; 15 import replica.group.GroupManager; 16 import replica.group.IpAddress; 17 import replica.group.event.GroupListener; 18 import replica.group.event.MessageEvent; 19 import replica.group.jgroups.JGroupsGroupManager; 20 import junit.framework.TestCase; 21 22 /*** 23 * @author no119431 24 * 25 * To change the template for this generated type comment go to 26 * Window>Preferences>Java>Code Generation>Code and Comments 27 */ 28 public class ApplicationGroupListenerTest extends TestCase { 29 30 /*** 31 * Constructor for ApplicationGroupListenerTest. 32 * @param arg0 33 */ 34 public ApplicationGroupListenerTest(String arg0) { 35 super(arg0); 36 } 37 38 public void testMessageFromDatabase() { 39 40 ApplicationGroupListener app = new ApplicationGroupListener(); 41 42 final ApplicationMessage appMsg = new ApplicationMessage(); 43 appMsg.setOriginator(ApplicationMessage.DATABASE_MODULE); 44 45 final MessageEvent evt = new MessageEvent(this, appMsg, new IpAddress()); 46 47 app.setServerCommandProcessor(new CommandProcessor(){ 48 public Object process(Object command){ 49 assertEquals(appMsg, evt.getMessage()); 50 return null; 51 } 52 }); 53 54 app.message(evt); 55 } 56 57 public void testMessageFromServer() { 58 59 ApplicationGroupListener app = new ApplicationGroupListener(); 60 61 final ApplicationMessage appMsg = new ApplicationMessage(); 62 appMsg.setOriginator(ApplicationMessage.SERVER_MODULE); 63 64 final MessageEvent evt = new MessageEvent(this, appMsg, new IpAddress()); 65 66 app.setDatabaseCommandProcessor(new CommandProcessor(){ 67 public Object process(Object command){ 68 assertEquals(appMsg, evt.getMessage()); 69 return null; 70 } 71 }); 72 73 app.message(evt); 74 } 75 76 public void testProcessDatabaseUpdateResult() { 77 78 ApplicationGroupListener app = new ApplicationGroupListener(); 79 80 final String ms = "test"; 81 final String ssID = "sessionId"; 82 83 app.setGroupManager(new GroupManager(){ 84 public void joinGroup(){} 85 public void leaveGroup(){} 86 public String getGroupName(){return null;} 87 public void setGroupName(String groupName){} 88 public List getGroupView(){return null;} 89 public void sendMessage(Address receiverAddress, Object message){ 90 assertEquals(ms, ((ApplicationMessage)message).getBody()); 91 assertEquals(ssID, ((ApplicationMessage)message).getSessionID()); 92 assertTrue( ((ApplicationMessage)message).isFromDatabase()); 93 } 94 public void sendMessage(Object message){} 95 public void addListener(GroupListener listener){} 96 public boolean removeListener( GroupListener listener){return false;} 97 public Address getLocalAddress(){return null;} 98 }); 99 100 app.processDatabaseUpdateResult(ssID, ms); 101 } 102 103 public void testAddAsListenerOnStart(){ 104 105 ClassPathXmlApplicationContext appCon = 106 new ClassPathXmlApplicationContext("replica/core/test-applicationContext.xml"); 107 108 JGroupsGroupManager gm = (JGroupsGroupManager)appCon.getBean("groupManager"); 109 110 assertEquals(1, gm.getGroupListeneres().size() ); 111 } 112 113 }

This page was automatically generated by Maven