View Javadoc

1   /*
2    * Copyright 2006-2008 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }