001: // $Id: ViewTest.java,v 1.5.2.1 2006/12/19 09:36:45 belaban Exp $
002:
003: package org.jgroups.tests;
004:
005: import junit.framework.TestCase;
006: import org.jgroups.View;
007: import org.jgroups.ViewId;
008: import org.jgroups.stack.IpAddress;
009:
010: import java.util.Vector;
011:
012: public class ViewTest extends TestCase {
013: IpAddress a, b, c, d, e, f, g, h, i, j, k;
014: View view;
015: Vector members;
016:
017: public ViewTest(String Name_) {
018: super (Name_);
019: }
020:
021: public void setUp() throws Exception {
022: super .setUp();
023: a = new IpAddress("localhost", 5555);
024: b = new IpAddress("localhost", 5555);
025: c = b;
026: d = new IpAddress("localhost", 5556);
027: e = new IpAddress("127.0.0.1", 5555);
028: f = new IpAddress("www.ibm.com", 80);
029: g = new IpAddress("www.ibm.com", 8080);
030: h = new IpAddress("224.0.0.1", 5555);
031: i = new IpAddress("224.0.0.2", 5555);
032: ViewId id = new ViewId(a, 34);
033: members = new java.util.Vector();
034: members.addElement(a);
035: members.addElement(b);
036: members.addElement(d);
037: members.addElement(e);
038: members.addElement(f);
039: members.addElement(g);
040: members.addElement(h);
041: view = new View(id, members);
042:
043: }
044:
045: public void testContainsMember() {
046: assertTrue("Member should be in view", view.containsMember(a));
047: assertTrue("Member should be in view", view.containsMember(b));
048: assertTrue("Member should be in view", view.containsMember(c));
049: assertTrue("Member should be in view", view.containsMember(d));
050: assertTrue("Member should be in view", view.containsMember(e));
051: assertTrue("Member should be in view", view.containsMember(f));
052: assertTrue("Member should not be in view", !view
053: .containsMember(i));
054: }
055:
056: public void testEqualsCreator() {
057: assertEquals("Creator should be a:", view.getCreator(), a);
058: assertTrue("Creator should not be d", !view.getCreator()
059: .equals(d));
060: }
061:
062: public void testEquals() {
063: assertEquals(view, view);
064: }
065:
066: public void testEquals2() {
067: View v1 = new View(new ViewId(a, 12345), (Vector) members
068: .clone());
069: View v2 = new View(a, 12345, (Vector) members.clone());
070: assertEquals(v1, v2);
071: View v3 = new View(a, 12543, (Vector) members.clone());
072: assertFalse(v1.equals(v3));
073: }
074:
075: public void testEquals3() {
076: View v1, v2;
077: v1 = new View();
078: v2 = new View();
079: assertEquals(v1, v2);
080: }
081:
082: public void tearDown() throws Exception {
083: a = null;
084: b = null;
085: c = null;
086: d = null;
087: e = null;
088: f = null;
089: g = null;
090: h = null;
091: i = null;
092: view = null;
093: super .tearDown();
094: }
095:
096: public static void main(String[] args) {
097: String[] testCaseName = { ViewTest.class.getName() };
098: junit.textui.TestRunner.main(testCaseName);
099: } //public static void main(String[] args)
100:
101: } //public class ViewTest extends TestCase
|