01: package net.sourceforge.tracelog.testcases;
02:
03: import java.util.List;
04:
05: import net.sourceforge.tracelog.config.ConfigFile;
06: import net.sourceforge.tracelog.config.ConfigFileFactory;
07: import net.sourceforge.tracelog.config.LogFile;
08: import net.sourceforge.tracelog.config.LogGroup;
09: import net.sourceforge.tracelog.config.UserConfig;
10:
11: import org.junit.Assert;
12: import org.junit.Test;
13:
14: public class TXMLConfigFile {
15:
16: @Test
17: public void addLogFile() {
18: ConfigFile configFile = ConfigFileFactory.getInstance()
19: .getConfigFile();
20:
21: try {
22: UserConfig userConfig = configFile.getUserConfig();
23: List<LogGroup> logGroups = userConfig.getLogGroups();
24:
25: LogFile logFile = new LogFile(100, "testlog",
26: "testlog.txt", 1, 1);
27:
28: List<LogFile> logFiles = logGroups.get(0).getLogFiles();
29:
30: int beforeSize = logFiles.size();
31: logFiles.add(logFile);
32:
33: configFile.saveUserConfig(userConfig);
34:
35: Assert.assertEquals(beforeSize + 1, logFiles.size());
36: } catch (Exception e) {
37: Assert.fail(e.getMessage());
38: e.printStackTrace();
39: }
40: }
41:
42: @Test
43: public void changeTextEditorPath() {
44: ConfigFile configFile = ConfigFileFactory.getInstance()
45: .getConfigFile();
46:
47: try {
48: UserConfig userConfig = configFile.getUserConfig();
49: userConfig.setTextEditorPath("notepad2.exe");
50:
51: Assert.assertEquals("notepad2.exe", userConfig
52: .getTextEditorPath());
53: } catch (Exception e) {
54: Assert.fail(e.getMessage());
55: e.printStackTrace();
56: }
57: }
58:
59: @Test
60: public void readConfig() {
61: ConfigFile configFile = ConfigFileFactory.getInstance()
62: .getConfigFile();
63:
64: try {
65: UserConfig userConfig = configFile.getUserConfig();
66: Assert.assertEquals("notepad.exe", userConfig
67: .getTextEditorPath());
68:
69: List<LogGroup> logGroups = userConfig.getLogGroups();
70:
71: Assert.assertEquals(1, logGroups.size());
72:
73: for (LogGroup logGroup : logGroups) {
74: Assert.assertEquals("default", logGroup.getGroupName());
75: Assert.assertEquals(1, logGroup.getGroupOrder());
76:
77: Assert.assertNotSame(0, logGroup.getLogFiles().size());
78: }
79:
80: Assert.assertEquals("notepad.exe", userConfig
81: .getTextEditorPath());
82: } catch (Exception e) {
83: Assert.fail(e.getMessage());
84: e.printStackTrace();
85: }
86: }
87:
88: }
|