Friday, October 30, 2009

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package org.lcra.elc.util.emplookup.test;

import java.io.IOException;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import org.junit.*;

import org.junit.runner.JUnitCore;

import org.lcra.elc.util.emplookup.EmployeeLookupClient;
import org.lcra.elc.util.emplookup.exception.EmployeeLookupException;
import org.lcra.elc.util.emplookup.exception.NoSearchInfoException;
import org.lcra.elc.util.emplookup.exception.NoUserFoundException;
import org.lcra.esr.identity.types.UserType;

/**
* 20090825 [staylor@mythics.com] Updated test to use new package classes and migrate to JUnit 4.x.
*/
public class EmployeeLookupClientTest {

private Log log =
LogFactory.getFactory().getInstance(EmployeeLookupClientTest.class);

public static void main(String[] args) {
String[] args2 = { EmployeeLookupClientTest.class.getName() };
JUnitCore.main(args2);
}

//INPUT params for WS Client
private static final String USER_EMPLOYEE_ID = "9999999990";
private static final String USER_NAME = "patestuseriqbal";
private static final String USER_EMPLOYEE_ID_GARBAGE = "5494abcd";
private static final String USER_EMPLOYEE_ID_EMPTY = "";

//Expected variables to be used in JUnit assertion
private static final String USER_FIRST_NAME = "Iqbal";
private static final String USER_LAST_NAME = "Yusuf";
private static final String USER_EMAIL = "iqbal.yusuf@lcra.org";


public EmployeeLookupClientTest() {
}

@Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}

/**
* @see org.lcra.elc.util.emplookup.EmployeeLookupClient#getUserByEmployeeID(String)
*/
@Test
public void testGetUserByEmployeeID() {
log.debug("@Test testGetUserByEmployeeID");
try {
UserType user =
EmployeeLookupClient.getUserByEmployeeID(USER_EMPLOYEE_ID);

Assert.assertEquals("User First Name should be Iqbal: ",
USER_FIRST_NAME.toUpperCase(),
user.getFirstName().toUpperCase());
log.debug("User First Name: " + user.getFirstName());
Assert.assertEquals("User Last Name should be Yusuf: ",
USER_LAST_NAME.toUpperCase(),
user.getLastName().toUpperCase());
log.debug("User Last Name: " + user.getLastName());
Assert.assertEquals("User email should be iqbal.yusuf@lcra.org ",
USER_EMAIL.toUpperCase(),
user.getEMail().toUpperCase());
log.debug("User e-Mail: " + user.getEMail());
} catch (Exception e) {
log.debug(e.getMessage() + " \n");
log.debug(e);
Assert.fail("there is a exception thrown whiile calling getUserByEmployeeID method");
}
}

/**
*
* @see org.lcra.elc.util.emplookup.EmployeeLookupClient#getUserByUserName(String)
*
*/
@Test
public void testGetUserByUserName() {
log.debug("@Test testGetUserByUserName");
try {
UserType user = EmployeeLookupClient.getUserByUserName(USER_NAME);

Assert.assertEquals("User First Name should be Iqbal: ",
USER_FIRST_NAME.toUpperCase(),
user.getFirstName().toUpperCase());
log.debug("User First Name: " + user.getFirstName());
Assert.assertEquals("User Last Name should be Yusuf: ",
USER_LAST_NAME.toUpperCase(),
user.getLastName().toUpperCase());
log.debug("User Last Name: " + user.getLastName());
Assert.assertEquals("User email should be iqbal.yusuf@lcra.org ",
USER_EMAIL.toUpperCase(),
user.getEMail().toUpperCase());
log.debug("User e-Mail: " + user.getEMail());
} catch (Exception e) {
log.debug(e.getMessage() + " \n");
log.debug(e);
Assert.fail("there is a exception thrown whiile calling getUserByEmployeeID method");
}
}

@Test
public void testGetUserByEmployee_FailedCase() throws IOException {
log.debug("@Test testGetUserByEmployee_FailedCase");
try {
log.debug(USER_EMPLOYEE_ID_GARBAGE);
UserType user = EmployeeLookupClient.getUserByEmployeeID(USER_EMPLOYEE_ID_GARBAGE);
log.debug(user.getFirstName());
//Put Assert fail since we should not be able to come to this line. Above line should fail
Assert.fail("Input was a bad nonexistent EmployeeID. Test should not have passed!!!");
} catch (EmployeeLookupException e) {
log.debug("error code " + e.getError());
Assert.assertEquals(true, e.getError().equals("nouserfound"));
Assert.assertTrue("Input was a bad nonexistent EmployeeID, test did not pass",
true);
}
}

@Test
public void testGetUserByEmployee_EmptyInput() {
log.debug("@Test testGetUserByEmployee_EmptyInput");
try {
UserType user = EmployeeLookupClient.getUserByEmployeeID(USER_EMPLOYEE_ID_EMPTY);
log.debug(user.getFirstName());
//Put Assert fail since we should not be able to come to this line. Above line should fail
Assert.fail("Input was a nonexistent EmployeeID. Test should not have passed!!!");
} catch (EmployeeLookupException e) {
log.debug("error code " + e.getError());
Assert.assertEquals(true, e.getError().equals("nosearchinfo"));
Assert.assertTrue("Input was a nonexistent EmployeeID, Test did not pass",
true);
} catch (Exception e) {
log.debug(e.getMessage());
}
}

}

No comments:

Post a Comment