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 edu.sampleu.travel.options.PostalCountryCode;
19  import edu.sampleu.travel.options.PostalStateCode;
20  import edu.sampleu.travel.options.TripType;
21  import org.junit.Test;
22  import org.kuali.rice.krad.service.KRADServiceLocator;
23  import org.kuali.rice.krad.test.KRADTestCase;
24  import org.kuali.rice.test.BaselineTestCase;
25  
26  import static org.junit.Assert.assertEquals;
27  import static org.junit.Assert.assertNotNull;
28  import static org.junit.Assert.assertTrue;
29  
30  /**
31   * Tests basic {@code TravelDestination} persistence.
32   *
33   * @author Kuali Rice Team (rice.collab@kuali.org)
34   */
35  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.ROLLBACK_CLEAR_DB)
36  public class TravelDestinationTest extends KRADTestCase {
37  
38      private static final String DESTINATION_NAME = PostalStateCode.PR.getLabel();
39      private static final String COUNTRY_CODE = PostalCountryCode.US.getCode();
40      private static final String STATE_CODE = PostalStateCode.PR.getCode();
41  
42      /**
43       * Tests basic {@code TravelDestination} persistence by saving it, reloading it, and checking the data.
44       */
45      @Test
46      public void testTravelDestination() {
47          assertTrue(TravelDestination.class.getName() + " is not mapped in JPA",
48                  KRADServiceLocator.getDataObjectService().supports(TravelDestination.class));
49  
50          String id = createTravelDestination();
51  
52          TravelDestination travelDestination = KRADServiceLocator.getDataObjectService().find(TravelDestination.class, id);
53          assertNotNull("Travel Destination ID is null", travelDestination.getTravelDestinationId());
54          assertEquals("Travel Destination name is incorrect", DESTINATION_NAME, travelDestination.getTravelDestinationName());
55          assertEquals("Travel Destination country is incorrect", COUNTRY_CODE, travelDestination.getCountryCd());
56          assertEquals("Travel Destination state is incorrect", STATE_CODE, travelDestination.getStateCd());
57          assertTrue("Travel Destination is not active", travelDestination.isActive());
58      }
59  
60      private String createTravelDestination() {
61          TravelDestination travelDestination = new TravelDestination();
62          travelDestination.setTravelDestinationName(DESTINATION_NAME);
63          travelDestination.setCountryCd(COUNTRY_CODE);
64          travelDestination.setStateCd(STATE_CODE);
65          travelDestination.setActive(true);
66  
67          return KRADServiceLocator.getDataObjectService().save(travelDestination).getTravelDestinationId();
68      }
69  }