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 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.URLMapper; 31 32 36 public class TCGroupParserTest extends NbTestCase { 37 38 public TCGroupParserTest() { 39 super(""); 40 } 41 42 public TCGroupParserTest(java.lang.String testName) { 43 super(testName); 44 } 45 46 public static void main(java.lang.String [] args) { 47 junit.textui.TestRunner.run(suite()); 48 } 49 50 public static NbTest suite() { 51 NbTestSuite suite = new NbTestSuite(TCGroupParserTest.class); 52 return suite; 53 } 54 55 protected void setUp () throws Exception { 56 } 57 58 63 public void testLoadTCGroup00 () throws Exception { 64 System.out.println(""); 65 System.out.println("TCGroupParserTest.testLoadTCGroup00 START"); 66 67 TCGroupParser tcGroupParser = createGroupParser("data/valid/Windows/Groups/group00","tcgroup00"); 68 69 TCGroupConfig tcGroupCfg = tcGroupParser.load(); 70 71 assertNotNull("Could not load data.", tcGroupCfg); 73 74 assertTrue("Attribute \"open\". Expected true but is false.", tcGroupCfg.open); 75 assertFalse("Attribute \"close\". Expected false but is true.", tcGroupCfg.close); 76 assertTrue("Attribute \"was-opened\". Expected true but is false.", tcGroupCfg.wasOpened); 77 78 System.out.println("TCGroupParserTest.testLoadTCGroup00 FINISH"); 79 } 80 81 83 public void testLoadTCGroup01 () throws Exception { 84 System.out.println(""); 85 System.out.println("TCGroupParserTest.testLoadTCGroup01 START"); 86 87 TCGroupParser tcGroupParser = createGroupParser("data/valid/Windows/Groups/group00","tcgroup01"); 88 89 TCGroupConfig tcGroupCfg = tcGroupParser.load(); 90 91 assertNotNull("Could not load data.", tcGroupCfg); 93 94 assertFalse("Attribute \"open\". Expected false but is true.", tcGroupCfg.open); 95 assertTrue("Attribute \"close\". Expected true but is false.", tcGroupCfg.close); 96 assertFalse("Attribute \"was-opened\". Expected false but is true.", tcGroupCfg.wasOpened); 97 98 System.out.println("TCGroupParserTest.testLoadTCGroup01 FINISH"); 99 } 100 101 103 public void testSaveTCGroup00 () throws Exception { 104 System.out.println(""); 105 System.out.println("TCGroupParserTest.testSaveTCGroup00 START"); 106 107 TCGroupParser tcGroupParser = createGroupParser("data/valid/Windows/Groups/group00","tcgroup00"); 108 109 TCGroupConfig tcGroupCfg1 = tcGroupParser.load(); 110 111 tcGroupParser.save(tcGroupCfg1); 112 113 TCGroupConfig tcGroupCfg2 = tcGroupParser.load(); 114 115 assertTrue("Compare configuration data",tcGroupCfg1.equals(tcGroupCfg2)); 117 118 System.out.println("TCGroupParserTest.testSaveTCGroup00 FINISH"); 119 } 120 121 123 public void testSaveTCGroup01 () throws Exception { 124 System.out.println(""); 125 System.out.println("TCGroupParserTest.testSaveTCGroup01 START"); 126 127 TCGroupParser tcGroupParser = createGroupParser("data/valid/Windows/Groups/group00","tcgroup01"); 128 129 TCGroupConfig tcGroupCfg1 = tcGroupParser.load(); 130 131 tcGroupParser.save(tcGroupCfg1); 132 133 TCGroupConfig tcGroupCfg2 = tcGroupParser.load(); 134 135 assertTrue("Compare configuration data",tcGroupCfg1.equals(tcGroupCfg2)); 137 138 System.out.println("TCGroupParserTest.testSaveTCGroup01 FINISH"); 139 } 140 141 146 public void testLoadTCGroup00Invalid () throws Exception { 147 System.out.println(""); 148 System.out.println("TCGroupParserTest.testLoadTCGroup00Invalid START"); 149 150 TCGroupParser tcGroupParser = createGroupParser("data/invalid/Windows/Groups/group00","tcgroup00"); 151 152 try { 153 tcGroupParser.load(); 154 } catch (FileNotFoundException exc) { 155 System.out.println("TCGroupParserTest.testLoadTCGroup00Invalid FINISH"); 158 return; 159 } 160 161 fail("Missing file was not detected."); 162 } 163 164 166 public void testLoadTCGroup01Invalid () throws Exception { 167 System.out.println(""); 168 System.out.println("TCGroupParserTest.testLoadTCGroup01Invalid START"); 169 170 TCGroupParser tcGroupParser = createGroupParser("data/invalid/Windows/Groups/group00","tcgroup01"); 171 172 try { 173 tcGroupParser.load(); 174 } catch (IOException exc) { 175 System.out.println("TCGroupParserTest.testLoadTCGroup01Invalid FINISH"); 177 return; 178 } 179 180 fail("Empty file was not detected."); 181 } 182 183 185 public void testLoadTCGroup02Invalid () throws Exception { 186 System.out.println(""); 187 System.out.println("TCGroupParserTest.testLoadTCGroup02Invalid START"); 188 189 TCGroupParser tcGroupParser = createGroupParser("data/invalid/Windows/Groups/group00","tcgroup02"); 190 191 try { 192 tcGroupParser.load(); 193 } catch (IOException exc) { 194 System.out.println("TCGroupParserTest.testLoadTCGroup02Invalid FINISH"); 196 return; 197 } 198 199 fail("Missing required attribute \"id\" of element \"properties\" was not detected."); 200 } 201 202 204 public void testLoadTCGroup03Invalid () throws Exception { 205 System.out.println(""); 206 System.out.println("TCGroupParserTest.testLoadTCGroup03Invalid START"); 207 208 TCGroupParser tcGroupParser = createGroupParser("data/invalid/Windows/Groups/group00","tcgroup03"); 209 210 try { 211 tcGroupParser.load(); 212 } catch (IOException exc) { 213 System.out.println("TCGroupParserTest.testLoadTCGroup03Invalid FINISH"); 215 return; 216 } 217 218 fail("Mismatch of file name and value of attribute \"id\" of element \"properties\" was not detected."); 219 } 220 221 private TCGroupParser createGroupParser (String path, String name) { 222 URL url; 223 url = TCGroupParserTest.class.getResource(path); 224 assertNotNull("url not found.",url); 225 226 FileObject [] foArray = URLMapper.findFileObjects(url); 227 assertNotNull("Test parent folder not found. Array is null.",foArray); 228 assertTrue("Test parent folder not found. Array is empty.",foArray.length > 0); 229 230 FileObject parentFolder = foArray[0]; 231 assertNotNull("Test parent folder not found. ParentFolder is null.",parentFolder); 232 233 TCGroupParser tcGroupParser = new TCGroupParser(name); 234 tcGroupParser.setInLocalFolder(true); 235 tcGroupParser.setLocalParentFolder(parentFolder); 236 237 return tcGroupParser; 238 } 239 } 240 | Popular Tags |