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.logging.Level ; 27 import java.util.logging.Logger ; 28 29 import org.netbeans.junit.NbTest; 30 import org.netbeans.junit.NbTestCase; 31 import org.netbeans.junit.NbTestSuite; 32 33 import org.netbeans.core.windows.Constants; 34 import org.netbeans.core.windows.SplitConstraint; 35 import org.openide.filesystems.FileObject; 36 import org.openide.filesystems.URLMapper; 37 38 42 public class WindowManagerParserTest extends NbTestCase { 43 private FileObject origRootModuleFolder; 44 private FileObject origRootLocalFolder; 45 46 public WindowManagerParserTest() { 47 super(""); 48 } 49 50 public WindowManagerParserTest(java.lang.String testName) { 51 super(testName); 52 } 53 54 public static void main(java.lang.String [] args) { 55 junit.textui.TestRunner.run(suite()); 56 } 57 58 public static NbTest suite() { 59 NbTestSuite suite = new NbTestSuite(WindowManagerParserTest.class); 60 return suite; 61 } 62 63 protected void setUp () throws Exception { 64 origRootModuleFolder = PersistenceManager.getDefault().getRootModuleFolder(); 65 origRootLocalFolder = PersistenceManager.getDefault().getRootLocalFolder(); 66 } 67 68 protected void tearDown () throws Exception { 69 PersistenceManager.getDefault().setRootModuleFolder(origRootModuleFolder); 70 PersistenceManager.getDefault().setRootLocalFolder(origRootLocalFolder); 71 } 72 73 78 public void testLoadWM01 () throws Exception { 79 System.out.println(""); 80 System.out.println("WindowManagerParserTest.testLoadWM01 START"); 81 82 WindowManagerParser wmParser = createWMParser("data/valid/Windows","windowmanager01"); 83 84 WindowManagerConfig wmCfg = null; 85 try { 86 wmCfg = wmParser.load(); 87 } catch (IOException exc) { 88 Logger.global.log(Level.WARNING, null, exc); 89 fail("Unexpected exception during parsing"); 90 } 91 92 assertNotNull("Could not load data.",wmCfg); 94 95 assertEquals("Joined bounds x",100,wmCfg.xJoined); 96 assertEquals("Joined bounds y",100,wmCfg.yJoined); 97 assertEquals("Joined bounds width",800,wmCfg.widthJoined); 98 assertEquals("Joined bounds height",600,wmCfg.heightJoined); 99 100 assertEquals("Joined bounds relative width",-1.0,wmCfg.relativeWidthJoined,0.0); 101 assertEquals("Joined bounds relative height",-1.0,wmCfg.relativeHeightJoined,0.0); 102 103 assertEquals("Joined maximizeIfWidthBelow",-1,wmCfg.maximizeIfWidthBelowJoined); 104 assertEquals("Joined maximizeIfHeightBelow",-1,wmCfg.maximizeIfHeightBelowJoined); 105 106 assertFalse("Joined centered horizontaly",wmCfg.centeredHorizontallyJoined); 107 assertFalse("Joined centered verticaly",wmCfg.centeredVerticallyJoined); 108 109 assertEquals("Joined main window frame state",Frame.NORMAL,wmCfg.mainWindowFrameStateJoined); 110 assertEquals("Separated main window frame state",Frame.NORMAL,wmCfg.mainWindowFrameStateSeparated); 111 112 assertEquals("Incorrect editor area state",Constants.EDITOR_AREA_JOINED,wmCfg.editorAreaState); 113 114 assertNotNull("Editor area relative bounds are null",wmCfg.editorAreaRelativeBounds); 115 116 assertEquals("Editor area relative bounds x",0,wmCfg.editorAreaRelativeBounds.x); 117 assertEquals("Editor area relative bounds y",0,wmCfg.editorAreaRelativeBounds.y); 118 assertEquals("Editor area relative bounds width",100,wmCfg.editorAreaRelativeBounds.width); 119 assertEquals("Editor area relative bounds height",60,wmCfg.editorAreaRelativeBounds.height); 120 121 assertNull("Editor area bounds are not null",wmCfg.editorAreaBounds); 122 123 assertEquals("Editor area window frame state",Frame.NORMAL,wmCfg.editorAreaFrameState); 124 125 assertNotNull("Editor area constraints are null",wmCfg.editorAreaConstraints); 126 assertEquals("Editor area constraints array has incorrect size",2,wmCfg.editorAreaConstraints.length); 127 SplitConstraint item; 128 item = wmCfg.editorAreaConstraints[0]; 129 assertEquals("Editor area constraint 0 - orientation",Constants.VERTICAL,item.orientation); 130 assertEquals("Editor area constraint 0 - index",0,item.index); 131 assertEquals("Editor area constraint 0 - weight",0.7,item.splitWeight,0.0); 132 133 item = wmCfg.editorAreaConstraints[1]; 134 assertEquals("Editor area constraint 1 - orientation",Constants.HORIZONTAL,item.orientation); 135 assertEquals("Editor area constraint 1 - index",1,item.index); 136 assertEquals("Editor area constraint 1 - weight",0.5,item.splitWeight,0.0); 137 138 assertNotNull("Screen size is null",wmCfg.screenSize); 139 assertEquals("Screen width",1280,wmCfg.screenSize.width); 140 assertEquals("Screen height",1024,wmCfg.screenSize.height); 141 142 assertEquals("Active mode","editor",wmCfg.activeModeName); 143 assertEquals("Editor maximized mode","editor",wmCfg.editorMaximizedModeName); 144 assertEquals("View maximized mode","explorer",wmCfg.viewMaximizedModeName); 145 assertEquals("Toolbar","Standard",wmCfg.toolbarConfiguration); 146 147 assertNotNull("Modes are null",wmCfg.modes); 148 149 assertNotNull("Groups are null",wmCfg.groups); 150 151 System.out.println("WindowManagerParserTest.testLoadWM01 FINISH"); 152 } 153 154 156 public void testLoadWM02 () throws Exception { 157 System.out.println(""); 158 System.out.println("WindowManagerParserTest.testLoadWM02 START"); 159 160 WindowManagerParser wmParser = createWMParser("data/valid/Windows","windowmanager02"); 161 162 WindowManagerConfig wmCfg = null; 163 try { 164 wmCfg = wmParser.load(); 165 } catch (IOException exc) { 166 Logger.global.log(Level.WARNING, null, exc); 167 fail("Unexpected exception during parsing"); 168 } 169 170 assertNotNull("Could not load data.",wmCfg); 172 173 assertEquals("Joined bounds x",-1,wmCfg.xJoined); 174 assertEquals("Joined bounds y",-1,wmCfg.yJoined); 175 assertEquals("Joined bounds width",-1,wmCfg.widthJoined); 176 assertEquals("Joined bounds height",-1,wmCfg.heightJoined); 177 178 assertEquals("Joined bounds relative x",-1.0,wmCfg.relativeXJoined,0.0); 179 assertEquals("Joined bounds relative y",-1.0,wmCfg.relativeYJoined,0.0); 180 assertEquals("Joined bounds relative width",85.0,wmCfg.relativeWidthJoined,0.0); 181 assertEquals("Joined bounds relative height",85.0,wmCfg.relativeHeightJoined,0.0); 182 183 assertEquals("Joined maximizeIfWidthBelow",1004,wmCfg.maximizeIfWidthBelowJoined); 184 assertEquals("Joined maximizeIfHeightBelow",728,wmCfg.maximizeIfHeightBelowJoined); 185 186 assertTrue("Joined centered horizontaly",wmCfg.centeredHorizontallyJoined); 187 assertTrue("Joined centered verticaly",wmCfg.centeredVerticallyJoined); 188 189 assertEquals("Joined main window frame state", 190 Frame.MAXIMIZED_BOTH,wmCfg.mainWindowFrameStateJoined); 191 assertEquals("Separated main window frame state", 192 Frame.MAXIMIZED_BOTH,wmCfg.mainWindowFrameStateSeparated); 193 194 assertEquals("Incorrect editor area state",Constants.EDITOR_AREA_SEPARATED,wmCfg.editorAreaState); 195 196 assertNull("Editor area relative bounds are not null",wmCfg.editorAreaRelativeBounds); 197 198 assertNotNull("Editor area bounds are null",wmCfg.editorAreaBounds); 199 200 assertEquals("Editor area bounds x",50,wmCfg.editorAreaBounds.x); 201 assertEquals("Editor area bounds y",60,wmCfg.editorAreaBounds.y); 202 assertEquals("Editor area bounds width",600,wmCfg.editorAreaBounds.width); 203 assertEquals("Editor area bounds height",400,wmCfg.editorAreaBounds.height); 204 205 assertEquals("Editor area window frame state", 206 Frame.MAXIMIZED_BOTH,wmCfg.editorAreaFrameState); 207 208 assertNotNull("Editor area constraints are null",wmCfg.editorAreaConstraints); 209 assertEquals("Editor area constraints array has incorrect size",2,wmCfg.editorAreaConstraints.length); 210 SplitConstraint item; 211 item = wmCfg.editorAreaConstraints[0]; 212 assertEquals("Editor area constraint 0 - orientation",Constants.VERTICAL,item.orientation); 213 assertEquals("Editor area constraint 0 - index",1,item.index); 214 assertEquals("Editor area constraint 0 - weight",0.6,item.splitWeight,0.0); 215 216 item = wmCfg.editorAreaConstraints[1]; 217 assertEquals("Editor area constraint 1 - orientation",Constants.HORIZONTAL,item.orientation); 218 assertEquals("Editor area constraint 1 - index",0,item.index); 219 assertEquals("Editor area constraint 1 - weight",0.75,item.splitWeight,0.0); 220 221 assertNotNull("Screen size is null",wmCfg.screenSize); 222 assertEquals("Screen width",640,wmCfg.screenSize.width); 223 assertEquals("Screen height",480,wmCfg.screenSize.height); 224 225 assertEquals("Active mode","editor",wmCfg.activeModeName); 226 assertEquals("View maximized mode","explorer",wmCfg.viewMaximizedModeName); 227 assertNotNull("Editor maximized mode is null",wmCfg.editorMaximizedModeName); 228 assertEquals("Editor maximized mode is not empty","",wmCfg.editorMaximizedModeName); 229 assertEquals("Toolbar","Standard",wmCfg.toolbarConfiguration); 230 231 assertNotNull("Modes are null",wmCfg.modes); 232 233 assertNotNull("Groups are null",wmCfg.groups); 234 235 System.out.println("WindowManagerParserTest.testLoadWM02 FINISH"); 236 } 237 238 240 public void testLoadWM03 () throws Exception { 241 System.out.println(""); 242 System.out.println("WindowManagerParserTest.testLoadWM03 START"); 243 244 WindowManagerParser wmParser = createWMParser("data/valid/Windows","windowmanager03"); 245 246 WindowManagerConfig wmCfg = null; 247 try { 248 wmCfg = wmParser.load(); 249 } catch (IOException exc) { 250 Logger.global.log(Level.WARNING, null, exc); 251 fail("Unexpected exception during parsing"); 252 } 253 254 assertNotNull("Could not load data.",wmCfg); 256 257 assertEquals("Editor maximized mode","editor",wmCfg.editorMaximizedModeName); 258 assertNotNull("View maximized mode is null",wmCfg.viewMaximizedModeName); 259 assertEquals("View maximized mode is not empty","",wmCfg.viewMaximizedModeName); 260 261 assertNotNull("Modes are null",wmCfg.modes); 262 263 assertNotNull("Groups are null",wmCfg.groups); 264 265 System.out.println("WindowManagerParserTest.testLoadWM03 FINISH"); 266 } 267 268 270 public void testLoadWM04 () throws Exception { 271 System.out.println(""); 272 System.out.println("WindowManagerParserTest.testLoadWM04 START"); 273 274 WindowManagerParser wmParser = createWMParser("data/valid/Windows","windowmanager04"); 275 276 WindowManagerConfig wmCfg = null; 277 try { 278 wmCfg = wmParser.load(); 279 } catch (IOException exc) { 280 Logger.global.log(Level.WARNING, null, exc); 281 fail("Unexpected exception during parsing"); 282 } 283 284 assertNotNull("Could not load data.",wmCfg); 286 287 assertNotNull("View maximized mode is null",wmCfg.viewMaximizedModeName); 288 assertEquals("View maximized mode is not empty","",wmCfg.viewMaximizedModeName); 289 290 assertNotNull("Editor maximized mode is null",wmCfg.editorMaximizedModeName); 291 assertEquals("Editor maximized mode is not empty","",wmCfg.editorMaximizedModeName); 292 293 assertNotNull("Modes are null",wmCfg.modes); 294 295 assertNotNull("Groups are null",wmCfg.groups); 296 297 System.out.println("WindowManagerParserTest.testLoadWM04 FINISH"); 298 } 299 300 302 public void testSaveWM01 () throws Exception { 303 System.out.println(""); 304 System.out.println("WindowManagerParserTest.testSaveWM01 START"); 305 306 WindowManagerParser wmParser = createWMParser("data/valid/Windows","windowmanager01"); 307 308 WindowManagerConfig wmCfg1 = wmParser.load(); 309 310 wmParser.save(wmCfg1); 311 312 WindowManagerConfig wmCfg2 = wmParser.load(); 313 314 assertTrue("Compare configuration data",wmCfg1.equals(wmCfg2)); 316 317 System.out.println("WindowManagerParserTest.testSaveWM01 FINISH"); 318 } 319 320 public void testSaveWM02 () throws Exception { 321 System.out.println(""); 322 System.out.println("WindowManagerParserTest.testSaveWM02 START"); 323 324 WindowManagerParser wmParser = createWMParser("data/valid/Windows","windowmanager02"); 325 326 WindowManagerConfig wmCfg1 = wmParser.load(); 327 328 wmParser.save(wmCfg1); 329 330 WindowManagerConfig wmCfg2 = wmParser.load(); 331 332 assertTrue("Compare configuration data",wmCfg1.equals(wmCfg2)); 334 335 System.out.println("WindowManagerParserTest.testSaveWM02 FINISH"); 336 } 337 338 public void testSaveWM03 () throws Exception { 339 System.out.println(""); 340 System.out.println("WindowManagerParserTest.testSaveWM03 START"); 341 342 WindowManagerParser wmParser = createWMParser("data/valid/Windows","windowmanager03"); 343 344 WindowManagerConfig wmCfg1 = wmParser.load(); 345 346 wmParser.save(wmCfg1); 347 348 WindowManagerConfig wmCfg2 = wmParser.load(); 349 350 assertTrue("Compare configuration data",wmCfg1.equals(wmCfg2)); 352 353 System.out.println("WindowManagerParserTest.testSaveWM03 FINISH"); 354 } 355 356 public void testSaveWM04 () throws Exception { 357 System.out.println(""); 358 System.out.println("WindowManagerParserTest.testSaveWM04 START"); 359 360 WindowManagerParser wmParser = createWMParser("data/valid/Windows","windowmanager04"); 361 362 WindowManagerConfig wmCfg1 = wmParser.load(); 363 364 wmParser.save(wmCfg1); 365 366 WindowManagerConfig wmCfg2 = wmParser.load(); 367 368 assertTrue("Compare configuration data",wmCfg1.equals(wmCfg2)); 370 371 System.out.println("WindowManagerParserTest.testSaveWM04 FINISH"); 372 } 373 374 379 public void testLoadWM01Invalid () throws Exception { 380 System.out.println(""); 381 System.out.println("WindowManagerParserTest.testLoadWM01Invalid START"); 382 383 WindowManagerParser wmParser = createWMParser("data/invalid/Windows","windowmanager01"); 384 385 try { 386 wmParser.load(); 387 } catch (FileNotFoundException exc) { 388 System.out.println("WindowManagerParserTest.testLoadWM01Invalid FINISH"); 391 return; 392 } 393 394 fail("Missing file was not detected."); 395 } 396 397 399 public void testLoadWM02Invalid () throws Exception { 400 System.out.println(""); 401 System.out.println("WindowManagerParserTest.testLoadWM02Invalid START"); 402 403 WindowManagerParser wmParser = createWMParser("data/invalid/Windows","windowmanager02"); 404 405 try { 406 wmParser.load(); 407 } catch (IOException exc) { 408 System.out.println("WindowManagerParserTest.testLoadWM02Invalid FINISH"); 411 return; 412 } 413 414 fail("Empty file was not detected."); 415 } 416 417 private WindowManagerParser createWMParser (String path, String name) { 418 URL url; 419 url = WindowManagerParserTest.class.getResource(path); 420 assertNotNull("url not found.",url); 421 422 FileObject [] foArray = URLMapper.findFileObjects(url); 423 assertNotNull("Test parent folder not found. Array is null.",foArray); 424 assertTrue("Test parent folder not found. Array is empty.",foArray.length > 0); 425 426 FileObject parentFolder = foArray[0]; 427 assertNotNull("Test parent folder not found. ParentFolder is null.",parentFolder); 428 429 PersistenceManager.getDefault().setRootModuleFolder(parentFolder); 430 PersistenceManager.getDefault().setRootLocalFolder(parentFolder); 431 432 WindowManagerParser wmParser = new WindowManagerParser(PersistenceManager.getDefault(),name); 433 434 return wmParser; 435 } 436 437 } 438 | Popular Tags |