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 edu.sampleu.travel.dataobject;
017
018import edu.sampleu.travel.options.PostalCountryCode;
019import edu.sampleu.travel.options.PostalStateCode;
020import edu.sampleu.travel.options.TripType;
021import org.junit.Test;
022import org.kuali.rice.krad.service.KRADServiceLocator;
023import org.kuali.rice.krad.test.KRADTestCase;
024import org.kuali.rice.test.BaselineTestCase;
025
026import static org.junit.Assert.assertEquals;
027import static org.junit.Assert.assertNotNull;
028import static org.junit.Assert.assertTrue;
029
030/**
031 * Tests basic {@code TravelDestination} persistence.
032 *
033 * @author Kuali Rice Team (rice.collab@kuali.org)
034 */
035@BaselineTestCase.BaselineMode(BaselineTestCase.Mode.ROLLBACK_CLEAR_DB)
036public class TravelDestinationTest extends KRADTestCase {
037
038    private static final String DESTINATION_NAME = PostalStateCode.PR.getLabel();
039    private static final String COUNTRY_CODE = PostalCountryCode.US.getCode();
040    private static final String STATE_CODE = PostalStateCode.PR.getCode();
041
042    /**
043     * Tests basic {@code TravelDestination} persistence by saving it, reloading it, and checking the data.
044     */
045    @Test
046    public void testTravelDestination() {
047        assertTrue(TravelDestination.class.getName() + " is not mapped in JPA",
048                KRADServiceLocator.getDataObjectService().supports(TravelDestination.class));
049
050        String id = createTravelDestination();
051
052        TravelDestination travelDestination = KRADServiceLocator.getDataObjectService().find(TravelDestination.class, id);
053        assertNotNull("Travel Destination ID is null", travelDestination.getTravelDestinationId());
054        assertEquals("Travel Destination name is incorrect", DESTINATION_NAME, travelDestination.getTravelDestinationName());
055        assertEquals("Travel Destination country is incorrect", COUNTRY_CODE, travelDestination.getCountryCd());
056        assertEquals("Travel Destination state is incorrect", STATE_CODE, travelDestination.getStateCd());
057        assertTrue("Travel Destination is not active", travelDestination.isActive());
058    }
059
060    private String createTravelDestination() {
061        TravelDestination travelDestination = new TravelDestination();
062        travelDestination.setTravelDestinationName(DESTINATION_NAME);
063        travelDestination.setCountryCd(COUNTRY_CODE);
064        travelDestination.setStateCd(STATE_CODE);
065        travelDestination.setActive(true);
066
067        return KRADServiceLocator.getDataObjectService().save(travelDestination).getTravelDestinationId();
068    }
069}