001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.cluster;
018:
019: import junit.framework.Test;
020: import junit.framework.TestSuite;
021:
022: import org.apache.jetspeed.components.util.DatasourceEnabledSpringTestCase;
023:
024: /**
025: * <p>
026: * TestCluster
027: * </p>
028: *
029: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
030: * @version $Id: TestCluster.java 463270 2006-10-12 15:19:29Z taylor $
031: *
032: */
033: public class TestCluster extends DatasourceEnabledSpringTestCase {
034:
035: /** The node manager. */
036: private NodeManager single;
037:
038: /**
039: * @see junit.framework.TestCase#setUp()
040: */
041: public void setUp() throws Exception {
042: System.setProperty("applicationRoot", "target/jetspeed");
043: super .setUp();
044:
045: single = (NodeManager) ctx
046: .getBean("org.apache.jetspeed.cluster.NodeManager");
047: }
048:
049: public static Test suite() {
050: // All methods starting with "test" will be executed in the test suite.
051: return new TestSuite(TestCluster.class);
052: }
053:
054: /** Test set user info map. * */
055: public void testCluser() throws Exception {
056: String contextName = "SOME_NEW_PORTLET_APPLICATION";
057: Long id = new Long(10);
058:
059: assertNotNull("Manager should be instantiated", single);
060:
061: int numExistingApps = single.getNumberOfNodes();
062:
063: //create a new node
064: int status = single.checkNode(id, contextName);
065: if (status != NodeManager.NODE_NEW) {
066: single.removeNode(contextName); //previous run didn't clean up
067: status = single.checkNode(id, contextName);
068: assertEquals("Should be a new node", NodeManager.NODE_NEW,
069: status);
070: }
071:
072: // ok - create a new node
073: single.addNode(id, contextName);
074: int newApps = single.getNumberOfNodes();
075:
076: assertEquals("Should have added new node", newApps,
077: numExistingApps + 1);
078:
079: status = single.checkNode(id, contextName);
080: assertEquals("Should be a current (saved) node",
081: NodeManager.NODE_SAVED, status);
082:
083: id = new Long(20);
084: status = single.checkNode(id, contextName);
085: assertEquals("Should be an outdated node",
086: NodeManager.NODE_OUTDATED, status);
087:
088: single.addNode(id, contextName);
089: status = single.checkNode(id, contextName);
090: assertEquals("Should be again a current (saved) node",
091: NodeManager.NODE_SAVED, status);
092:
093: id = new Long(10);
094: status = single.checkNode(id, contextName);
095: assertEquals("Should still be a current (saved) node",
096: NodeManager.NODE_SAVED, status);
097:
098: single.removeNode(contextName); //previous run didn't clean up
099: status = single.checkNode(id, contextName);
100: assertEquals("Node should be gone....", NodeManager.NODE_NEW,
101: status);
102: }
103:
104: protected String[] getConfigurations() {
105: return new String[] { "system-properties.xml",
106: "cluster-node.xml" };
107: }
108:
109: }
|