View Javadoc
1   /**
2    * Copyright 2005-2016 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  package org.kuali.rice.core.impl.services;
17  
18  import org.junit.Test;
19  import org.kuali.rice.core.api.exception.RiceRuntimeException;
20  import org.kuali.rice.core.impl.services.ConfigurationServiceImpl;
21  
22  import static org.junit.Assert.assertTrue;
23  
24  /**
25   * This class tests the FilePropertySource methods.
26   */
27  public class FilePropertySourceTest {
28  
29      @Test public void testLoadProperties_defaultFileName() {
30          ConfigurationServiceImpl.FilePropertySource fps = new ConfigurationServiceImpl.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          ConfigurationServiceImpl.FilePropertySource fps = new ConfigurationServiceImpl.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          ConfigurationServiceImpl.FilePropertySource fps = new ConfigurationServiceImpl.FilePropertySource();
60          fps.setFileName("unknown");
61  
62          boolean failedAsExpected = false;
63          try {
64              fps.loadProperties();
65          }
66          catch (RiceRuntimeException e) {
67              failedAsExpected = true;
68          }
69  
70          assertTrue(failedAsExpected);
71      }
72  
73      @Test public void testLoadProperties_knownFileName_noSuffix() {
74          ConfigurationServiceImpl.FilePropertySource fps = new ConfigurationServiceImpl.FilePropertySource();
75          fps.setFileName("configuration");
76  
77          boolean failedAsExpected = false;
78          try {
79              fps.loadProperties();
80          }
81          catch (RiceRuntimeException e) {
82              failedAsExpected = true;
83          }
84  
85          assertTrue(failedAsExpected);
86      }
87  }