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 */
016package org.kuali.rice.krad.service;
017
018import org.junit.Test;
019import org.kuali.rice.kns.service.KNSServiceLocator;
020import org.kuali.rice.krad.test.KRADTestCase;
021
022import static org.junit.Assert.assertTrue;
023
024/**
025 * tests {@link org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService}
026 */
027public class MaintenanceDocumentDictionaryServiceTest extends KRADTestCase {
028
029    private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(MaintenanceDocumentDictionaryServiceTest.class);
030
031    /**
032     * tests to make sure <code>IllegalArgumentExceptions</code> are being thrown on null parameters
033     */
034    @Test public void testGetFieldDefaultValue_NullArguments() {
035
036        boolean exceptionThrown;
037
038        // test the boClass null argument
039        exceptionThrown = false;
040        try {
041            KNSServiceLocator.getMaintenanceDocumentDictionaryService().getFieldDefaultValue((Class) null, "accountNumber");
042        }
043        catch (IllegalArgumentException e) {
044            exceptionThrown = true;
045        }
046        catch (Exception e) {
047            exceptionThrown = false;
048        }
049        assertTrue("An IllegalArgumentException should have been thrown.", exceptionThrown);
050
051        // test the docTypeName null argument
052        exceptionThrown = false;
053        try {
054            KNSServiceLocator.getMaintenanceDocumentDictionaryService().getFieldDefaultValue((String) null, "accountNumber");
055        }
056        catch (IllegalArgumentException e) {
057            exceptionThrown = true;
058        }
059        catch (Exception e) {
060            exceptionThrown = false;
061        }
062        assertTrue("An IllegalArgumentException should have been thrown.", exceptionThrown);
063
064        // test the fieldName null argument
065        exceptionThrown = false;
066        try {
067            KNSServiceLocator.getMaintenanceDocumentDictionaryService().getFieldDefaultValue("docTypeName", null);
068        }
069        catch (IllegalArgumentException e) {
070            exceptionThrown = true;
071        }
072        catch (Exception e) {
073            exceptionThrown = false;
074        }
075        assertTrue("An IllegalArgumentException should have been thrown.", exceptionThrown);
076    }
077
078//    @Test public void testGetFieldDefaultValue_Account() {
079//
080//        String result;
081//        result = KRADServiceLocatorInternal.getMaintenanceDocumentDictionaryService().getFieldDefaultValue(AccountManager.class, "defaultType");
082//        LOG.debug(result);
083//        assertEquals("Standard", result);
084//
085//    }
086//
087//    @Test public void testGetFieldDefaultValue_SubAccount() {
088//
089//        String result;
090//        result = KRADServiceLocatorInternal.getMaintenanceDocumentDictionaryService().getFieldDefaultValue(SubAccount.class, "subAccountActiveIndicator");
091//        LOG.debug(result);
092//        assertEquals("true", result);
093//
094//        result = KRADServiceLocatorInternal.getMaintenanceDocumentDictionaryService().getFieldDefaultValue(SubAccount.class, "a21SubAccount.subAccountTypeCode");
095//        LOG.debug(result);
096//        assertEquals("EX", result);
097//
098//        result = KRADServiceLocatorInternal.getMaintenanceDocumentDictionaryService().getFieldDefaultValue(SubAccount.class, "a21SubAccount.offCampusCode");
099//        LOG.debug(result);
100//        assertEquals("false", result);
101//
102//    }
103//
104//    @Test public void testGetFieldDefaultValue_SubObjectCode() {
105//
106//        String result;
107//
108//        result = KRADServiceLocatorInternal.getMaintenanceDocumentDictionaryService().getFieldDefaultValue(SubObjCd.class, "universityFiscalYear");
109//        LOG.debug(result);
110//        assertEquals(getValueFromFinder(FiscalYearFinder.class), result);
111//
112//        result = KRADServiceLocatorInternal.getMaintenanceDocumentDictionaryService().getFieldDefaultValue(SubObjCd.class, "financialSubObjectActiveIndicator");
113//        LOG.debug(result);
114//        assertEquals("true", result);
115//
116//    }
117//
118//    private String getValueFromFinder(Class finderClass) {
119//
120//        ValueFinder valueFinder = null;
121//        try {
122//            valueFinder = (ValueFinder) finderClass.newInstance();
123//        }
124//        catch (InstantiationException e) {
125//            e.printStackTrace();
126//            assertTrue("An InstantiationException should not have been thrown.", false);
127//        }
128//        catch (IllegalAccessException e) {
129//            e.printStackTrace();
130//            assertTrue("An IllegalAccessException should not have been thrown.", false);
131//        }
132//
133//        assertNotNull("The valueFinder object should not be null.", valueFinder);
134//
135//        return valueFinder.getValue();
136//    }
137}