1   /*** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * 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   **/
18  package org.activecluster.group;
19  
20  import junit.framework.TestCase;
21  import org.activecluster.Cluster;
22  import org.activecluster.ClusterEvent;
23  import org.activecluster.ClusterListener;
24  import org.activecluster.Node;
25  import org.activecluster.impl.NodeImpl;
26  import org.activemq.message.ActiveMQQueue;
27  
28  import java.util.HashMap;
29  import java.util.Map;
30  
31  /***
32   * A base class for Group model testing
33   *
34   * @version $Revision: 1.3 $
35   */
36  public abstract class GroupTestSupport extends TestCase {
37  
38      protected GroupModel model;
39      private ClusterListener listener;
40      private Cluster cluster;
41      private Map nodes = new HashMap();
42  
43      protected void addNodes(String[] nodeNames) {
44          for (int i = 0; i < nodeNames.length; i++) {
45              String nodeName = nodeNames[i];
46              addNode(nodeName);
47          }
48      }
49  
50      protected void addNode(String nodeName) {
51          Node node = new NodeImpl(new ActiveMQQueue(nodeName));
52          nodes.put(nodeName, node);
53          listener.onNodeAdd(new ClusterEvent(cluster, node, ClusterEvent.ADD_NODE));
54      }
55  
56      protected void assertFull(Group group) {
57          assertTrue("Group is not full and usable. Members: " + group.getMembers(), group.isFull() && group.isUsable());
58      }
59  
60      protected void assertNotFullButUsable(Group group) {
61          assertTrue("Group is not not full but usable. Members: " + group.getMembers(), !group.isFull() && group.isUsable());
62      }
63  
64      protected void assertIncomplete(Group group) {
65          assertTrue("Group is not not full or usable. Members: " + group.getMembers(), !group.isFull() && !group.isUsable());
66      }
67  
68      protected void assertUsable(Group group) {
69          assertTrue("Group is not usable. Members: " + group.getMembers(), group.isUsable());
70      }
71  
72      protected void setUp() throws Exception {
73          model = createGroupModel();
74          listener = new GroupClusterListener(model);
75      }
76  
77      protected GroupModel createGroupModel() {
78          return new GroupModel();
79      }
80  }