001 /** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.krad.service.impl; 017 018 import org.junit.Test; 019 import org.kuali.rice.krad.exception.PropertiesException; 020 021 import static org.junit.Assert.assertTrue; 022 023 /** 024 * This class tests the FilePropertySource methods. 025 */ 026 public class FilePropertySourceTest { 027 028 @Test public void testLoadProperties_defaultFileName() { 029 ConfigurationServiceImpl.FilePropertySource fps = new ConfigurationServiceImpl.FilePropertySource(); 030 031 boolean failedAsExpected = false; 032 try { 033 fps.loadProperties(); 034 } 035 catch (IllegalStateException e) { 036 failedAsExpected = true; 037 } 038 039 assertTrue(failedAsExpected); 040 } 041 042 @Test public void testLoadProperties_invalidFileName() { 043 ConfigurationServiceImpl.FilePropertySource fps = new ConfigurationServiceImpl.FilePropertySource(); 044 fps.setFileName(" "); 045 046 boolean failedAsExpected = false; 047 try { 048 fps.loadProperties(); 049 } 050 catch (IllegalStateException e) { 051 failedAsExpected = true; 052 } 053 054 assertTrue(failedAsExpected); 055 } 056 057 @Test public void testLoadProperties_unknownFileName() { 058 ConfigurationServiceImpl.FilePropertySource fps = new ConfigurationServiceImpl.FilePropertySource(); 059 fps.setFileName("unknown"); 060 061 boolean failedAsExpected = false; 062 try { 063 fps.loadProperties(); 064 } 065 catch (PropertiesException e) { 066 failedAsExpected = true; 067 } 068 069 assertTrue(failedAsExpected); 070 } 071 072 @Test public void testLoadProperties_knownFileName_noSuffix() { 073 ConfigurationServiceImpl.FilePropertySource fps = new ConfigurationServiceImpl.FilePropertySource(); 074 fps.setFileName("configuration"); 075 076 boolean failedAsExpected = false; 077 try { 078 fps.loadProperties(); 079 } 080 catch (PropertiesException e) { 081 failedAsExpected = true; 082 } 083 084 assertTrue(failedAsExpected); 085 } 086 }