View Javadoc

1   /*
2    * Copyright 2006-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package edu.samplu.travel.krad.test;
18  
19  import edu.sampleu.travel.bo.TravelAccount;
20  import edu.sampleu.travel.bo.TravelAccountExtension;
21  import edu.sampleu.travel.bo.TravelAccountType;
22  import org.junit.Assert;
23  import org.junit.Test;
24  import org.kuali.rice.core.api.util.type.KualiPercent;
25  import org.kuali.rice.kew.api.exception.WorkflowException;
26  import org.kuali.rice.krad.exception.ValidationException;
27  import org.kuali.rice.krad.service.BusinessObjectService;
28  import org.kuali.rice.krad.service.KRADServiceLocator;
29  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
30  import org.kuali.rice.location.impl.campus.CampusTypeBo;
31  import org.kuali.rice.test.BaselineTestCase;
32  import org.kuali.test.BaseMaintenanceDocumentTest;
33  /*
34  import org.kuali.rice.test.BaselineTestCase;
35  import org.kuali.test.BaseMaintenanceDocumentTest;
36  */
37  
38  import java.util.HashMap;
39  
40  import static junit.framework.Assert.assertNotNull;
41  
42  /**
43   * TravelAccountMaintenanceDocumentTest tests that the TravelAccountMaintenanceDocument can be routed to final
44   *
45   */
46  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
47  public class TravelAccountMaintenanceDocumentTest extends BaseMaintenanceDocumentTest {
48      private BusinessObjectService businessObjectService;
49      String travAcctNumber = "8097";
50  
51      @Override
52      public void setUp() throws Exception {
53          super.setUp();
54          businessObjectService = KRADServiceLocator.getBusinessObjectService();
55  
56      }
57  
58      @Override
59      protected Object getNewMaintainableObject()  {
60          // create new account
61          TravelAccount ac = new TravelAccount();
62          ac.setName("unit-test-acc");
63          ac.setSubsidizedPercent(new KualiPercent(0.02));
64          ac.setNumber(travAcctNumber);
65  
66          //set the account type
67          TravelAccountExtension travExtension = new TravelAccountExtension();
68  
69          HashMap<String, String> primaryKeys = new HashMap<String, String>(1);
70          primaryKeys.put("accountTypeCode", "EAT");
71          TravelAccountType expAcctType = businessObjectService.findByPrimaryKey(TravelAccountType.class, primaryKeys);
72          travExtension.setAccountType(expAcctType);
73          travExtension.setNumber(travAcctNumber);
74  
75          ac.setExtension(travExtension);
76  
77  
78          return ac;
79      }
80  
81      @Override
82      protected String getDocumentTypeName() {
83          return "TravelAccountMaintenanceDocument";
84      }
85  
86      @Override
87      protected String getInitiatorPrincipalName() {
88          return "admin";
89      }
90  
91      @Override
92      protected Object getOldMaintainableObject() {
93          return getNewMaintainableObject();
94      }
95  
96      @Test
97      /**
98       * test that a validation error occurs when a business object is missing required fields
99       */
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 }