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 GroupParserTest extends NbTestCase { 37 38 public GroupParserTest() { 39 super(""); 40 } 41 42 public GroupParserTest(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(GroupParserTest.class); 52 return suite; 53 } 54 55 protected void setUp () throws Exception { 56 } 57 58 63 public void testLoadGroup01 () throws Exception { 64 System.out.println(""); 65 System.out.println("GroupParserTest.testLoadGroup01 START"); 66 67 GroupParser groupParser = createGroupParser("data/valid/Windows/Groups","group01"); 68 69 GroupConfig groupCfg = groupParser.load(); 70 71 assertNotNull("Could not load data.",groupCfg); 73 74 InternalConfig internalCfg = groupParser.getInternalConfig(); 75 76 assertNotNull("Could not load internal data.",internalCfg); 77 78 assertEquals("moduleCodeNameBase","org.netbeans.modules.form",internalCfg.moduleCodeNameBase); 80 assertEquals("moduleCodeNameBase","2",internalCfg.moduleCodeNameRelease); 81 assertEquals("moduleCodeNameBase","1.7",internalCfg.moduleSpecificationVersion); 82 83 assertTrue("opened",groupCfg.opened); 84 85 System.out.println("GroupParserTest.testLoadGroup01 FINISH"); 86 } 87 88 90 public void testLoadGroup02 () throws Exception { 91 System.out.println(""); 92 System.out.println("GroupParserTest.testLoadGroup02 START"); 93 94 GroupParser groupParser = createGroupParser("data/valid/Windows/Groups","group02"); 95 96 GroupConfig groupCfg = groupParser.load(); 97 98 assertNotNull("Could not load data.",groupCfg); 100 101 InternalConfig internalCfg = groupParser.getInternalConfig(); 102 103 assertNotNull("Could not load internal data.",internalCfg); 104 105 assertEquals("moduleCodeNameBase","org.netbeans.modules.form",internalCfg.moduleCodeNameBase); 107 assertEquals("moduleCodeNameBase","2",internalCfg.moduleCodeNameRelease); 108 assertEquals("moduleCodeNameBase","1.7",internalCfg.moduleSpecificationVersion); 109 110 assertFalse("opened",groupCfg.opened); 111 112 System.out.println("GroupParserTest.testLoadGroup02 FINISH"); 113 } 114 115 117 public void testSaveGroup01 () throws Exception { 118 System.out.println(""); 119 System.out.println("GroupParserTest.testSaveGroup01 START"); 120 121 GroupParser groupParser = createGroupParser("data/valid/Windows/Groups","group01"); 122 123 GroupConfig groupCfg1 = groupParser.load(); 124 125 groupParser.save(groupCfg1); 126 127 GroupConfig groupCfg2 = groupParser.load(); 128 129 assertTrue("Compare configuration data",groupCfg1.equals(groupCfg2)); 131 132 System.out.println("GroupParserTest.testSaveGroup01 FINISH"); 133 } 134 135 137 public void testSaveGroup02 () throws Exception { 138 System.out.println(""); 139 System.out.println("GroupParserTest.testSaveGroup02 START"); 140 141 GroupParser groupParser = createGroupParser("data/valid/Windows/Groups","group02"); 142 143 GroupConfig groupCfg1 = groupParser.load(); 144 145 groupParser.save(groupCfg1); 146 147 GroupConfig groupCfg2 = groupParser.load(); 148 149 assertTrue("Compare configuration data",groupCfg1.equals(groupCfg2)); 151 152 System.out.println("GroupParserTest.testSaveGroup02 FINISH"); 153 } 154 155 160 public void testLoadGroup01Invalid () throws Exception { 161 System.out.println(""); 162 System.out.println("GroupParserTest.testLoadGroup01Invalid START"); 163 164 GroupParser groupParser = createGroupParser("data/invalid/Windows/Groups","group01"); 165 166 try { 167 groupParser.load(); 168 } catch (FileNotFoundException exc) { 169 System.out.println("GroupParserTest.testLoadGroup01Invalid FINISH"); 172 return; 173 } 174 175 fail("Missing file was not detected."); 176 } 177 178 180 public void testLoadGroup02Invalid () throws Exception { 181 System.out.println(""); 182 System.out.println("GroupParserTest.testLoadGroup02Invalid START"); 183 184 GroupParser groupParser = createGroupParser("data/invalid/Windows/Groups","group02"); 185 186 try { 187 groupParser.load(); 188 } catch (IOException exc) { 189 System.out.println("GroupParserTest.testLoadGroup02Invalid FINISH"); 191 return; 192 } 193 194 fail("Empty file was not detected."); 195 } 196 197 199 public void testLoadGroup03Invalid () throws Exception { 200 System.out.println(""); 201 System.out.println("GroupParserTest.testLoadGroup03Invalid START"); 202 203 GroupParser groupParser = createGroupParser("data/invalid/Windows/Groups","group03"); 204 205 try { 206 groupParser.load(); 207 } catch (IOException exc) { 208 System.out.println("GroupParserTest.testLoadGroup03Invalid FINISH"); 210 return; 211 } 212 213 fail("Missing required attribute \"name\" of element \"properties\" was not detected."); 214 } 215 216 218 public void testLoadGroup04Invalid () throws Exception { 219 System.out.println(""); 220 System.out.println("GroupParserTest.testLoadGroup04Invalid START"); 221 222 GroupParser groupParser = createGroupParser("data/invalid/Windows/Groups","group04"); 223 224 try { 225 groupParser.load(); 226 } catch (IOException exc) { 227 System.out.println("GroupParserTest.testLoadGroup04Invalid FINISH"); 229 return; 230 } 231 232 fail("Mismatch of file name and value of attribute \"name\" of element \"properties\" was not detected."); 233 } 234 235 private GroupParser createGroupParser (String path, String name) { 236 URL url; 237 url = GroupParserTest.class.getResource(path); 238 assertNotNull("url not found.",url); 239 240 FileObject parentFolder = URLMapper.findFileObject(url); 241 assertNotNull("Test parent folder not found. ParentFolder is null. for " + url, parentFolder); 242 243 GroupParser groupParser = new GroupParser(name); 244 groupParser.setInLocalFolder(true); 245 groupParser.setLocalParentFolder(parentFolder); 246 247 return groupParser; 248 } 249 250 } 251 | Popular Tags |