View Javadoc

1   /***
2    * Jetrix TetriNET Server
3    * Copyright (C) 2001-2003  Emmanuel Bourg
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18   */
19  
20  package net.jetrix;
21  
22  import junit.framework.*;
23  
24  import net.jetrix.config.*;
25  
26  /***
27   * JUnit TestCase for the class net.jetrix.ChannelManager.
28   *
29   * @author Emmanuel Bourg
30   * @version $Revision: 836 $, $Date: 2010-04-11 23:25:35 +0200 (dim., 11 avr. 2010) $
31   */
32  public class ChannelManagerTest extends TestCase
33  {
34      private ChannelManager manager;
35      private ChannelConfig config1;
36      private ChannelConfig config2;
37  
38      public void setUp()
39      {
40          manager = ChannelManager.getInstance();
41          manager.clear();
42  
43          config1 = new ChannelConfig();
44          config1.setName("test1");
45  
46          config2 = new ChannelConfig();
47          config2.setName("test2");
48      }
49  
50      public void tearDown()
51      {
52          manager.clear();
53      }
54  
55      public void testCreateChannel()
56      {
57          assertEquals("channel count before creation", 0, manager.getChannelCount());
58  
59          // add a test channel
60          manager.createChannel(config1, false);
61  
62          assertEquals("channel count after creation", 1, manager.getChannelCount());
63      }
64  
65      public void testGetChannel()
66      {
67          // add a test channel
68          String name = config1.getName();
69          manager.createChannel(config1, false);
70  
71          // retrieve the channel
72          Channel channel = manager.getChannel(name);
73          assertNotNull("channel not found", channel);
74          assertEquals("channel name", name, channel.getConfig().getName());
75      }
76  
77      public void testGetChannelSharp()
78      {
79          // add a test channel
80          String name = config1.getName();
81          manager.createChannel(config1, false);
82  
83          // retrieve the channel
84          Channel channel = manager.getChannel("#" + name);
85          assertNotNull("channel not found", channel);
86          assertEquals("channel name", name, channel.getConfig().getName());
87      }
88  
89      public void testGetChannelMixedCase()
90      {
91          // add a test channel
92          String name = config1.getName();
93          manager.createChannel(config1, false);
94  
95          // retrieve the channel
96          Channel channel = manager.getChannel("tEsT1");
97          assertNotNull("channel not found", channel);
98          assertEquals("channel name", name, channel.getConfig().getName());
99      }
100 
101     public void testGetChannelPartialName()
102     {
103         // add a test channel
104         config1.setName("xzyt");
105         manager.createChannel(config1, false);
106         manager.createChannel(config2, false);
107 
108         // retrieve the channel
109         Channel channel = manager.getChannel("test", true);
110         assertNotNull("channel not found", channel);
111         assertEquals("channel name", config2.getName(), channel.getConfig().getName());
112     }
113 
114     public void testGetChannelByNumber()
115     {
116         // add a test channel
117         String name = config1.getName();
118         manager.createChannel(config1, false);
119 
120         // retrieve the channel
121         Channel channel = manager.getChannel(0);
122         assertNotNull("channel not found", channel);
123         assertEquals("channel name", name, channel.getConfig().getName());
124 
125         Channel channel2 = manager.getChannel(1);
126         assertNull("channel found at index 1", channel2);
127     }
128 
129     public void testGetOpenedChannel()
130     {
131         // add a test channel
132         config1.setMaxPlayers(0);
133         manager.createChannel(config1, false);
134 
135         assertNull("closed channel returned", manager.getOpenedChannel());
136 
137         config1.setMaxPlayers(6);
138         assertNotNull("opened channel not found", manager.getOpenedChannel());
139     }
140 
141     public void testRemoveChannel()
142     {
143         // add a test channel
144         manager.createChannel(config1, false);
145 
146         assertEquals("channel count before removal", 1, manager.getChannelCount());
147         manager.removeChannel(config1.getName());
148         assertEquals("channel count after removal", 0, manager.getChannelCount());
149     }
150 
151 }