1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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          // All methods starting with "test" will be executed in the test suite.
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          //create a new node
67          int status = single.checkNode(id, contextName);
68          if (status != NodeManager.NODE_NEW)
69          {
70          	single.removeNode(contextName); //previous run didn't clean up
71          	status = single.checkNode(id, contextName);
72              assertEquals("Should be a new node",NodeManager.NODE_NEW,status);
73          }
74          
75          // ok - create a new node
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); //previous run didn't clean up
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 }