1 19 20 package org.netbeans.core.windows.persistence; 21 22 import java.awt.Frame ; 23 import java.io.FileNotFoundException ; 24 import java.io.IOException ; 25 import java.net.URL ; 26 import java.util.HashSet ; 27 import java.util.Map ; 28 import java.util.Set ; 29 30 import org.netbeans.junit.NbTest; 31 import org.netbeans.junit.NbTestCase; 32 import org.netbeans.junit.NbTestSuite; 33 34 import org.netbeans.core.windows.Constants; 35 import org.netbeans.core.windows.SplitConstraint; 36 import org.openide.filesystems.FileObject; 37 import org.openide.filesystems.URLMapper; 38 39 43 public class ModeParserTest extends NbTestCase { 44 45 public ModeParserTest() { 46 super(""); 47 } 48 49 public ModeParserTest(java.lang.String testName) { 50 super(testName); 51 } 52 53 public static void main(java.lang.String [] args) { 54 junit.textui.TestRunner.run(suite()); 55 } 56 57 public static NbTest suite() { 58 NbTestSuite suite = new NbTestSuite(ModeParserTest.class); 59 return suite; 60 } 61 62 protected void setUp () throws Exception { 63 } 78 79 84 public void testLoadMode01 () throws Exception { 85 System.out.println(""); 86 System.out.println("ModeParserTest.testLoadMode01 START"); 87 88 ModeParser modeParser = createModeParser("data/valid/Windows/Modes","mode01"); 89 90 ModeConfig modeCfg = modeParser.load(); 91 92 assertNotNull("Could not load data.",modeCfg); 94 95 InternalConfig internalCfg = modeParser.getInternalConfig(); 96 97 assertNotNull("Could not load internal data.",internalCfg); 98 99 assertEquals("moduleCodeNameBase","org.netbeans.core.ui",internalCfg.moduleCodeNameBase); 101 assertEquals("moduleCodeNameBase","1",internalCfg.moduleCodeNameRelease); 102 assertEquals("moduleCodeNameBase","1.2",internalCfg.moduleSpecificationVersion); 103 104 assertEquals("Mode state",Constants.MODE_STATE_JOINED,modeCfg.state); 106 107 assertNotNull("Mode constraints are null",modeCfg.constraints); 108 assertEquals("Mode constraints are not empty",0,modeCfg.constraints.length); 109 110 assertEquals("Mode type",Constants.MODE_KIND_EDITOR,modeCfg.kind); 111 112 assertNull("Mode bounds are not null",modeCfg.bounds); 113 assertNull("Mode relative bounds are not null",modeCfg.relativeBounds); 114 115 assertNotNull("Active TC is null",modeCfg.selectedTopComponentID); 116 assertEquals("Active TC is not empty","",modeCfg.selectedTopComponentID); 117 assertNotNull("Previous active TC is null",modeCfg.previousSelectedTopComponentID); 118 assertEquals("Previous active TC is not empty","",modeCfg.previousSelectedTopComponentID); 119 assertTrue("Permanent",modeCfg.permanent); 120 121 System.out.println("ModeParserTest.testLoadMode01 FINISH"); 122 } 123 124 126 public void testLoadMode02 () throws Exception { 127 System.out.println(""); 128 System.out.println("ModeParserTest.testLoadMode02 START"); 129 130 ModeParser modeParser = createModeParser("data/valid/Windows/Modes","mode02"); 131 132 ModeConfig modeCfg = modeParser.load(); 133 134 assertNotNull("Could not load data.", modeCfg); 136 137 assertEquals("Mode state",Constants.MODE_STATE_JOINED,modeCfg.state); 139 140 assertNotNull("Mode constraints are null",modeCfg.constraints); 141 assertEquals("Mode constraints array has incorrect size",2,modeCfg.constraints.length); 142 SplitConstraint item; 143 item = modeCfg.constraints[0]; 144 assertEquals("Mode constraint 0 - orientation",Constants.VERTICAL,item.orientation); 145 assertEquals("Mode constraint 0 - index",1,item.index); 146 assertEquals("Mode constraint 0 - weight",0.3,item.splitWeight,0.0); 147 148 item = modeCfg.constraints[1]; 149 assertEquals("Mode constraint 1 - orientation",Constants.HORIZONTAL,item.orientation); 150 assertEquals("Mode constraint 1 - index",0,item.index); 151 assertEquals("Mode constraint 1 - weight",0.5,item.splitWeight,0.0); 152 153 assertNull("Mode bounds are not null",modeCfg.bounds); 154 assertNull("Mode relative bounds are not null",modeCfg.relativeBounds); 155 156 assertEquals("Mode type",Constants.MODE_KIND_VIEW,modeCfg.kind); 157 assertEquals("Active TC","output",modeCfg.selectedTopComponentID); 158 assertFalse("Permanent",modeCfg.permanent); 159 160 System.out.println("ModeParserTest.testLoadMode02 FINISH"); 161 } 162 163 165 public void testLoadMode03 () throws Exception { 166 System.out.println(""); 167 System.out.println("ModeParserTest.testLoadMode03 START"); 168 169 ModeParser modeParser = createModeParser("data/valid/Windows/Modes","mode03"); 170 171 ModeConfig modeCfg = modeParser.load(); 172 173 assertNotNull("Could not load data.", modeCfg); 175 176 assertEquals("Mode state",Constants.MODE_STATE_SEPARATED,modeCfg.state); 178 179 assertNotNull("Mode constraints are null",modeCfg.constraints); 180 assertEquals("Mode constraints are not empty",0,modeCfg.constraints.length); 181 182 assertNotNull("Mode bounds are null",modeCfg.bounds); 183 184 assertEquals("Mode bounds x",0,modeCfg.bounds.x); 185 assertEquals("Mode bounds y",0,modeCfg.bounds.y); 186 assertEquals("Mode bounds width",400,modeCfg.bounds.width); 187 assertEquals("Mode bounds height",200,modeCfg.bounds.height); 188 189 assertNull("Mode relative bounds are not null",modeCfg.relativeBounds); 190 191 assertEquals("Mode frame state",Frame.NORMAL,modeCfg.frameState); 192 193 assertEquals("Active TC","output",modeCfg.selectedTopComponentID); 194 assertTrue("Permanent",modeCfg.permanent); 195 196 System.out.println("ModeParserTest.testLoadMode03 FINISH"); 197 } 198 199 201 public void testLoadMode04 () throws Exception { 202 System.out.println(""); 203 System.out.println("ModeParserTest.testLoadMode04 START"); 204 205 ModeParser modeParser = createModeParser("data/valid/Windows/Modes","mode04"); 206 207 ModeConfig modeCfg = modeParser.load(); 208 209 assertNotNull("Could not load data.", modeCfg); 211 212 assertEquals("Mode state",Constants.MODE_STATE_SEPARATED,modeCfg.state); 214 215 assertNotNull("Mode constraints are null",modeCfg.constraints); 216 assertEquals("Mode constraints are not empty",0,modeCfg.constraints.length); 217 218 assertNull("Mode bounds are not null",modeCfg.bounds); 219 220 assertNotNull("Mode relative bounds are null",modeCfg.relativeBounds); 221 222 assertEquals("Mode relative bounds x",0,modeCfg.relativeBounds.x); 223 assertEquals("Mode relative bounds y",0,modeCfg.relativeBounds.y); 224 assertEquals("Mode relative bounds width",40,modeCfg.relativeBounds.width); 225 assertEquals("Mode relative bounds height",20,modeCfg.relativeBounds.height); 226 227 assertEquals("Mode frame state",Frame.MAXIMIZED_BOTH,modeCfg.frameState); 228 229 assertEquals("Active TC","output",modeCfg.selectedTopComponentID); 230 assertTrue("Permanent",modeCfg.permanent); 231 232 System.out.println("ModeParserTest.testLoadMode04 FINISH"); 233 } 234 235 237 public void testLoadMode05 () throws Exception { 238 System.out.println(""); 239 System.out.println("ModeParserTest.testLoadMode05 START"); 240 241 ModeParser modeParser = createModeParser("data/valid/Windows/Modes","mode05"); 242 243 ModeConfig modeCfg = modeParser.load(); 244 245 assertNotNull("Could not load data.", modeCfg); 247 248 assertEquals("Mode kind",Constants.MODE_KIND_SLIDING,modeCfg.kind); 250 assertEquals("Mode sliding side",Constants.LEFT, modeCfg.side); 251 253 256 258 260 265 267 assertEquals("Active TC","output",modeCfg.selectedTopComponentID); 268 assertTrue("Permanent",modeCfg.permanent); 269 270 System.out.println("ModeParserTest.testLoadMode05 FINISH"); 271 } 272 273 275 public void testLoadMode06 () throws Exception { 276 System.out.println(""); 277 System.out.println("ModeParserTest.testLoadMode06 START"); 278 279 ModeParser modeParser = createModeParser("data/valid/Windows/Modes","mode06"); 280 281 ModeConfig modeCfg = modeParser.load(); 282 283 assertNotNull("Could not load data.", modeCfg); 285 286 assertEquals("Mode kind",Constants.MODE_KIND_SLIDING,modeCfg.kind); 288 assertEquals("Mode sliding side",Constants.LEFT, modeCfg.side); 289 290 assertEquals("Active TC","output",modeCfg.selectedTopComponentID); 291 assertTrue("Permanent",modeCfg.permanent); 292 293 Map <String ,Integer > slideInSizes = modeCfg.slideInSizes; 294 assertNotNull( slideInSizes ); 295 assertEquals( 2, slideInSizes.size() ); 296 assertEquals( Integer.valueOf(123), slideInSizes.get( "output" ) ); 297 assertEquals( Integer.valueOf(321), slideInSizes.get( "someOtherTopComponentId" ) ); 298 299 System.out.println("ModeParserTest.testLoadMode06 FINISH"); 300 } 301 302 304 public void testLoadMode07 () throws Exception { 305 System.out.println(""); 306 System.out.println("ModeParserTest.testLoadMode07 START"); 307 308 ModeParser modeParser = createModeParser("data/valid/Windows/Modes","mode07"); 309 310 ModeConfig modeCfg = modeParser.load(); 311 312 assertNotNull("Could not load data.",modeCfg); 314 315 InternalConfig internalCfg = modeParser.getInternalConfig(); 316 317 assertNotNull("Could not load internal data.",internalCfg); 318 319 assertEquals("Mode state",Constants.MODE_STATE_JOINED,modeCfg.state); 321 322 assertEquals("Mode type",Constants.MODE_KIND_VIEW,modeCfg.kind); 323 324 assertEquals("Active TC","filesystems",modeCfg.selectedTopComponentID); 325 assertEquals("Previous active TC","explorer",modeCfg.previousSelectedTopComponentID); 326 assertTrue("Permanent",modeCfg.permanent); 327 328 System.out.println("ModeParserTest.testLoadMode07 FINISH"); 329 } 330 331 333 public void testSaveMode01 () throws Exception { 334 System.out.println(""); 335 System.out.println("ModeParserTest.testSaveMode01 START"); 336 337 ModeParser modeParser = createModeParser("data/valid/Windows/Modes","mode01"); 338 339 ModeConfig modeCfg1 = modeParser.load(); 340 341 modeParser.save(modeCfg1); 342 343 ModeConfig modeCfg2 = modeParser.load(); 344 345 assertTrue("Compare configuration data",modeCfg1.equals(modeCfg2)); 347 348 System.out.println("ModeParserTest.testSaveMode01 FINISH"); 349 } 350 351 353 public void testSaveMode02 () throws Exception { 354 System.out.println(""); 355 System.out.println("ModeParserTest.testSaveMode02 START"); 356 357 ModeParser modeParser = createModeParser("data/valid/Windows/Modes","mode02"); 358 359 ModeConfig modeCfg1 = modeParser.load(); 360 361 modeParser.save(modeCfg1); 362 363 ModeConfig modeCfg2 = modeParser.load(); 364 365 assertTrue("Compare configuration data",modeCfg1.equals(modeCfg2)); 367 368 System.out.println("ModeParserTest.testSaveMode02 FINISH"); 369 } 370 371 373 public void testSaveMode03 () throws Exception { 374 System.out.println(""); 375 System.out.println("ModeParserTest.testSaveMode03 START"); 376 377 ModeParser modeParser = createModeParser("data/valid/Windows/Modes","mode03"); 378 379 ModeConfig modeCfg1 = modeParser.load(); 380 381 modeParser.save(modeCfg1); 382 383 ModeConfig modeCfg2 = modeParser.load(); 384 385 assertTrue("Compare configuration data",modeCfg1.equals(modeCfg2)); 387 388 System.out.println("ModeParserTest.testSaveMode03 FINISH"); 389 } 390 391 393 public void testSaveMode04 () throws Exception { 394 System.out.println(""); 395 System.out.println("ModeParserTest.testSaveMode04 START"); 396 397 ModeParser modeParser = createModeParser("data/valid/Windows/Modes","mode04"); 398 399 ModeConfig modeCfg1 = modeParser.load(); 400 401 modeParser.save(modeCfg1); 402 403 ModeConfig modeCfg2 = modeParser.load(); 404 405 assertTrue("Compare configuration data",modeCfg1.equals(modeCfg2)); 407 408 System.out.println("ModeParserTest.testSaveMode04 FINISH"); 409 } 410 411 412 414 public void testSaveMode06 () throws Exception { 415 System.out.println(""); 416 System.out.println("ModeParserTest.testSaveMode06 START"); 417 418 ModeParser modeParser = createModeParser("data/valid/Windows/Modes","mode06"); 419 420 ModeConfig modeCfg1 = modeParser.load(); 421 422 modeParser.save(modeCfg1); 423 424 ModeConfig modeCfg2 = modeParser.load(); 425 426 assertTrue("Compare configuration data",modeCfg1.equals(modeCfg2)); 428 429 System.out.println("ModeParserTest.testSaveMode06 FINISH"); 430 } 431 432 434 public void testSaveMode07 () throws Exception { 435 System.out.println(""); 436 System.out.println("ModeParserTest.testSaveMode07 START"); 437 438 ModeParser modeParser = createModeParser("data/valid/Windows/Modes","mode07"); 439 440 ModeConfig modeCfg1 = modeParser.load(); 441 442 modeParser.save(modeCfg1); 443 444 ModeConfig modeCfg2 = modeParser.load(); 445 446 assertTrue("Compare configuration data",modeCfg1.equals(modeCfg2)); 448 449 System.out.println("ModeParserTest.testSaveMode07 FINISH"); 450 } 451 452 457 public void testLoadMode01Invalid () throws Exception { 458 System.out.println(""); 459 System.out.println("ModeParserTest.testLoadMode01Invalid START"); 460 461 ModeParser modeParser = createModeParser("data/invalid/Windows/Modes","mode01"); 462 463 try { 464 modeParser.load(); 465 } catch (FileNotFoundException exc) { 466 System.out.println("ModeParserTest.testLoadMode01Invalid FINISH"); 469 return; 470 } 471 472 fail("Missing file was not detected."); 473 } 474 475 477 public void testLoadMode02Invalid () throws Exception { 478 System.out.println(""); 479 System.out.println("ModeParserTest.testLoadMode02Invalid START"); 480 481 ModeParser modeParser = createModeParser("data/invalid/Windows/Modes","mode02"); 482 483 try { 484 modeParser.load(); 485 } catch (IOException exc) { 486 System.out.println("ModeParserTest.testLoadMode02Invalid FINISH"); 488 return; 489 } 490 491 fail("Empty file was not detected."); 492 } 493 494 496 public void testLoadMode03Invalid () throws Exception { 497 System.out.println(""); 498 System.out.println("ModeParserTest.testLoadMode03Invalid START"); 499 500 ModeParser modeParser = createModeParser("data/invalid/Windows/Modes","mode03"); 501 502 try { 503 modeParser.load(); 504 } catch (IOException exc) { 505 System.out.println("ModeParserTest.testLoadMode03Invalid FINISH"); 507 return; 508 } 509 510 fail("Missing required attribute \"unique\" of element \"name\" was not detected."); 511 } 512 513 515 public void testLoadMode04Invalid () throws Exception { 516 System.out.println(""); 517 System.out.println("ModeParserTest.testLoadMode04Invalid START"); 518 519 ModeParser modeParser = createModeParser("data/invalid/Windows/Modes","mode04"); 520 521 try { 522 modeParser.load(); 523 } catch (IOException exc) { 524 System.out.println("ModeParserTest.testLoadMode04Invalid FINISH"); 526 return; 527 } 528 529 fail("Mismatch of file name and value of attribute \"unique\" of element \"name\" was not detected."); 530 } 531 532 private ModeParser createModeParser (String path, String name) { 533 URL url; 534 url = ModeParserTest.class.getResource(path); 535 assertNotNull("url not found.",url); 536 537 FileObject parentFolder = URLMapper.findFileObject(url); 538 assertNotNull("Test parent folder not found. ParentFolder is null.",url); 539 540 Set setLocal = new HashSet (); 541 ModeParser modeParser = new ModeParser(name,setLocal); 542 modeParser.setInLocalFolder(true); 543 modeParser.setLocalParentFolder(parentFolder); 544 545 return modeParser; 546 } 547 548 } 549 | Popular Tags |