]> jaekl.net Git - cfb.git/blob - test/net/jaekl/cfb/ConfigTest.java
Store db parameters in Config object, not in CFB object.
[cfb.git] / test / net / jaekl / cfb / ConfigTest.java
1 package net.jaekl.cfb;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
5
6 import java.io.IOException;
7 import java.util.List;
8
9 import net.jaekl.qd.util.FileIOMock;
10 import net.jaekl.qd.util.FileMock;
11
12 import org.junit.AfterClass;
13 import org.junit.BeforeClass;
14 import org.junit.Test;
15
16 public class ConfigTest {
17         private static final String CHRIS = "chris@localhost";
18         private static final String DB_HOST = "dbserver";
19         private static final int    DB_PORT = 1234;
20         private static final String DB_NAME = "Fred";
21         private static final String DB_PASS = "Pebbles";
22         private static final String DB_USER = "Wilma";
23         private static final String HUDSON = "hudson@jenkins.org";
24         private static final String MAIL_FROM = "findbugs@jaekl.net";
25         private static final String MAIL_TO = CHRIS + "," + HUDSON;
26         private static final String LOCALHOST = "localhost";
27
28         private static final String SAMPLE1 = 
29                           "; Path (relative or absolute) to the FINDBUGS_HOME, i.e., where FindBugs is installed\n"
30                         + "FindBugsHome=../findbugs-3.0.1/\n"
31                         + "; List (comma-separated) of email addresses to which notifications should be sent\n"
32                         + "notify=" + MAIL_TO + "\n"
33                         + "\n"
34                         + "; Mail server setup\n"
35                         + "mail.smtp.host=" + LOCALHOST + "\n"
36                         + "mail.from=" + MAIL_FROM + "\n"
37                         + "\n"
38                         + "; Database\n"
39                         + "db.host=" + DB_HOST + "\n"
40                         + "db.port=" + DB_PORT + "\n"
41                         + "db.name=" + DB_NAME + "\n"
42                         + "db.user=" + DB_USER + "\n"
43                         + "db.pass=" + DB_PASS + "\n";
44
45         @BeforeClass 
46         public static void beforeClass() {
47                 FileIOMock.mock_setInstance();
48         }
49         
50         @AfterClass
51         public static void afterClass() {
52                 FileIOMock.mock_clearInstance();
53         }
54         
55         @Test
56         public void testReadFile() throws IOException {
57                 Config config = new Config();
58                 
59                 FileMock fm = new FileMock("config.properties");
60                 fm.mock_setContent(SAMPLE1);
61                 
62                 config.readFile(fm);
63                 
64                 assertEquals(MAIL_FROM, config.getMailFrom());
65                 assertEquals(LOCALHOST, config.getMailSmtpHost());
66                 
67                 List<String> notify = config.getNotify();
68                 assertTrue(notify.contains(CHRIS));
69                 assertTrue(notify.contains(HUDSON));
70                 
71                 assertEquals(DB_HOST, config.getDbHost());
72                 assertEquals(DB_PORT, config.getDbPort());
73                 assertEquals(DB_NAME, config.getDbName());
74                 assertEquals(DB_USER, config.getDbUser());
75                 assertEquals(DB_PASS, config.getDbPass());
76         }
77         
78         @Test
79         public void testReadEmptyFile() throws IOException {
80                 Config config = new Config();
81                 FileMock fm = new FileMock("empty.properties");
82                 fm.mock_setContent("");
83                 
84                 config.readFile(fm);
85                 
86                 assertEquals("findbugs@localhost", config.getMailFrom());
87                 assertEquals("localhost", config.getMailSmtpHost());
88                 assertEquals(0, config.getNotify().size());
89         }
90 }