KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > tests > ViewTest


1 // $Id: ViewTest.java,v 1.1 2007/07/04 07:29:34 belaban Exp $
2

3 package org.jgroups.tests;
4
5
6 import junit.framework.TestCase;
7 import org.jgroups.View;
8 import org.jgroups.ViewId;
9 import org.jgroups.stack.IpAddress;
10
11 import java.util.Vector JavaDoc;
12
13
14 public class ViewTest extends TestCase {
15     IpAddress a, b, c, d, e, f, g, h, i, j, k;
16     View view;
17     Vector JavaDoc members;
18     
19
20     public ViewTest(String JavaDoc Name_) {
21         super(Name_);
22     }
23
24     public void setUp() throws Exception JavaDoc {
25         super.setUp();
26         a=new IpAddress("localhost", 5555);
27         b=new IpAddress("localhost", 5555);
28         c=b;
29         d=new IpAddress("localhost", 5556);
30         e=new IpAddress("127.0.0.1", 5555);
31         f=new IpAddress("www.ibm.com", 80);
32         g=new IpAddress("www.ibm.com", 8080);
33         h=new IpAddress("224.0.0.1", 5555);
34         i=new IpAddress("224.0.0.2", 5555);
35         ViewId id=new ViewId(a, 34);
36         members=new java.util.Vector JavaDoc();
37         members.addElement(a);
38         members.addElement(b);
39         members.addElement(d);
40         members.addElement(e);
41         members.addElement(f);
42         members.addElement(g);
43         members.addElement(h);
44         view=new View(id, members);
45
46     }
47
48     public void testContainsMember() {
49         assertTrue("Member should be in view", view.containsMember(a));
50         assertTrue("Member should be in view", view.containsMember(b));
51         assertTrue("Member should be in view", view.containsMember(c));
52         assertTrue("Member should be in view", view.containsMember(d));
53         assertTrue("Member should be in view", view.containsMember(e));
54         assertTrue("Member should be in view", view.containsMember(f));
55         assertTrue("Member should not be in view", !view.containsMember(i));
56     }
57
58     public void testEqualsCreator() {
59         assertEquals("Creator should be a:", view.getCreator(), a);
60         assertTrue("Creator should not be d", !view.getCreator().equals(d));
61     }
62
63     public void testEquals() {
64         assertEquals(view, view);
65     }
66
67     public void testEquals2() {
68         View v1=new View(new ViewId(a, 12345), (Vector JavaDoc)members.clone());
69         View v2=new View(a, 12345, (Vector JavaDoc)members.clone());
70         assertEquals(v1, v2);
71         View v3=new View(a, 12543, (Vector JavaDoc)members.clone());
72         assertFalse(v1.equals(v3));
73     }
74
75
76     public void testEquals3() {
77         View v1, v2;
78         v1=new View();
79         v2=new View();
80         assertEquals(v1, v2);
81     }
82
83     public void tearDown() throws Exception JavaDoc {
84         a=null;
85         b=null;
86         c=null;
87         d=null;
88         e=null;
89         f=null;
90         g=null;
91         h=null;
92         i=null;
93         view=null;
94         super.tearDown();
95     }
96
97     public static void main(String JavaDoc[] args) {
98         String JavaDoc[] testCaseName={ViewTest.class.getName()};
99         junit.textui.TestRunner.main(testCaseName);
100     } //public static void main(String[] args)
101

102 } //public class ViewTest extends TestCase
103
Popular Tags