1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.core.config;
18
19 import java.io.File;
20 import java.io.FileInputStream;
21 import java.io.IOException;
22 import java.util.Properties;
23
24 import junit.framework.TestCase;
25
26 import org.junit.Test;
27 import org.kuali.rice.core.config.SimpleNodeSettingsStore;
28
29 public class SimpleNodeSettingStoreTest extends TestCase {
30
31 @Test public void test() throws Exception {
32 SimpleNodeSettingsStore s = new SimpleNodeSettingsStore();
33 File f = File.createTempFile("simplenodesettingstoretest", "unittest");
34 f.deleteOnExit();
35 s.setPropertiesPath(f.getAbsolutePath());
36 s.afterPropertiesSet();
37 assertEquals(0, s.getSettings().size());
38 s.setSetting("foo", "bar");
39
40 assertSetting(f.getAbsolutePath(), "foo", "bar");
41
42 s.removeSetting("foo");
43
44 assertSetting(f.getAbsolutePath(), "foo", null);
45 }
46
47 protected void assertSetting(String path, String name, String value) throws IOException {
48 Properties p = new Properties();
49 FileInputStream fis = new FileInputStream(path);
50 try {
51 p.load(fis);
52 } finally {
53 fis.close();
54 }
55 assertEquals(value, p.getProperty(name));
56 }
57 }