1 37 package net.sourceforge.cruisecontrol.publishers; 38 39 import junit.framework.TestCase; 40 import net.sourceforge.cruisecontrol.CruiseControlException; 41 import com.jpeterson.x10.module.CM11A; 42 import com.jpeterson.x10.module.CM17A; 43 44 public class X10PublisherTest extends TestCase { 45 46 77 public void testSettingAPort() { 78 X10Publisher x10Publisher = new X10Publisher(); 79 x10Publisher.setDeviceCode("3"); 80 x10Publisher.setHouseCode("A"); 81 x10Publisher.setPort("COM1"); 82 x10Publisher.setPort("THIS_ISN'T_A_REAL_PORT"); 85 } 86 87 public void testRequiredFieldValidation() throws CruiseControlException { 88 X10Publisher x10Publisher = new X10Publisher(); 89 90 try { 91 x10Publisher.validate(); 92 fail("Should have gotten an exception when " 93 + "required fields left blank."); 94 } catch (CruiseControlException e) { 95 assertTrue("Expected this exception.", true); 96 } 97 98 x10Publisher.setHouseCode("A"); 99 x10Publisher.setDeviceCode("3"); 100 101 x10Publisher.validate(); 102 } 103 104 public void testHouseCodeValidation() throws CruiseControlException { 105 X10Publisher x10Publisher = new X10Publisher(); 106 107 x10Publisher.setDeviceCode("3"); x10Publisher.setHouseCode(null); try { 110 x10Publisher.validate(); 111 fail("Should have gotten an exception when house code set to null"); 112 } catch (CruiseControlException e) { 113 assertTrue("Expected this exception.", true); 114 } 115 116 x10Publisher.setHouseCode(""); try { 118 x10Publisher.validate(); 119 fail("Should have gotten an exception when " 120 + "house code set to blank"); 121 } catch (CruiseControlException e) { 122 assertTrue("Expected this exception.", true); 123 } 124 125 x10Publisher.setHouseCode("1"); try { 127 x10Publisher.validate(); 128 fail("Should have gotten an exception when house code" 129 + " set to a number"); 130 } catch (CruiseControlException e) { 131 assertTrue("Expected this exception.", true); 132 } 133 134 x10Publisher.setHouseCode("AA"); try { 136 x10Publisher.validate(); 137 fail("Should have gotten an exception when house code set " 138 + "to more than one character"); 139 } catch (CruiseControlException e) { 140 assertTrue("Expected this exception.", true); 141 } 142 143 String [] illegalHouseCodes = {"Q", "R", "S", "T", "U", "V", "W", "X", 144 "Y", "Z"}; 145 for (int i = 0; i < illegalHouseCodes.length; i++) { 146 String nextHouseCode = illegalHouseCodes[ i ]; 147 x10Publisher.setHouseCode(nextHouseCode); try { 149 x10Publisher.validate(); 150 fail("Should have gotten an exception when house code set to " 151 + nextHouseCode); 152 } catch (CruiseControlException e) { 153 assertTrue("Expected this exception.", true); 154 } 155 } 156 157 String [] legalHouseCodes = {"A", "B", "C", "D", "E", "F", "G", "H", 158 "I", "J", "K", "L", "M", "N", "O", "P"}; 159 for (int i = 0; i < legalHouseCodes.length; i++) { 160 String nextHouseCode = legalHouseCodes[ i ]; 161 x10Publisher.setHouseCode(nextHouseCode); x10Publisher.validate(); 163 } 164 165 String [] lowerCaseLegalHouseCodes = {"a", "b", "c", "d", "e", "f", "g", 166 "h", "i", "j", "k", "l", "m", "n", 167 "o", "p"}; 168 for (int i = 0; i < lowerCaseLegalHouseCodes.length; i++) { 169 String nextHouseCode = lowerCaseLegalHouseCodes[ i ]; 170 x10Publisher.setHouseCode(nextHouseCode); x10Publisher.validate(); 172 } 173 } 174 175 public void testDeviceCodeValidation() throws CruiseControlException { 176 X10Publisher x10Publisher = new X10Publisher(); 177 178 x10Publisher.setHouseCode("A"); x10Publisher.setDeviceCode(null); try { 181 x10Publisher.validate(); 182 fail("Should have gotten an exception when device" 183 + " code set to null"); 184 } catch (CruiseControlException e) { 185 assertTrue("Expected this exception.", true); 186 } 187 188 x10Publisher.setDeviceCode(""); try { 190 x10Publisher.validate(); 191 fail("Should have gotten an exception when device" 192 + " code set to blank"); 193 } catch (CruiseControlException e) { 194 assertTrue("Expected this exception.", true); 195 } 196 197 x10Publisher.setDeviceCode("A"); try { 199 x10Publisher.validate(); 200 fail("Should have gotten an exception when device code" 201 + " set to an alphabetic character"); 202 } catch (CruiseControlException e) { 203 assertTrue("Expected this exception.", true); 204 } 205 206 String [] legalDeviceCodes = {"1", "2", "3", "4", "5", "6", "7", "8", 207 "9", "10", "11", "12", "13", "14", "15", 208 "16"}; 209 for (int i = 0; i < legalDeviceCodes.length; i++) { 210 String nextDeviceCode = legalDeviceCodes[ i ]; 211 x10Publisher.setDeviceCode(nextDeviceCode); x10Publisher.validate(); 213 } 214 215 String [] illegalDeviceCodes = {"-1", "17", "0", "-100", "1.1", "1.56", 216 "13.00000000000000000001"}; 217 for (int i = 0; i < illegalDeviceCodes.length; i++) { 218 String nextDeviceCode = illegalDeviceCodes[ i ]; 219 x10Publisher.setDeviceCode(nextDeviceCode); try { 221 x10Publisher.validate(); 222 fail("Should have gotten an exception when" 223 + " the device code is set to " 224 + nextDeviceCode); 225 } catch (CruiseControlException e) { 226 assertTrue("Expected this exception", true); 227 } 228 } 229 } 230 231 public void testInterfaceModelValidation() throws CruiseControlException { 232 X10Publisher x10Publisher = new X10Publisher(); 233 234 x10Publisher.setHouseCode("A"); x10Publisher.setDeviceCode("3"); x10Publisher.setInterfaceModel(null); x10Publisher.validate(); 238 239 x10Publisher.setInterfaceModel("CM11A"); x10Publisher.validate(); 241 242 x10Publisher.setInterfaceModel("CM17A"); x10Publisher.validate(); 244 245 x10Publisher.setInterfaceModel(""); x10Publisher.validate(); 247 248 x10Publisher.setInterfaceModel("cm11a"); x10Publisher.validate(); 250 251 x10Publisher.setInterfaceModel("cm17a"); x10Publisher.validate(); 253 254 x10Publisher.setInterfaceModel("cM11A"); x10Publisher.validate(); 256 257 x10Publisher.setInterfaceModel("cM17A"); x10Publisher.validate(); 259 260 x10Publisher.setInterfaceModel("jibberish"); try { 262 x10Publisher.validate(); 263 fail("Expected an exception"); 264 } catch (CruiseControlException e) { 265 assertTrue("Expected this exception", true); 266 } 267 268 x10Publisher.setInterfaceModel("firecraker"); try { 270 x10Publisher.validate(); 271 fail("Expected an exception"); 272 } catch (CruiseControlException e) { 273 assertTrue("Expected this exception", true); 274 } 275 } 276 277 public void testGetTransmitter() throws CruiseControlException { 278 X10Publisher x10Publisher = new X10Publisher(); 279 280 x10Publisher.setHouseCode("A"); x10Publisher.setDeviceCode("3"); 283 x10Publisher.setInterfaceModel(null); assertTrue(x10Publisher.getTransmitter() instanceof CM11A); 285 286 x10Publisher.setInterfaceModel(""); assertTrue(x10Publisher.getTransmitter() instanceof CM11A); 288 289 x10Publisher.setInterfaceModel("cm11a"); assertTrue(x10Publisher.getTransmitter() instanceof CM11A); 291 292 x10Publisher.setInterfaceModel("cm11A"); assertTrue(x10Publisher.getTransmitter() instanceof CM11A); 294 295 x10Publisher.setInterfaceModel("cm17a"); assertTrue(x10Publisher.getTransmitter() instanceof CM17A); 297 298 x10Publisher.setInterfaceModel("cm17A"); assertTrue(x10Publisher.getTransmitter() instanceof CM17A); 300 } 301 } 302 | Popular Tags |