1 19 20 package org.netbeans.core.windows.persistence; 21 22 import java.io.FileNotFoundException ; 23 import java.io.IOException ; 24 import java.net.URL ; 25 26 import org.netbeans.junit.NbTest; 27 import org.netbeans.junit.NbTestCase; 28 import org.netbeans.junit.NbTestSuite; 29 30 import org.netbeans.core.windows.persistence.TCRefConfig; 31 32 import org.openide.ErrorManager; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.URLMapper; 35 36 40 public class TCRefParserTest extends NbTestCase { 41 42 public TCRefParserTest() { 43 super(""); 44 } 45 46 public TCRefParserTest(java.lang.String testName) { 47 super(testName); 48 } 49 50 public static void main(java.lang.String [] args) { 51 junit.textui.TestRunner.run(suite()); 52 } 53 54 public static NbTest suite() { 55 NbTestSuite suite = new NbTestSuite(TCRefParserTest.class); 56 return suite; 57 } 58 59 protected void setUp () throws Exception { 60 } 61 62 67 public void testLoadTCRef00 () throws Exception { 68 System.out.println(""); 69 System.out.println("TCRefParserTest.testLoadTCRef00 START"); 70 71 TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref00"); 72 73 TCRefConfig tcRefCfg = tcRefParser.load(); 74 75 assertNotNull("Could not load data.", tcRefCfg); 77 78 assertTrue("TopComponent is opened.", tcRefCfg.opened); 79 80 System.out.println("TCRefParserTest.testLoadTCRef00 FINISH"); 81 } 82 83 85 public void testLoadTCRef01 () throws Exception { 86 System.out.println(""); 87 System.out.println("TCRefParserTest.testLoadTCRef01 START"); 88 89 TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref01"); 90 91 TCRefConfig tcRefCfg = tcRefParser.load(); 92 93 assertNotNull("Could not load data.", tcRefCfg); 95 96 assertFalse("TopComponent is closed.", tcRefCfg.opened); 97 98 System.out.println("TCRefParserTest.testLoadTCRef01 FINISH"); 99 } 100 101 103 public void testLoadTCRef03 () throws Exception { 104 System.out.println(""); 105 System.out.println("TCRefParserTest.testLoadTCRef03 START"); 106 107 TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref03"); 108 109 TCRefConfig tcRefCfg = tcRefParser.load(); 110 111 assertNotNull("Could not load data.", tcRefCfg); 113 114 assertFalse("TopComponent is closed.", tcRefCfg.opened); 115 116 assertEquals("Previous mode.", "explorer", tcRefCfg.previousMode); 117 assertEquals("Tab index in previous mode.", 2, tcRefCfg.previousIndex); 118 119 assertTrue("TopComponent is docked in maximized mode.", tcRefCfg.dockedInMaximizedMode); 120 assertFalse("TopComponent is slided-out in default mode.", tcRefCfg.dockedInDefaultMode); 121 122 assertTrue("TopComponent is maximized when slided-in.", tcRefCfg.slidedInMaximized); 123 124 System.out.println("TCRefParserTest.testLoadTCRef03 FINISH"); 125 } 126 127 129 public void testSaveTCRef00 () throws Exception { 130 System.out.println(""); 131 System.out.println("TCRefParserTest.testSaveTCRef00 START"); 132 133 TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref00"); 134 135 TCRefConfig tcRefCfg1 = tcRefParser.load(); 136 137 tcRefParser.save(tcRefCfg1); 138 139 TCRefConfig tcRefCfg2 = tcRefParser.load(); 140 141 assertTrue("Compare configuration data",tcRefCfg1.equals(tcRefCfg2)); 143 144 System.out.println("TCRefParserTest.testSaveTCRef00 FINISH"); 145 } 146 147 149 public void testSaveTCRef01 () throws Exception { 150 System.out.println(""); 151 System.out.println("TCRefParserTest.testSaveTCRef01 START"); 152 153 TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref01"); 154 155 TCRefConfig tcRefCfg1 = tcRefParser.load(); 156 157 tcRefParser.save(tcRefCfg1); 158 159 TCRefConfig tcRefCfg2 = tcRefParser.load(); 160 161 assertTrue("Compare configuration data",tcRefCfg1.equals(tcRefCfg2)); 163 164 System.out.println("TCRefParserTest.testSaveTCRef01 FINISH"); 165 } 166 167 169 public void testSaveTCRef02 () throws Exception { 170 System.out.println(""); 171 System.out.println("TCRefParserTest.testSaveTCRef02 START"); 172 173 TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref02&'"); 174 175 TCRefConfig tcRefCfg1 = tcRefParser.load(); 176 177 tcRefParser.save(tcRefCfg1); 178 179 TCRefConfig tcRefCfg2 = tcRefParser.load(); 180 System.out.println("tcrefcfg1: " + tcRefCfg1); 181 System.out.println("tcrefcfg2: " + tcRefCfg2); 182 assertTrue("Compare configuration data",tcRefCfg1.equals(tcRefCfg2)); 184 185 System.out.println("TCRefParserTest.testSaveTCRef02 FINISH"); 186 } 187 188 public void testSaveTCRef03 () throws Exception { 189 System.out.println(""); 190 System.out.println("TCRefParserTest.testSaveTCRef03 START"); 191 192 TCRefParser tcRefParser = createRefParser("data/valid/Windows/Modes/mode00","tcref03"); 193 194 TCRefConfig tcRefCfg1 = tcRefParser.load(); 195 196 tcRefParser.save(tcRefCfg1); 197 198 TCRefConfig tcRefCfg2 = tcRefParser.load(); 199 200 assertTrue("Compare configuration data",tcRefCfg1.equals(tcRefCfg2)); 202 203 System.out.println("TCRefParserTest.testSaveTCRef03 FINISH"); 204 } 205 206 211 public void testLoadTCRef00Invalid () throws Exception { 212 System.out.println(""); 213 System.out.println("TCRefParserTest.testLoadTCRef00Invalid START"); 214 215 TCRefParser tcRefParser = createRefParser("data/invalid/Windows/Modes/mode00","tcref00"); 216 217 try { 218 tcRefParser.load(); 219 } catch (FileNotFoundException exc) { 220 System.out.println("TCRefParserTest.testLoadTCRef00Invalid FINISH"); 223 return; 224 } 225 226 fail("Missing file was not detected."); 227 } 228 229 231 public void testLoadTCRef01Invalid () throws Exception { 232 System.out.println(""); 233 System.out.println("TCRefParserTest.testLoadTCRef01Invalid START"); 234 235 TCRefParser tcRefParser = createRefParser("data/invalid/Windows/Modes/mode00","tcref01"); 236 237 try { 238 tcRefParser.load(); 239 } catch (IOException exc) { 240 System.out.println("TCRefParserTest.testLoadTCRef01Invalid FINISH"); 242 return; 243 } 244 245 fail("Empty file was not detected."); 246 } 247 248 250 public void testLoadTCRef02Invalid () throws Exception { 251 System.out.println(""); 252 System.out.println("TCRefParserTest.testLoadTCRef02Invalid START"); 253 254 TCRefParser tcRefParser = createRefParser("data/invalid/Windows/Modes/mode00","tcref02"); 255 256 try { 257 tcRefParser.load(); 258 } catch (IOException exc) { 259 System.out.println("TCRefParserTest.testLoadTCRef02Invalid FINISH"); 261 return; 262 } 263 264 fail("Missing required attribute \"id\" of element \"properties\" was not detected."); 265 } 266 267 269 public void testLoadTCRef03Invalid () throws Exception { 270 System.out.println(""); 271 System.out.println("TCRefParserTest.testLoadTCRef03Invalid START"); 272 273 TCRefParser tcRefParser = createRefParser("data/invalid/Windows/Modes/mode00","tcref03"); 274 275 try { 276 tcRefParser.load(); 277 } catch (IOException exc) { 278 System.out.println("TCRefParserTest.testLoadTCRef03Invalid FINISH"); 280 return; 281 } 282 283 fail("Mismatch of file name and value of attribute \"id\" of element \"properties\" was not detected."); 284 } 285 286 private TCRefParser createRefParser (String path, String name) { 287 URL url; 288 url = TCRefParserTest.class.getResource(path); 289 assertNotNull("url not found.",url); 290 291 FileObject [] foArray = URLMapper.findFileObjects(url); 292 assertNotNull("Test parent folder not found. Array is null.",foArray); 293 assertTrue("Test parent folder not found. Array is empty.",foArray.length > 0); 294 295 FileObject parentFolder = foArray[0]; 296 assertNotNull("Test parent folder not found. ParentFolder is null.",parentFolder); 297 298 TCRefParser tcRefParser = new TCRefParser(name); 299 tcRefParser.setInLocalFolder(true); 300 tcRefParser.setLocalParentFolder(parentFolder); 301 302 return tcRefParser; 303 } 304 305 } 306 | Popular Tags |