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     */
016    package edu.sampleu.travel.dataobject;
017    
018    import org.junit.Test;
019    import org.kuali.rice.krad.service.KRADServiceLocator;
020    import org.kuali.rice.krad.test.KRADTestCase;
021    import org.kuali.rice.test.BaselineTestCase;
022    
023    import java.math.BigDecimal;
024    
025    import static org.junit.Assert.assertEquals;
026    import static org.junit.Assert.assertNotNull;
027    import static org.junit.Assert.assertTrue;
028    
029    /**
030     * Tests basic {@code TravelMileageRate} persistence.
031     *
032     * @author Kuali Rice Team (rice.collab@kuali.org)
033     */
034    @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.ROLLBACK_CLEAR_DB)
035    public class TravelMileageRateTest extends KRADTestCase {
036    
037        private static final String MILEAGE_RATE_CODE = "IL";
038        private static final String MILEAGE_RATE_NAME = "International";
039        private static final BigDecimal MILEAGE_RATE = new BigDecimal("50");
040    
041        /**
042         * Tests basic {@code TravelMileageRate} persistence by saving it, reloading it, and checking the data.
043         */
044        @Test
045        public void testTravelMileageRate() {
046            assertTrue(TravelMileageRate.class.getName() + " is not mapped in JPA",
047                    KRADServiceLocator.getDataObjectService().supports(TravelMileageRate.class));
048    
049            String id = createTravelMileageRate();
050    
051            TravelMileageRate travelMileageRate = KRADServiceLocator.getDataObjectService().find(TravelMileageRate.class, id);
052            assertNotNull("Travel Mileage Rate ID is null", travelMileageRate.getMileageRateId());
053            assertEquals("Travel Mileage Rate code is incorrect", MILEAGE_RATE_CODE, travelMileageRate.getMileageRateCd());
054            assertEquals("Travel Mileage Rate name is incorrect", MILEAGE_RATE_NAME, travelMileageRate.getMileageRateName());
055            assertEquals("Travel Mileage Rate amount is incorrect", MILEAGE_RATE, travelMileageRate.getMileageRate());
056            assertTrue("Travel Mileage Rate is not active", travelMileageRate.isActive());
057        }
058    
059        private String createTravelMileageRate() {
060            TravelMileageRate travelMileageRate = new TravelMileageRate();
061            travelMileageRate.setMileageRateCd(MILEAGE_RATE_CODE);
062            travelMileageRate.setMileageRateName(MILEAGE_RATE_NAME);
063            travelMileageRate.setMileageRate(MILEAGE_RATE);
064            travelMileageRate.setActive(true);
065    
066            return KRADServiceLocator.getDataObjectService().save(travelMileageRate).getMileageRateId();
067        }
068    }