View Javadoc

1   /*
2    * Copyright 2005-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.kns.util.properties;
18  
19  import org.junit.Test;
20  import org.kuali.rice.kns.exception.PropertiesException;
21  import org.kuali.rice.kns.util.properties.FilePropertySource;
22  import org.kuali.test.KNSTestCase;
23  
24  /**
25   * This class tests the FilePropertySource methods.
26   */
27  public class FilePropertySourceTest extends KNSTestCase {
28  
29      @Test public void testLoadProperties_defaultFileName() {
30          FilePropertySource fps = new FilePropertySource();
31  
32          boolean failedAsExpected = false;
33          try {
34              fps.loadProperties();
35          }
36          catch (IllegalStateException e) {
37              failedAsExpected = true;
38          }
39  
40          assertTrue(failedAsExpected);
41      }
42  
43      @Test public void testLoadProperties_invalidFileName() {
44          FilePropertySource fps = new FilePropertySource();
45          fps.setFileName("      ");
46  
47          boolean failedAsExpected = false;
48          try {
49              fps.loadProperties();
50          }
51          catch (IllegalStateException e) {
52              failedAsExpected = true;
53          }
54  
55          assertTrue(failedAsExpected);
56      }
57  
58      @Test public void testLoadProperties_unknownFileName() {
59          FilePropertySource fps = new FilePropertySource();
60          fps.setFileName("unknown");
61  
62          boolean failedAsExpected = false;
63          try {
64              fps.loadProperties();
65          }
66          catch (PropertiesException e) {
67              failedAsExpected = true;
68          }
69  
70          assertTrue(failedAsExpected);
71      }
72  
73      @Test public void testLoadProperties_knownFileName_noSuffix() {
74          FilePropertySource fps = new FilePropertySource();
75          fps.setFileName("configuration");
76  
77          boolean failedAsExpected = false;
78          try {
79              fps.loadProperties();
80          }
81          catch (PropertiesException e) {
82              failedAsExpected = true;
83          }
84  
85          assertTrue(failedAsExpected);
86      }
87  }