1 /**
2 * Title: LdapQueryImplTest.java<br>
3 * Description: TODO<br>
4 * Copyright: HFT-SO<br>
5 * Erstellt am: 01.05.2007<br>
6 * Java Version: JDK 1.5<br>
7 *
8 * @author Philipp Gantert
9 * @version 1.0
10 */
11
12 package net.sourceforge.heracles.dao;
13
14 import java.text.DateFormat;
15 import java.util.ArrayList;
16 import java.util.Calendar;
17 import java.util.Date;
18 import java.util.GregorianCalendar;
19 import java.util.List;
20
21 import junit.framework.TestCase;
22 import junitx.util.PrivateAccessor;
23 import net.sourceforge.heracles.dao.impl.LdapQueryImpl;
24 import net.sourceforge.heracles.model.LdapUser;
25
26 public class LdapQueryImplTest extends TestCase {
27
28 /**
29 * This Test tests the private method convertDate. And the method changeEpoch. The goal is the
30 * show if the data convertion from long the a Date object successful.
31 *
32 * @throws Throwable
33 */
34 public void testConvertDate() throws Throwable {
35 LdapQuery ldapQuery = new LdapQueryImpl();
36 try {
37 List<Long> longs = new ArrayList();
38 longs.add(new Long("128218057058946001"));
39 longs.add(new Long("128218422932932903"));
40 longs.add(new Long("128218834832483248"));
41 longs.add(new Long("128218472929292282"));
42
43 for (Long l : longs) {
44 Date date = (Date) PrivateAccessor.invoke(ldapQuery, "convertDate", new Class[] { long.class }, new Object[] { l.longValue() });
45 assertEquals(displayWin32Date(new String(l.toString())), (DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format(date)));
46 }
47
48 } catch (IllegalStateException ex) {
49 ex.printStackTrace();
50 }
51 }
52
53 /**
54 * This Test tests the private method defineUserAccountControl. LdapUser Account should be
55 * disabled and locked. The password should be expired.
56 *
57 * @throws Throwable
58 */
59 public void testDefineUserAccountControl() throws Throwable {
60 LdapQuery ldapQuery = new LdapQueryImpl();
61 LdapUser ldapUser = new LdapUser();
62 int normalAccount= 512;
63 int accountDisabled=2;
64 int accountLocked=16;
65 int passwordExpired=8388608;
66 int userAccountControlFlag=normalAccount+accountDisabled+accountLocked+passwordExpired;
67
68 PrivateAccessor.invoke(ldapQuery, "defineUserAccountControl", new Class[] { LdapUser.class, int.class }, new Object[] { ldapUser, userAccountControlFlag });
69
70 assertEquals("Account is not disabled",true, ldapUser.isAccountDisable());
71 assertEquals("Account is not locked",true, ldapUser.isAccountLockout());
72 assertEquals("Password is expired", true,ldapUser.isPasswordExpired());
73 }
74
75 /**
76 * This is a helper method for the convertDate Test.
77 *
78 * @param win32FileTime
79 * @return
80 */
81 private String displayWin32Date(String win32FileTime) {
82 GregorianCalendar win32Epoch = new GregorianCalendar(1601, Calendar.JANUARY, 1);
83 Long lWin32Epoch = win32Epoch.getTimeInMillis();
84 Long lWin32FileTime = new Long(win32FileTime);
85 return (DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL).format((lWin32FileTime / 10000) + lWin32Epoch));
86 }
87
88 }