View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.tem.service;
20  
21  import java.sql.Date;
22  import java.util.HashMap;
23  import java.util.List;
24  
25  import org.junit.Test;
26  import org.kuali.kfs.module.tem.TemConstants;
27  import org.kuali.kfs.module.tem.TemKeyConstants;
28  import org.kuali.kfs.module.tem.businessobject.TemProfile;
29  import org.kuali.kfs.module.tem.businessobject.TravelerType;
30  import org.kuali.kfs.sys.ConfigureContext;
31  import org.kuali.kfs.sys.context.KualiTestBase;
32  import org.kuali.kfs.sys.context.SpringContext;
33  import org.kuali.rice.core.api.datetime.DateTimeService;
34  import org.kuali.rice.kns.datadictionary.validation.fieldlevel.PhoneNumberValidationPattern;
35  import org.kuali.rice.krad.service.BusinessObjectService;
36  import org.kuali.rice.krad.service.SequenceAccessorService;
37  
38  /**
39   *
40   * This class tests the TravelService class
41   */
42  @ConfigureContext
43  public class TravelServiceTest extends KualiTestBase{
44  
45      private TravelService travelService;
46      private DateTimeService dateTimeService;
47      private static final int ONE_DAY = 86400;
48      private BusinessObjectService businessObjectService;
49      private SequenceAccessorService sas;
50  
51      @Override
52      protected void setUp() throws Exception {
53          super.setUp();
54          final TravelService travelServiceTemp = SpringContext.getBean(TravelService.class);
55          businessObjectService = SpringContext.getBean(BusinessObjectService.class);
56          sas = SpringContext.getBean(SequenceAccessorService.class);
57          travelService = SpringContext.getBean(TravelService.class);
58          dateTimeService = SpringContext.getBean(DateTimeService.class);
59      }
60  
61      /**
62       *
63       * This method tests {@link TravelService#validatePhoneNumber(String)}
64       */
65      @Test
66      public void testValidatePhoneNumber_byPhoneNumber() {
67          assertTrue(TemKeyConstants.ERROR_PHONE_NUMBER.equals(travelService.validatePhoneNumber(null, TemKeyConstants.ERROR_PHONE_NUMBER)));
68          assertFalse(TemKeyConstants.ERROR_PHONE_NUMBER.equals(travelService.validatePhoneNumber("123-555-1234", TemKeyConstants.ERROR_PHONE_NUMBER)));
69          assertFalse(TemKeyConstants.ERROR_PHONE_NUMBER.equals(travelService.validatePhoneNumber("123-555-1234 x1234", TemKeyConstants.ERROR_PHONE_NUMBER)));
70      }
71  
72      /**
73       *
74       * This method tests {@link TravelService#validatePhoneNumber(String, String)}
75       */
76      @Test
77      public void testValidatePhoneNumber_byCountryCodeAndPhoneNumber() {
78          // validate International phone numbers
79          assertTrue(TemKeyConstants.ERROR_PHONE_NUMBER.equals(travelService.validatePhoneNumber(null,null,TemKeyConstants.ERROR_PHONE_NUMBER)));
80          assertFalse(TemKeyConstants.ERROR_PHONE_NUMBER.equals(travelService.validatePhoneNumber("UK","555-1234",TemKeyConstants.ERROR_PHONE_NUMBER)));
81          assertFalse(TemKeyConstants.ERROR_PHONE_NUMBER.equals(travelService.validatePhoneNumber("UK","555-1234 x1234",TemKeyConstants.ERROR_PHONE_NUMBER)));
82  
83          // validate US phone numbers
84          PhoneNumberValidationPattern pattern = new PhoneNumberValidationPattern();
85          assertTrue(TemKeyConstants.ERROR_PHONE_NUMBER.equals(travelService.validatePhoneNumber("US","1",TemKeyConstants.ERROR_PHONE_NUMBER)));
86          assertFalse(TemKeyConstants.ERROR_PHONE_NUMBER.equals(travelService.validatePhoneNumber("US","123-555-1234",TemKeyConstants.ERROR_PHONE_NUMBER)));
87          assertFalse(TemKeyConstants.ERROR_PHONE_NUMBER.equals(travelService.validatePhoneNumber("US","123-555-1234 x1234",TemKeyConstants.ERROR_PHONE_NUMBER)));
88      }
89  
90      /**
91       *
92       * This method tests {@link TravelService#findTemProfileByPrincipalId(String)}
93       */
94      @Test
95      public void testFindTemProfileByPrincipalId() {
96          TemProfile profile = new TemProfile();
97          Integer newProfileId = sas.getNextAvailableSequenceNumber(TemConstants.TEM_PROFILE_SEQ_NAME).intValue();
98          profile.setProfileId(newProfileId);
99          profile.getTemProfileAddress().setProfileId(newProfileId);
100         profile.setCustomerNumber("555555555");
101         profile.setPrincipalId("66666666");
102         profile.setDateOfBirth(new Date(Date.parse("03/03/1975")));
103         profile.setCitizenship("United States");
104         profile.setDriversLicenseExpDate(new Date(Date.parse("03/03/2014")));
105         profile.setDriversLicenseNumber("B43212345");
106         profile.setUpdatedBy("jamey");
107         profile.setLastUpdate(new Date(Date.parse("03/03/2011")));
108         profile.setGender("M");
109         profile.setNonResidentAlien(false);
110         profile.setHomeDeptChartOfAccountsCode("UA");
111         profile.setHomeDeptOrgCode("VPIT");
112 
113         List<TravelerType> travelerTypes = (List<TravelerType>) businessObjectService.findMatching(TravelerType.class, new HashMap<String, Object>());
114         profile.setTravelerType(travelerTypes.get(0));
115         profile.setTravelerTypeCode(profile.getTravelerType().getCode());
116         profile.setProfileId(-1);
117         businessObjectService.save(profile);
118 
119         profile = travelService.findTemProfileByPrincipalId("-1");
120         assertNull(profile);
121 
122         profile = travelService.findTemProfileByPrincipalId("66666666");
123         assertNotNull(profile);
124     }
125 
126 }