001 /** 002 * Copyright 2005-2012 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.maintainable; 017 018 import org.junit.Before; 019 import org.junit.Test; 020 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; 021 import org.kuali.rice.kns.maintenance.Maintainable; 022 023 import static org.junit.Assert.assertFalse; 024 import static org.junit.Assert.assertTrue; 025 026 /** 027 * Test methods for default Kuali maintainable implementation. 028 */ 029 public class KualiMaintainableTest { 030 Maintainable maintainable = null; 031 032 033 @Before 034 public void setUp() throws Exception { 035 maintainable = new KualiMaintainableImpl(); 036 } 037 038 /** 039 * Tests the retrieval of the inactive record display setting when it has not been set (default). Default 040 * should be false according to specification. 041 */ 042 @Test 043 public void testGetShowInactiveRecords_Default() throws Exception { 044 boolean displayInactive = maintainable.getShowInactiveRecords("fooCollection"); 045 assertTrue("display setting returned true for unset collection", displayInactive); 046 } 047 048 /** 049 * Tests method throws an exception when given name is null. 050 */ 051 @Test 052 public void testGetShowInactiveRecords_NullParam() throws Exception { 053 boolean failedAsExpected = false; 054 try { 055 maintainable.getShowInactiveRecords(null); 056 } 057 catch (IllegalArgumentException expected) { 058 failedAsExpected = true; 059 } 060 061 assertTrue("exception not thrown for null collection name", failedAsExpected); 062 } 063 064 /** 065 * Tests setting to display inactive records for a collection. 066 */ 067 @Test 068 public void testSetShowInactiveRecords_DisplayCollectionInActive() throws Exception { 069 maintainable.setShowInactiveRecords("collection1", true); 070 assertTrue("state failure on set inactive display to true", maintainable.getShowInactiveRecords("collection1")); 071 } 072 073 /** 074 * Tests setting to not display inactive records for a collection. 075 */ 076 @Test 077 public void testSetShowInactiveRecords_NoDisplayCollectionInActive() throws Exception { 078 maintainable.setShowInactiveRecords("collection1", false); 079 assertFalse("state failure on set inactive display to false", maintainable.getShowInactiveRecords("collection1")); 080 } 081 082 /** 083 * Tests setting to display inactive records for a sub-collection. 084 */ 085 @Test 086 public void testSetShowInactiveRecords_DisplaySubCollectionInActive() throws Exception { 087 maintainable.setShowInactiveRecords("collection1.subCollection", true); 088 assertTrue("state failure on set inactive display to true", maintainable.getShowInactiveRecords("collection1.subCollection")); 089 } 090 091 /** 092 * Tests setting to not display inactive records for a sub-collection. 093 */ 094 @Test 095 public void testSetShowInactiveRecords_NoDisplaySubCollectionInActive() throws Exception { 096 maintainable.setShowInactiveRecords("collection1.subCollection", false); 097 assertFalse("state failure on set inactive display to false", maintainable.getShowInactiveRecords("collection1.subCollection")); 098 } 099 100 /** 101 * Tests method throws an exception when given name is null. 102 */ 103 @Test 104 public void testSetShowInactiveRecords_NullParam() throws Exception { 105 boolean failedAsExpected = false; 106 try { 107 maintainable.setShowInactiveRecords(null, true); 108 } 109 catch (IllegalArgumentException expected) { 110 failedAsExpected = true; 111 } 112 113 assertTrue("exception not thrown for null collection name", failedAsExpected); 114 } 115 }