KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > tracelog > testcases > TXMLConfigFile


1 package net.sourceforge.tracelog.testcases;
2
3 import java.util.List JavaDoc;
4
5 import net.sourceforge.tracelog.config.ConfigFile;
6 import net.sourceforge.tracelog.config.ConfigFileFactory;
7 import net.sourceforge.tracelog.config.LogFile;
8 import net.sourceforge.tracelog.config.LogGroup;
9 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 readConfig() {
18         ConfigFile configFile = ConfigFileFactory.getInstance().getConfigFile();
19
20         try {
21             UserConfig userConfig = configFile.getUserConfig();
22             Assert.assertEquals("notepad.exe", userConfig.getTextEditorPath());
23
24             List JavaDoc<LogGroup> logGroups = userConfig.getLogGroups();
25
26             Assert.assertEquals(1, logGroups.size());
27
28             for (LogGroup logGroup : logGroups) {
29                 Assert.assertEquals("default", logGroup.getGroupName());
30                 Assert.assertEquals(1, logGroup.getGroupOrder());
31
32                 Assert.assertNotSame(0, logGroup.getLogFiles().size());
33             }
34
35             Assert.assertEquals("notepad.exe", userConfig.getTextEditorPath());
36         }
37         catch (Exception JavaDoc e) {
38             Assert.fail(e.getMessage());
39             e.printStackTrace();
40         }
41     }
42
43     @Test
44     public void changeTextEditorPath() {
45         ConfigFile configFile = ConfigFileFactory.getInstance().getConfigFile();
46
47         try {
48             UserConfig userConfig = configFile.getUserConfig();
49             userConfig.setTextEditorPath("notepad2.exe");
50
51             Assert.assertEquals("notepad2.exe", userConfig.getTextEditorPath());
52         }
53         catch (Exception JavaDoc e) {
54             Assert.fail(e.getMessage());
55             e.printStackTrace();
56         }
57     }
58
59     @Test
60     public void addLogFile() {
61         ConfigFile configFile = ConfigFileFactory.getInstance().getConfigFile();
62
63         try {
64             UserConfig userConfig = configFile.getUserConfig();
65             List JavaDoc<LogGroup> logGroups = userConfig.getLogGroups();
66
67             LogFile logFile = new LogFile(100, "testlog", "testlog.txt", 1, 1);
68
69             List JavaDoc<LogFile> logFiles = logGroups.get(0).getLogFiles();
70
71             int beforeSize = logFiles.size();
72             logFiles.add(logFile);
73
74             configFile.saveUserConfig(userConfig);
75
76             Assert.assertEquals(beforeSize + 1, logFiles.size());
77         }
78         catch (Exception JavaDoc e) {
79             Assert.fail(e.getMessage());
80             e.printStackTrace();
81         }
82     }
83
84 }
85
Popular Tags