View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.sys.context;
20  
21  import org.kuali.kfs.coa.businessobject.Account;
22  import org.kuali.kfs.gl.batch.service.impl.BalancingServiceBaseImpl;
23  import org.kuali.kfs.gl.businessobject.Balance;
24  import org.kuali.kfs.gl.businessobject.Entry;
25  import org.kuali.kfs.sys.ConfigureContext;
26  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
27  
28  /**
29   * Yes, we need to test our test utilities since they seem to be misbehaving in some areas.
30   * 
31   */
32  @ConfigureContext
33  public class TestUtilsTest extends KualiTestBase {
34  
35      public static final String TEST_PARAM_NAME = "FUND_GROUP_DENOTES_CG_IND";
36      public static final Class TEST_PARAM_COMPONENT = Account.class;
37      
38      public void testSetSystemParameter1() throws Exception {
39          String dbValue = SpringContext.getBean(ParameterService.class).getParameterValueAsString(TEST_PARAM_COMPONENT, TEST_PARAM_NAME);
40          assertEquals( "indicator must be true", "Y", dbValue );
41          TestUtils.setSystemParameter(TEST_PARAM_COMPONENT, TEST_PARAM_NAME, "N");
42          String cachedValue = SpringContext.getBean(ParameterService.class).getParameterValueAsString(TEST_PARAM_COMPONENT, TEST_PARAM_NAME);
43          assertEquals( "indicator must be false when pulled after the set", "N", cachedValue );        
44      }
45  
46      public void testSetSystemParameter2() throws Exception {
47          String dbValue = SpringContext.getBean(ParameterService.class).getParameterValueAsString(TEST_PARAM_COMPONENT, TEST_PARAM_NAME);
48          assertEquals( "indicator must be true", "Y", dbValue );
49      }
50      
51      @ConfigureContext(shouldCommitTransactions=true)
52      public void testSetSystemParameterFailsWhenNonRollback() throws Exception {
53          try {
54              TestUtils.setSystemParameter(TEST_PARAM_COMPONENT, TEST_PARAM_NAME, "N");
55              fail( "TestUtils.setSystemParameter() did not fail when called from a committing test.");
56          } catch ( Exception ex ) {
57              System.err.println( ex.getMessage() );
58              // failed as expected
59          }
60      }
61  
62      @ConfigureContext(shouldCommitTransactions=false)
63      public void testSetSystemParameterSucceedsWhenRollback() throws Exception {
64          try {
65              TestUtils.setSystemParameter(TEST_PARAM_COMPONENT, TEST_PARAM_NAME, "N");
66          } catch ( Exception ex ) {
67              fail( "TestUtils.setSystemParameter() failed when called from a non-committing test: " + ex.getMessage() );
68          }
69      }
70  
71      public void testGetUnproxiedService() {
72          try {
73              BalancingServiceBaseImpl<Entry, Balance> balancingService = (BalancingServiceBaseImpl<Entry, Balance>) TestUtils.getUnproxiedService("laborBalancingService");
74              assertNotNull(balancingService);
75          }
76          catch (Exception e) {
77              assertTrue("testGetUnproxiedService failed due to stacktrace: " + e.getMessage(), false);
78          }
79      }
80  }