1 package net.sourceforge.pmd.util.database;
2
3 import java.io.File;
4 import java.io.FileOutputStream;
5 import java.io.PrintStream;
6 import java.util.Map.Entry;
7 import java.util.Properties;
8 import java.util.ResourceBundle;
9 import junit.framework.Test;
10 import junit.framework.TestCase;
11 import junit.framework.TestSuite;
12
13
14
15
16
17 public class DBTypeTest extends TestCase {
18
19 private static String TEST_FILE_NAME ="/tmp/test.properties";
20
21 private File absoluteFile = new File(TEST_FILE_NAME);
22
23 private Properties testProperties;
24 private Properties includeProperties;
25
26 public DBTypeTest(String testName) {
27 super(testName);
28 }
29
30 public static Test suite() {
31 TestSuite suite = new TestSuite(DBTypeTest.class);
32 return suite;
33 }
34
35 @Override
36 protected void setUp() throws Exception {
37 super.setUp();
38
39 testProperties = new Properties();
40 testProperties.put("prop1", "value1");
41 testProperties.put("prop2", "value2");
42 testProperties.put("prop3", "value3");
43
44 includeProperties = new Properties();
45 includeProperties.putAll(testProperties);
46 includeProperties.put("prop3", "include3");
47
48 FileOutputStream fileOutputStream = new FileOutputStream(absoluteFile);
49 PrintStream printStream = new PrintStream(fileOutputStream);
50
51 for (Entry entry : testProperties.entrySet() )
52 {
53 printStream.printf("%s=%s\n", entry.getKey(), entry.getValue());
54 }
55
56 }
57
58 @Override
59 protected void tearDown() throws Exception {
60 testProperties = null;
61 super.tearDown();
62 }
63
64
65
66
67 public void testGetPropertiesFromFile() throws Exception {
68 System.out.println("getPropertiesFromFile");
69 DBType instance = new DBType("/tmp/test.properties");
70 Properties expResult = testProperties;
71 Properties result = instance.getProperties();
72 assertEquals(expResult, result);
73
74
75 }
76
77
78
79
80 public void testGetProperties() throws Exception {
81 System.out.println("testGetProperties");
82 DBType instance = new DBType("test");
83 Properties expResult = testProperties;
84 System.out.println("testGetProperties: expected results "+ testProperties);
85 Properties result = instance.getProperties();
86 System.out.println("testGetProperties: actual results "+ result);
87 assertEquals(expResult, result);
88
89
90 }
91
92
93
94
95 public void testGetIncludeProperties() throws Exception {
96 System.out.println("testGetIncludeProperties");
97 DBType instance = new DBType("include");
98 Properties expResult = includeProperties;
99 System.out.println("testGetIncludeProperties: expected results "+ includeProperties);
100 Properties result = instance.getProperties();
101 System.out.println("testGetIncludeProperties: actual results "+ result);
102 assertEquals(expResult, result);
103
104
105 }
106
107
108
109
110 public void testAsProperties() {
111 System.out.println("asProperties");
112 ResourceBundle bundle = ResourceBundle.getBundle(DBType.class.getCanonicalName()+".test");
113 Properties expResult = testProperties;
114 Properties result = DBType.getResourceBundleAsProperties(bundle);
115 assertEquals(expResult, result);
116
117
118 }
119 }