View Javadoc
1   /**
2    * Copyright 2005-2014 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  package edu.sampleu.travel.dataobject;
17  
18  import org.junit.Test;
19  import org.kuali.rice.krad.service.KRADServiceLocator;
20  import org.kuali.rice.krad.test.KRADTestCase;
21  import org.kuali.rice.test.BaselineTestCase;
22  
23  import java.math.BigDecimal;
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertNotNull;
27  import static org.junit.Assert.assertTrue;
28  
29  /**
30   * Tests basic {@code TravelMileageRate} persistence.
31   *
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.ROLLBACK_CLEAR_DB)
35  public class TravelMileageRateTest extends KRADTestCase {
36  
37      private static final String MILEAGE_RATE_CODE = "IL";
38      private static final String MILEAGE_RATE_NAME = "International";
39      private static final BigDecimal MILEAGE_RATE = new BigDecimal("50");
40  
41      /**
42       * Tests basic {@code TravelMileageRate} persistence by saving it, reloading it, and checking the data.
43       */
44      @Test
45      public void testTravelMileageRate() {
46          assertTrue(TravelMileageRate.class.getName() + " is not mapped in JPA",
47                  KRADServiceLocator.getDataObjectService().supports(TravelMileageRate.class));
48  
49          String id = createTravelMileageRate();
50  
51          TravelMileageRate travelMileageRate = KRADServiceLocator.getDataObjectService().find(TravelMileageRate.class, id);
52          assertNotNull("Travel Mileage Rate ID is null", travelMileageRate.getMileageRateId());
53          assertEquals("Travel Mileage Rate code is incorrect", MILEAGE_RATE_CODE, travelMileageRate.getMileageRateCd());
54          assertEquals("Travel Mileage Rate name is incorrect", MILEAGE_RATE_NAME, travelMileageRate.getMileageRateName());
55          assertEquals("Travel Mileage Rate amount is incorrect", MILEAGE_RATE, travelMileageRate.getMileageRate());
56          assertTrue("Travel Mileage Rate is not active", travelMileageRate.isActive());
57      }
58  
59      private String createTravelMileageRate() {
60          TravelMileageRate travelMileageRate = new TravelMileageRate();
61          travelMileageRate.setMileageRateCd(MILEAGE_RATE_CODE);
62          travelMileageRate.setMileageRateName(MILEAGE_RATE_NAME);
63          travelMileageRate.setMileageRate(MILEAGE_RATE);
64          travelMileageRate.setActive(true);
65  
66          return KRADServiceLocator.getDataObjectService().save(travelMileageRate).getMileageRateId();
67      }
68  }