Test config updating
()
| 138 | |
| 139 | /** Test config updating */ |
| 140 | @Test |
| 141 | public void testConfigUpdating() throws Exception { |
| 142 | |
| 143 | //TODO try and fix this in some way |
| 144 | // Don't test if there is no file. Should probably test with a static file |
| 145 | // in the resources instead of relying on the running user |
| 146 | if (Gate.getUserConfigFile() == null) return; |
| 147 | |
| 148 | // clear the gate config so we don't write values from the |
| 149 | // system initialisation into the test file |
| 150 | |
| 151 | |
| 152 | OptionsMap configMap = Gate.getUserConfig(); |
| 153 | configMap.clear(); |
| 154 | |
| 155 | // if user config file exists, save it and remember the name |
| 156 | //String configName = Gate.getUserConfigFileName(); |
| 157 | //File userConfigFile = new File(configName); |
| 158 | File userConfigFile = Gate.getUserConfigFile(); |
| 159 | String configName = userConfigFile.getAbsolutePath(); |
| 160 | File savedConfigFile = null; |
| 161 | if(userConfigFile.exists()) { |
| 162 | if(DEBUG) { |
| 163 | Out.prln(userConfigFile); |
| 164 | Out.prln("can write: " + userConfigFile.canWrite()); |
| 165 | } |
| 166 | String userConfigDirectory = userConfigFile.getParent(); |
| 167 | if(userConfigDirectory == null) |
| 168 | userConfigDirectory = ""; |
| 169 | savedConfigFile = new File( |
| 170 | userConfigDirectory + Strings.getFileSep() + |
| 171 | "__saved_gate.xml__for_TestConfig__" + System.currentTimeMillis() |
| 172 | ); |
| 173 | if(DEBUG) Out.prln(savedConfigFile); |
| 174 | boolean renamed = userConfigFile.renameTo(savedConfigFile); |
| 175 | assertTrue("rename failed", renamed); |
| 176 | } |
| 177 | assertTrue("user config file still there", ! userConfigFile.exists()); |
| 178 | |
| 179 | // call Gate.writeConfig - check it creates an empty config file |
| 180 | //this is no longer a valid test as the written user config will at least |
| 181 | //contain the values for the known and autload plugin paths. |
| 182 | Gate.writeUserConfig(); |
| 183 | @SuppressWarnings("unused") |
| 184 | String writtenConfig = Files.getString(new File(configName)); |
| 185 | @SuppressWarnings("unused") |
| 186 | String empty = Gate.getEmptyConfigFile(); |
| 187 | // assertEquals("written config doesn't match", writtenConfig, empty); |
| 188 | |
| 189 | // set some config attributes via Gate.getConfigData |
| 190 | configMap.put("A", "1"); |
| 191 | configMap.put("B", "2"); |
| 192 | |
| 193 | // call Gate.writeConfig, delete the config data from Gate's map, |
| 194 | // read the config file and check that the new data is present |
| 195 | Gate.writeUserConfig(); |
| 196 | configMap.clear(); |
| 197 | readConfig(userConfigFile.toURI().toURL()); |
nothing calls this directly
no test coverage detected