1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.cluster;
18
19 import junit.framework.Test;
20 import junit.framework.TestSuite;
21
22 import org.apache.jetspeed.components.util.DatasourceEnabledSpringTestCase;
23
24 /***
25 * <p>
26 * TestCluster
27 * </p>
28 *
29 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
30 * @version $Id: TestCluster.java 463270 2006-10-12 15:19:29Z taylor $
31 *
32 */
33 public class TestCluster extends DatasourceEnabledSpringTestCase
34 {
35
36 /*** The node manager. */
37 private NodeManager single;
38
39 /***
40 * @see junit.framework.TestCase#setUp()
41 */
42 public void setUp() throws Exception
43 {
44 System.setProperty("applicationRoot","target/jetspeed");
45 super.setUp();
46
47 single = (NodeManager) ctx.getBean("org.apache.jetspeed.cluster.NodeManager");
48 }
49
50 public static Test suite()
51 {
52
53 return new TestSuite(TestCluster.class);
54 }
55
56 /*** Test set user info map. * */
57 public void testCluser() throws Exception
58 {
59 String contextName = "SOME_NEW_PORTLET_APPLICATION";
60 Long id = new Long(10);
61
62 assertNotNull("Manager should be instantiated", single);
63
64 int numExistingApps = single.getNumberOfNodes();
65
66
67 int status = single.checkNode(id, contextName);
68 if (status != NodeManager.NODE_NEW)
69 {
70 single.removeNode(contextName);
71 status = single.checkNode(id, contextName);
72 assertEquals("Should be a new node",NodeManager.NODE_NEW,status);
73 }
74
75
76 single.addNode(id, contextName);
77 int newApps = single.getNumberOfNodes();
78
79 assertEquals("Should have added new node",newApps, numExistingApps+1);
80
81 status = single.checkNode(id, contextName);
82 assertEquals("Should be a current (saved) node",NodeManager.NODE_SAVED,status);
83
84 id = new Long(20);
85 status = single.checkNode(id, contextName);
86 assertEquals("Should be an outdated node",NodeManager.NODE_OUTDATED,status);
87
88 single.addNode(id, contextName);
89 status = single.checkNode(id, contextName);
90 assertEquals("Should be again a current (saved) node",NodeManager.NODE_SAVED,status);
91
92 id = new Long(10);
93 status = single.checkNode(id, contextName);
94 assertEquals("Should still be a current (saved) node",NodeManager.NODE_SAVED,status);
95
96 single.removeNode(contextName);
97 status = single.checkNode(id, contextName);
98 assertEquals("Node should be gone....",NodeManager.NODE_NEW,status);
99 }
100 protected String[] getConfigurations()
101 {
102 return new String[]
103 { "system-properties.xml", "cluster-node.xml"};
104 }
105
106 }