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