001    /*
002     * Copyright 2006-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    
017    package edu.samplu.travel.krad.test;
018    
019    import edu.sampleu.travel.bo.TravelAccount;
020    import edu.sampleu.travel.bo.TravelAccountExtension;
021    import edu.sampleu.travel.bo.TravelAccountType;
022    import org.junit.Assert;
023    import org.junit.Test;
024    import org.kuali.rice.core.api.util.type.KualiPercent;
025    import org.kuali.rice.kew.api.exception.WorkflowException;
026    import org.kuali.rice.krad.exception.ValidationException;
027    import org.kuali.rice.krad.service.BusinessObjectService;
028    import org.kuali.rice.krad.service.KRADServiceLocator;
029    import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
030    import org.kuali.rice.location.impl.campus.CampusTypeBo;
031    import org.kuali.rice.test.BaselineTestCase;
032    import org.kuali.test.BaseMaintenanceDocumentTest;
033    /*
034    import org.kuali.rice.test.BaselineTestCase;
035    import org.kuali.test.BaseMaintenanceDocumentTest;
036    */
037    
038    import java.util.HashMap;
039    
040    import static junit.framework.Assert.assertNotNull;
041    
042    /**
043     * TravelAccountMaintenanceDocumentTest tests that the TravelAccountMaintenanceDocument can be routed to final
044     *
045     */
046    @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
047    public class TravelAccountMaintenanceDocumentTest extends BaseMaintenanceDocumentTest {
048        private BusinessObjectService businessObjectService;
049        String travAcctNumber = "8097";
050    
051        @Override
052        public void setUp() throws Exception {
053            super.setUp();
054            businessObjectService = KRADServiceLocator.getBusinessObjectService();
055    
056        }
057    
058        @Override
059        protected Object getNewMaintainableObject()  {
060            // create new account
061            TravelAccount ac = new TravelAccount();
062            ac.setName("unit-test-acc");
063            ac.setSubsidizedPercent(new KualiPercent(0.02));
064            ac.setNumber(travAcctNumber);
065    
066            //set the account type
067            TravelAccountExtension travExtension = new TravelAccountExtension();
068    
069            HashMap<String, String> primaryKeys = new HashMap<String, String>(1);
070            primaryKeys.put("accountTypeCode", "EAT");
071            TravelAccountType expAcctType = businessObjectService.findByPrimaryKey(TravelAccountType.class, primaryKeys);
072            travExtension.setAccountType(expAcctType);
073            travExtension.setNumber(travAcctNumber);
074    
075            ac.setExtension(travExtension);
076    
077    
078            return ac;
079        }
080    
081        @Override
082        protected String getDocumentTypeName() {
083            return "TravelAccountMaintenanceDocument";
084        }
085    
086        @Override
087        protected String getInitiatorPrincipalName() {
088            return "admin";
089        }
090    
091        @Override
092        protected Object getOldMaintainableObject() {
093            return getNewMaintainableObject();
094        }
095    
096        @Test
097        /**
098         * test that a validation error occurs when a business object is missing required fields
099         */
100        public void testRouteNewDoc() throws WorkflowException {
101            setupNewAccountMaintDoc(getDocument());
102            KRADServiceLocatorWeb.getDocumentService().routeDocument(getDocument(), "submit", null);
103            Assert.assertTrue(getDocument().getDocumentHeader().getWorkflowDocument().isFinal());
104            //check for account
105            HashMap<String, String> primaryKeys = new HashMap<String, String>(1);
106            primaryKeys.put("number", travAcctNumber);
107            TravelAccount travAcct = businessObjectService.findByPrimaryKey(TravelAccount.class, primaryKeys);
108            assertNotNull(travAcct);
109        }
110    }