Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mytime
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Narendar Vakiti
mytime
Commits
963f6644
Commit
963f6644
authored
May 21, 2018
by
Rajeshekar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed the compilation errors in test cases and now the build is
successful
parent
ac5da2a9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
896 additions
and
748 deletions
+896
-748
ProjectControllerTest.java
...om/nisum/mytime/controllertest/ProjectControllerTest.java
+144
-119
ProjectTeamControllerTest.java
...isum/mytime/controllertest/ProjectTeamControllerTest.java
+399
-342
UserControllerTest.java
...a/com/nisum/mytime/controllertest/UserControllerTest.java
+353
-287
No files found.
src/test/java/com/nisum/mytime/controllertest/ProjectControllerTest.java
View file @
963f6644
...
...
@@ -33,123 +33,148 @@ import com.nisum.mytime.service.UserService;
public
class
ProjectControllerTest
{
@Mock
UserService
userService
;
@Mock
ProjectService
projectService
;
@Mock
AccountRepo
accountRepo
;
@InjectMocks
ProjectController
projectController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
projectController
).
build
();
}
@Test
public
void
testgetEmployeeRole
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
null
,
null
,
"user@nisum.com"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
12
),
new
Date
(
2017
-
12
-
12
));
when
(
userService
.
getEmployeesRole
(
"user@nisum.com"
)).
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/project/employee"
).
param
(
"emailId"
,
"user@nisum.com"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeesRole
(
"user@nisum.com"
);
}
@Test
public
void
testaddProject
()
throws
Exception
{
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16101"
);
list
.
add
(
"16102"
);
list
.
add
(
"16103"
);
Project
employeeRole1
=
new
Project
(
new
ObjectId
(
"9976ef15874c902c98b8a05d"
),
"102"
,
"OMS"
,
"16101"
,
"Srikanth"
,
"Macys"
,
"Billable"
,
list
);
String
jsonvalue
=(
new
ObjectMapper
()).
writeValueAsString
(
employeeRole1
).
toString
();
Account
account
=
new
Account
(
new
ObjectId
(
"5a4f03661dca211ea7f94c02"
),
"2"
,
"Macys"
,
0
,
"Y"
);
when
(
projectService
.
addProject
(
employeeRole1
)).
thenReturn
(
employeeRole1
);
when
(
accountRepo
.
findByAccountName
(
"Macys"
)).
thenReturn
(
account
);
mockMvc
.
perform
(
post
(
"/project/addProject"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonvalue
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testupdateEmployeeRole
()
throws
Exception
{
List
<
String
>
list1
=
new
ArrayList
<>();
list1
.
add
(
"16104"
);
list1
.
add
(
"16105"
);
list1
.
add
(
"16106"
);
Project
project
=
new
Project
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
),
"101"
,
"MOSAIC"
,
"16100"
,
"Rajeshekar"
,
"Gap"
,
"Billable"
,
list1
);
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
project
);
when
(
projectService
.
updateProject
(
any
())).
thenReturn
(
project
);
mockMvc
.
perform
(
post
(
"/project/updateProject"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
updateProject
(
any
());
}
@Test
public
void
testdeleteProject
()
throws
Exception
{
mockMvc
.
perform
(
delete
(
"/project/deleteProject"
).
param
(
"projectId"
,
"101"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
deleteProject
(
"101"
);
}
@Test
public
void
testgetProjects
()
throws
Exception
{
List
<
Project
>
projects
=
CreateProjectDetails
();
when
(
projectService
.
getProjects
()).
thenReturn
(
projects
);
mockMvc
.
perform
(
get
(
"/project/getProjects"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getProjects
();
}
@Test
public
void
testgetEmployeeRoleData
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
"16127"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
18
),
new
Date
(
2017
-
12
-
18
));
when
(
userService
.
getEmployeesRoleData
(
"16127"
)).
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/project/getEmployeeRoleData"
).
param
(
"empId"
,
"16127"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeesRoleData
(
"16127"
);
}
private
List
<
Project
>
CreateProjectDetails
()
{
List
<
Project
>
data
=
new
ArrayList
<>();
Project
data1
=
new
Project
();
data1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
data1
.
setProjectId
(
"101"
);
data1
.
setProjectName
(
"MOSAIC"
);
data1
.
setManagerId
(
"16110"
);
data1
.
setManagerName
(
"Rajeshekar"
);
data1
.
setStatus
(
"Billable"
);
data1
.
setAccount
(
"GAP"
);
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16101"
);
list
.
add
(
"16102"
);
list
.
add
(
"16103"
);
data1
.
setEmployeeIds
(
list
);
Project
data2
=
new
Project
();
data2
.
setId
(
new
ObjectId
(
"9976ef15874c902c98b8a05d"
));
data2
.
setProjectId
(
"102"
);
data2
.
setProjectName
(
"OMS"
);
data2
.
setManagerId
(
"16111"
);
data2
.
setManagerName
(
"Reshma"
);
data2
.
setStatus
(
"Non-Billable"
);
data2
.
setAccount
(
"MACYS"
);
List
<
String
>
lists
=
new
ArrayList
<>();
lists
.
add
(
"16104"
);
lists
.
add
(
"16105"
);
lists
.
add
(
"16106"
);
data2
.
setEmployeeIds
(
lists
);
data
.
add
(
data1
);
data
.
add
(
data2
);
return
data
;
}
@Mock
UserService
userService
;
@Mock
ProjectService
projectService
;
@Mock
AccountRepo
accountRepo
;
@InjectMocks
ProjectController
projectController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
projectController
).
build
();
}
@Test
public
void
testgetEmployeeRole
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
null
,
null
,
"user@nisum.com"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
12
),
new
Date
(
2017
-
12
-
12
));
when
(
userService
.
getEmployeesRole
(
"user@nisum.com"
))
.
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/project/employee"
).
param
(
"emailId"
,
"user@nisum.com"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeesRole
(
"user@nisum.com"
);
}
@Test
public
void
testaddProject
()
throws
Exception
{
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16101"
);
list
.
add
(
"16102"
);
list
.
add
(
"16103"
);
Project
employeeRole1
=
new
Project
(
new
ObjectId
(
"9976ef15874c902c98b8a05d"
),
"102"
,
"OMS"
,
"16101"
,
"Srikanth"
,
"Macys"
,
"Billable"
,
list
);
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
employeeRole1
).
toString
();
Account
account
=
new
Account
(
new
ObjectId
(
"5a4f03661dca211ea7f94c02"
),
"2"
,
"Macys"
,
0
,
"Y"
);
when
(
projectService
.
addProject
(
employeeRole1
))
.
thenReturn
(
employeeRole1
);
when
(
accountRepo
.
findByAccountName
(
"Macys"
)).
thenReturn
(
account
);
mockMvc
.
perform
(
post
(
"/project/addProject"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testupdateEmployeeRole
()
throws
Exception
{
List
<
String
>
list1
=
new
ArrayList
<>();
list1
.
add
(
"16104"
);
list1
.
add
(
"16105"
);
list1
.
add
(
"16106"
);
Project
project
=
new
Project
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
),
"101"
,
"MOSAIC"
,
"16100"
,
"Rajeshekar"
,
"Gap"
,
"Billable"
,
list1
);
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
project
);
when
(
projectService
.
updateProject
(
any
())).
thenReturn
(
project
);
mockMvc
.
perform
(
post
(
"/project/updateProject"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
updateProject
(
any
());
}
@Test
public
void
testdeleteProject
()
throws
Exception
{
mockMvc
.
perform
(
delete
(
"/project/deleteProject"
).
param
(
"projectId"
,
"101"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
deleteProject
(
"101"
);
}
@Test
public
void
testgetProjects
()
throws
Exception
{
List
<
Project
>
projects
=
CreateProjectDetails
();
when
(
projectService
.
getProjects
()).
thenReturn
(
projects
);
mockMvc
.
perform
(
get
(
"/project/getProjects"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getProjects
();
}
@Test
public
void
testgetEmployeeRoleData
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
"16127"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
18
),
new
Date
(
2017
-
12
-
18
));
when
(
userService
.
getEmployeesRoleData
(
"16127"
))
.
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/project/getEmployeeRoleData"
).
param
(
"empId"
,
"16127"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeesRoleData
(
"16127"
);
}
private
List
<
Project
>
CreateProjectDetails
()
{
List
<
Project
>
data
=
new
ArrayList
<>();
Project
data1
=
new
Project
();
data1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
data1
.
setProjectId
(
"101"
);
data1
.
setProjectName
(
"MOSAIC"
);
data1
.
setManagerId
(
"16110"
);
data1
.
setManagerName
(
"Rajeshekar"
);
data1
.
setStatus
(
"Billable"
);
data1
.
setAccount
(
"GAP"
);
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16101"
);
list
.
add
(
"16102"
);
list
.
add
(
"16103"
);
data1
.
setEmployeeIds
(
list
);
Project
data2
=
new
Project
();
data2
.
setId
(
new
ObjectId
(
"9976ef15874c902c98b8a05d"
));
data2
.
setProjectId
(
"102"
);
data2
.
setProjectName
(
"OMS"
);
data2
.
setManagerId
(
"16111"
);
data2
.
setManagerName
(
"Reshma"
);
data2
.
setStatus
(
"Non-Billable"
);
data2
.
setAccount
(
"MACYS"
);
List
<
String
>
lists
=
new
ArrayList
<>();
lists
.
add
(
"16104"
);
lists
.
add
(
"16105"
);
lists
.
add
(
"16106"
);
data2
.
setEmployeeIds
(
lists
);
data
.
add
(
data1
);
data
.
add
(
data2
);
return
data
;
}
}
src/test/java/com/nisum/mytime/controllertest/ProjectTeamControllerTest.java
View file @
963f6644
...
...
@@ -6,9 +6,11 @@ import static org.mockito.Mockito.when;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
delete
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
org.bson.types.ObjectId
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -19,6 +21,7 @@ import org.springframework.http.MediaType;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.result.MockMvcResultMatchers
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.nisum.mytime.controller.ProjectTeamController
;
import
com.nisum.mytime.model.EmployeeRoles
;
...
...
@@ -30,346 +33,400 @@ import com.nisum.mytime.service.UserService;
public
class
ProjectTeamControllerTest
{
@Mock
UserService
userService
;
@Mock
ProjectService
projectService
;
@InjectMocks
ProjectTeamController
projectTeamController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
projectTeamController
).
build
();
}
@Test
public
void
testgetEmployeeRole
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
"user@nisum.com"
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2107
-
12
-
23
));
when
(
userService
.
getEmployeesRole
(
"user@nisum.com"
)).
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/projectTeam/employee"
).
param
(
"emailId"
,
"user@nisum.com"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeesRole
(
"user@nisum.com"
);
}
@Test
public
void
testaddProject
()
throws
Exception
{
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16101"
);
list
.
add
(
"16102"
);
list
.
add
(
"16103"
);
Project
employeeRole1
=
new
Project
(
new
ObjectId
(
"9976ef15874c902c98b8a05d"
),
"102"
,
"OMS"
,
"16101"
,
"Srikanth"
,
"Gap"
,
"Billable"
,
list
);
String
jsonvalue
=
(
new
ObjectMapper
()).
writeValueAsString
(
employeeRole1
).
toString
();
when
(
projectService
.
addProject
(
employeeRole1
)).
thenReturn
(
employeeRole1
);
mockMvc
.
perform
(
post
(
"/projectTeam/addProject"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testupdateEmployeeRole
()
throws
Exception
{
EmployeeRoles
employeesRoles2
=
new
EmployeeRoles
(
"1976ef15874c902c98b8a05d"
,
"16111"
,
"Vinay Singh"
,
"vsingh@nisum.com"
,
"Manager"
,
null
,
"09:00-06:00"
,
"Java/J2EE"
,
"Testing"
,
"8755672341"
,
"8800543678"
,
"vsingh@gmail.com"
,
null
,
new
Date
(
2017
-
11
-
29
),
new
Date
(
2017
-
12
-
20
));
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeesRoles2
);
when
(
userService
.
updateEmployeeRole
(
any
())).
thenReturn
(
employeesRoles2
);
mockMvc
.
perform
(
post
(
"/projectTeam/updateEmployeeRole"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonString
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
updateEmployeeRole
(
any
());
}
@Test
public
void
testdeleteEmployee
()
throws
Exception
{
mockMvc
.
perform
(
delete
(
"/projectTeam/deleteEmployee"
).
param
(
"empId"
,
"16157"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
deleteEmployee
(
"16157"
);
}
@Test
public
void
testgetEmployeeRoleData
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
"16127"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2107
-
12
-
23
));
when
(
userService
.
getEmployeesRoleData
(
"16127"
)).
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/projectTeam/getEmployeeRoleData"
).
param
(
"empId"
,
"16127"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeesRoleData
(
"16127"
);
}
@Test
public
void
testgetManagers
()
throws
Exception
{
List
<
EmployeeRoles
>
employeesRoles
=
createEmployeeRoles
();
when
(
userService
.
getEmployeeRoles
()).
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getEmployeesToTeam"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testgetTeamDetails
()
throws
Exception
{
List
<
ProjectTeamMate
>
employeesRoles
=
createProjectTeamMate
();
when
(
projectService
.
getTeamDetails
(
"16127"
)).
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getTeamDetails"
).
param
(
"employeeId"
,
"16127"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getTeamDetails
(
"16127"
);
}
@Test
public
void
testaddEmployeeToTeam
()
throws
Exception
{
ProjectTeamMate
projectTeamMate
=
new
ProjectTeamMate
(
new
ObjectId
(
"1976ef15874c902c98b8a05d"
),
"16127"
,
"Monika Srivastava"
,
"msrivastava@nisum.com"
,
"Employee"
,
"09:00-06:00"
,
"101"
,
"MOSAIC"
,
"GAP"
,
"16081"
,
"Rajeshekar"
,
"01"
,
"Software Engineer"
,
"Non-Billable"
,
"8765588388"
,
new
Date
(),
new
Date
(),
true
);
String
jsonvalue
=
(
new
ObjectMapper
()).
writeValueAsString
(
projectTeamMate
).
toString
();
when
(
projectService
.
addProjectTeamMate
(
projectTeamMate
)).
thenReturn
(
projectTeamMate
);
mockMvc
.
perform
(
post
(
"/projectTeam/addEmployeeToTeam"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testupdateTeammate
()
throws
Exception
{
ProjectTeamMate
updatedTeammate
=
new
ProjectTeamMate
(
new
ObjectId
(
"1976ef15874c902c98b8a05d"
),
"16127"
,
"Monika Srivastava"
,
"msrivastava@nisum.com"
,
"Employee"
,
"09:00-06:00"
,
"101"
,
"MOSAIC"
,
"GAP"
,
"16081"
,
"Rajeshekar"
,
"01"
,
"Software Engineer"
,
"Non-Billable"
,
"8765588388"
,
new
Date
(),
new
Date
(),
true
);
String
jsonvalue
=
(
new
ObjectMapper
()).
writeValueAsString
(
updatedTeammate
).
toString
();
when
(
projectService
.
updateTeammate
(
updatedTeammate
)).
thenReturn
(
updatedTeammate
);
mockMvc
.
perform
(
post
(
"/projectTeam/updateTeammate"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testdeleteTeammate
()
throws
Exception
{
ProjectTeamMate
deleteTeamMate
=
new
ProjectTeamMate
(
new
ObjectId
(
"1976ef15874c902c98b8a05d"
),
"16127"
,
"Monika Srivastava"
,
"msrivastava@nisum.com"
,
"Employee"
,
"09:00-06:00"
,
"101"
,
"MOSAIC"
,
"GAP"
,
"16081"
,
"Rajeshekar"
,
"01"
,
"Software Engineer"
,
"Non-Billable"
,
"8765588388"
,
new
Date
(),
new
Date
(),
true
);
String
jsonvalue
=
(
new
ObjectMapper
()).
writeValueAsString
(
deleteTeamMate
).
toString
();
mockMvc
.
perform
(
post
(
"/projectTeam/deleteTeammate"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
deleteTeammate
(
"16127"
,
"101"
,
new
ObjectId
(
"1976ef15874c902c98b8a05d"
));
}
@Test
public
void
testgetProjects
()
throws
Exception
{
List
<
Project
>
projects
=
CreateProjectDetails
();
when
(
projectService
.
getProjects
(
"16127"
)).
thenReturn
(
projects
);
mockMvc
.
perform
(
get
(
"/projectTeam/getProjects"
).
param
(
"employeeId"
,
"16127"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getProjects
(
"16127"
);
}
@Test
public
void
testgetMyTeamDetails
()
throws
Exception
{
List
<
ProjectTeamMate
>
employeesRoles
=
createProjectTeamMate
();
when
(
projectService
.
getMyTeamDetails
(
"16127"
)).
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getMyTeamDetails"
).
param
(
"employeeId"
,
"16127"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getMyTeamDetails
(
"16127"
);
}
@Test
public
void
testgetUnAssignedEmployees
()
throws
Exception
{
List
<
EmployeeRoles
>
employeesRoles
=
createEmployeeRoles
();
when
(
projectService
.
getUnAssignedEmployees
()).
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getUnAssignedEmployees"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getUnAssignedEmployees
();
}
@Test
public
void
testgetShiftDetails
()
throws
Exception
{
List
<
ProjectTeamMate
>
employeesRoles
=
createProjectTeamMate
();
when
(
projectService
.
getShiftDetails
(
"09:00-06:00"
)).
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getShiftDetails"
).
param
(
"shift"
,
"09:00-06:00"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getShiftDetails
(
"09:00-06:00"
);
}
@Test
public
void
testgetProjectAllocations
()
throws
Exception
{
List
<
ProjectTeamMate
>
employeesRoles
=
createProjectTeamMate
();
when
(
projectService
.
getAllProjectDetails
()).
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getProjectAllocations"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getAllProjectDetails
();
}
@Test
public
void
testgetProjectDetails
()
throws
Exception
{
List
<
ProjectTeamMate
>
employeesRoles
=
createProjectTeamMate
();
when
(
projectService
.
getProjectDetails
(
"101"
)).
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getProjectDetails"
).
param
(
"projectId"
,
"101"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getProjectDetails
(
"101"
);
}
@Test
public
void
testgetMyProjectAllocations
()
throws
Exception
{
List
<
ProjectTeamMate
>
projectAllocations
=
createProjectTeamMate
();
System
.
out
.
println
(
projectAllocations
);
when
(
projectService
.
getMyProjectAllocations
(
"16127"
)).
thenReturn
(
projectAllocations
);
mockMvc
.
perform
(
get
(
"/projectTeam/getMyProjectAllocations"
).
param
(
"employeeId"
,
"16127"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getMyProjectAllocations
(
"16127"
);
}
@Test
public
void
testgetEmployeeBillingDetails
()
throws
Exception
{
List
<
TeamMateBilling
>
billings
=
CreateTeamMateBilling
();
System
.
out
.
println
(
billings
);
when
(
projectService
.
getEmployeeBillingDetails
(
"16127"
,
"101"
)).
thenReturn
(
billings
);
mockMvc
.
perform
(
get
(
"/projectTeam/getEmployeeBillingDetails"
).
param
(
"employeeId"
,
"16127"
).
param
(
"projectId"
,
"101"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getEmployeeBillingDetails
(
"16127"
,
"101"
);
}
private
List
<
TeamMateBilling
>
CreateTeamMateBilling
()
{
List
<
TeamMateBilling
>
data
=
new
ArrayList
<>();
TeamMateBilling
team1
=
new
TeamMateBilling
();
team1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
team1
.
setEmployeeId
(
"16127"
);
team1
.
setEmployeeName
(
"Employee1"
);
team1
.
setProjectId
(
"101"
);
team1
.
setProjectName
(
"MOSAIC"
);
team1
.
setBillingStartDate
(
new
Date
(
2017
-
01
-
10
));
team1
.
setBillingEndDate
(
new
Date
(
2017
-
02
-
10
));
team1
.
setActive
(
true
);
data
.
add
(
team1
);
TeamMateBilling
team2
=
new
TeamMateBilling
();
team2
.
setId
(
new
ObjectId
(
"1976ef15874c902c98b8a05d"
));
team2
.
setEmployeeId
(
"16128"
);
team2
.
setEmployeeName
(
"Employee2"
);
team2
.
setProjectId
(
"102"
);
team2
.
setProjectName
(
"OMS"
);
team2
.
setBillingStartDate
(
new
Date
(
2017
-
01
-
15
));
team2
.
setBillingEndDate
(
new
Date
(
2017
-
02
-
15
));
team2
.
setActive
(
false
);
data
.
add
(
team2
);
return
data
;
}
private
List
<
Project
>
CreateProjectDetails
()
{
List
<
Project
>
data
=
new
ArrayList
<>();
Project
data1
=
new
Project
();
data1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
data1
.
setProjectId
(
"101"
);
data1
.
setProjectName
(
"MOSAIC"
);
data1
.
setManagerId
(
"16110"
);
data1
.
setManagerName
(
"Rajeshekar"
);
data1
.
setStatus
(
"Billable"
);
data1
.
setAccount
(
"Gap"
);
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16101"
);
list
.
add
(
"16102"
);
list
.
add
(
"16103"
);
data1
.
setEmployeeIds
(
list
);
Project
data2
=
new
Project
();
data2
.
setId
(
new
ObjectId
(
"9976ef15874c902c98b8a05d"
));
data2
.
setProjectId
(
"102"
);
data2
.
setProjectName
(
"OMS"
);
data2
.
setManagerId
(
"16111"
);
data2
.
setManagerName
(
"Reshma"
);
data2
.
setStatus
(
"Billable"
);
data2
.
setAccount
(
"Macys"
);
List
<
String
>
lists
=
new
ArrayList
<>();
lists
.
add
(
"16104"
);
lists
.
add
(
"16105"
);
lists
.
add
(
"16106"
);
data2
.
setEmployeeIds
(
lists
);
data
.
add
(
data1
);
data
.
add
(
data2
);
return
data
;
}
private
List
<
ProjectTeamMate
>
createProjectTeamMate
()
{
List
<
ProjectTeamMate
>
data
=
new
ArrayList
<>();
ProjectTeamMate
record1
=
new
ProjectTeamMate
();
record1
.
setId
(
new
ObjectId
(
"3976ef15874c902c98b8a05d"
));
record1
.
setEmployeeId
(
"16127"
);
record1
.
setEmployeeName
(
"Monika Srivastava"
);
record1
.
setEmailId
(
"msrivastava@nisum.com"
);
record1
.
setRole
(
"Employee"
);
record1
.
setShift
(
"09:00-06:00"
);
record1
.
setProjectId
(
"101"
);
record1
.
setProjectName
(
"Mosaic"
);
record1
.
setAccount
(
"Gap"
);
record1
.
setManagerId
(
"16081"
);
record1
.
setManagerName
(
"Rajeshekar"
);
record1
.
setExperience
(
"01 Year"
);
record1
.
setDesignation
(
"Software Engineer"
);
record1
.
setBillableStatus
(
"Non-Billable"
);
record1
.
setMobileNumber
(
"8765588388"
);
ProjectTeamMate
record2
=
new
ProjectTeamMate
();
record2
.
setId
(
new
ObjectId
(
"2976ef15874c902c98b8a05d"
));
record2
.
setEmployeeId
(
"16111"
);
record2
.
setEmployeeName
(
"Vinay Singh"
);
record2
.
setEmailId
(
"vsingh@nisum.com"
);
record2
.
setRole
(
"Employee"
);
record2
.
setShift
(
"09:00-06:00"
);
record2
.
setProjectId
(
"101"
);
record2
.
setProjectName
(
"Mosaic"
);
record2
.
setAccount
(
"Gap"
);
record2
.
setManagerId
(
"16081"
);
record2
.
setManagerName
(
"Rajeshekar"
);
record2
.
setExperience
(
"07 Year"
);
record2
.
setDesignation
(
"Senoir Software Engineer"
);
record2
.
setBillableStatus
(
"Billable"
);
record2
.
setMobileNumber
(
"8765588399"
);
data
.
add
(
record1
);
data
.
add
(
record2
);
return
data
;
}
private
List
<
EmployeeRoles
>
createEmployeeRoles
()
{
List
<
EmployeeRoles
>
data
=
new
ArrayList
<>();
EmployeeRoles
record1
=
new
EmployeeRoles
();
record1
.
setId
(
"5976ef15874c902c98b8a05d"
);
record1
.
setEmployeeId
(
"16127"
);
record1
.
setEmployeeName
(
"Monika Srivastava"
);
record1
.
setEmailId
(
"msrivastava@nisum.com"
);
record1
.
setRole
(
"Employee"
);
record1
.
setShift
(
"09:00-06:00"
);
record1
.
setBaseTechnology
(
"Spring"
);
record1
.
setTechnologyKnown
(
"Java"
);
record1
.
setMobileNumber
(
"9900786755"
);
record1
.
setAlternateMobileNumber
(
"7689009876"
);
record1
.
setPersonalEmailId
(
"msrivastava@gmail.com"
);
record1
.
setCreatedOn
(
new
Date
(
2017
-
11
-
18
));
record1
.
setLastModifiedOn
(
new
Date
(
2017
-
12
-
13
));
EmployeeRoles
record2
=
new
EmployeeRoles
();
record2
.
setId
(
"8976ef15874c902c98b8a05d"
);
record2
.
setEmployeeId
(
"16081"
);
record2
.
setEmployeeName
(
"Rajeshekar"
);
record2
.
setEmailId
(
"manager@nisum.com"
);
record2
.
setRole
(
"Manager"
);
record2
.
setShift
(
"03:00-12:00"
);
record2
.
setBaseTechnology
(
"Hibernate"
);
record2
.
setTechnologyKnown
(
"EJB"
);
record2
.
setMobileNumber
(
"9109897867"
);
record2
.
setAlternateMobileNumber
(
"9129098767"
);
record2
.
setPersonalEmailId
(
"manager@gmail.com"
);
record2
.
setCreatedOn
(
new
Date
(
2017
-
11
-
18
));
record2
.
setLastModifiedOn
(
new
Date
(
2017
-
12
-
21
));
data
.
add
(
record1
);
data
.
add
(
record2
);
return
data
;
}
@Mock
UserService
userService
;
@Mock
ProjectService
projectService
;
@InjectMocks
ProjectTeamController
projectTeamController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
projectTeamController
)
.
build
();
}
@Test
public
void
testgetEmployeeRole
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
"user@nisum.com"
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2107
-
12
-
23
));
when
(
userService
.
getEmployeesRole
(
"user@nisum.com"
))
.
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/projectTeam/employee"
).
param
(
"emailId"
,
"user@nisum.com"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeesRole
(
"user@nisum.com"
);
}
@Test
public
void
testaddProject
()
throws
Exception
{
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16101"
);
list
.
add
(
"16102"
);
list
.
add
(
"16103"
);
Project
employeeRole1
=
new
Project
(
new
ObjectId
(
"9976ef15874c902c98b8a05d"
),
"102"
,
"OMS"
,
"16101"
,
"Srikanth"
,
"Gap"
,
"Billable"
,
list
);
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
employeeRole1
).
toString
();
when
(
projectService
.
addProject
(
employeeRole1
))
.
thenReturn
(
employeeRole1
);
mockMvc
.
perform
(
post
(
"/projectTeam/addProject"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testupdateEmployeeRole
()
throws
Exception
{
EmployeeRoles
employeesRoles2
=
new
EmployeeRoles
(
"1976ef15874c902c98b8a05d"
,
"16111"
,
"Vinay Singh"
,
"vsingh@nisum.com"
,
"Manager"
,
null
,
"09:00-06:00"
,
"Java/J2EE"
,
"Testing"
,
"8755672341"
,
"8800543678"
,
"vsingh@gmail.com"
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
29
),
new
Date
(
2017
-
12
-
20
));
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeesRoles2
);
when
(
userService
.
updateEmployeeRole
(
any
())).
thenReturn
(
employeesRoles2
);
mockMvc
.
perform
(
post
(
"/projectTeam/updateEmployeeRole"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
updateEmployeeRole
(
any
());
}
@Test
public
void
testdeleteEmployee
()
throws
Exception
{
mockMvc
.
perform
(
delete
(
"/projectTeam/deleteEmployee"
).
param
(
"empId"
,
"16157"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
deleteEmployee
(
"16157"
);
}
@Test
public
void
testgetEmployeeRoleData
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
"16127"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2107
-
12
-
23
));
when
(
userService
.
getEmployeesRoleData
(
"16127"
))
.
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/projectTeam/getEmployeeRoleData"
).
param
(
"empId"
,
"16127"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeesRoleData
(
"16127"
);
}
@Test
public
void
testgetManagers
()
throws
Exception
{
List
<
EmployeeRoles
>
employeesRoles
=
createEmployeeRoles
();
when
(
userService
.
getEmployeeRoles
()).
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getEmployeesToTeam"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testgetTeamDetails
()
throws
Exception
{
List
<
ProjectTeamMate
>
employeesRoles
=
createProjectTeamMate
();
when
(
projectService
.
getTeamDetails
(
"16127"
)).
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getTeamDetails"
).
param
(
"employeeId"
,
"16127"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getTeamDetails
(
"16127"
);
}
@Test
public
void
testaddEmployeeToTeam
()
throws
Exception
{
ProjectTeamMate
projectTeamMate
=
new
ProjectTeamMate
(
new
ObjectId
(
"1976ef15874c902c98b8a05d"
),
"16127"
,
"Monika Srivastava"
,
"msrivastava@nisum.com"
,
"Employee"
,
"09:00-06:00"
,
"101"
,
"MOSAIC"
,
"GAP"
,
"16081"
,
"Rajeshekar"
,
"01"
,
"Software Engineer"
,
"Non-Billable"
,
"8765588388"
,
new
Date
(),
new
Date
(),
true
);
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
projectTeamMate
).
toString
();
when
(
projectService
.
addProjectTeamMate
(
projectTeamMate
))
.
thenReturn
(
projectTeamMate
);
mockMvc
.
perform
(
post
(
"/projectTeam/addEmployeeToTeam"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testupdateTeammate
()
throws
Exception
{
ProjectTeamMate
updatedTeammate
=
new
ProjectTeamMate
(
new
ObjectId
(
"1976ef15874c902c98b8a05d"
),
"16127"
,
"Monika Srivastava"
,
"msrivastava@nisum.com"
,
"Employee"
,
"09:00-06:00"
,
"101"
,
"MOSAIC"
,
"GAP"
,
"16081"
,
"Rajeshekar"
,
"01"
,
"Software Engineer"
,
"Non-Billable"
,
"8765588388"
,
new
Date
(),
new
Date
(),
true
);
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
updatedTeammate
).
toString
();
when
(
projectService
.
updateTeammate
(
updatedTeammate
))
.
thenReturn
(
updatedTeammate
);
mockMvc
.
perform
(
post
(
"/projectTeam/updateTeammate"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testdeleteTeammate
()
throws
Exception
{
ProjectTeamMate
deleteTeamMate
=
new
ProjectTeamMate
(
new
ObjectId
(
"1976ef15874c902c98b8a05d"
),
"16127"
,
"Monika Srivastava"
,
"msrivastava@nisum.com"
,
"Employee"
,
"09:00-06:00"
,
"101"
,
"MOSAIC"
,
"GAP"
,
"16081"
,
"Rajeshekar"
,
"01"
,
"Software Engineer"
,
"Non-Billable"
,
"8765588388"
,
new
Date
(),
new
Date
(),
true
);
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
deleteTeamMate
).
toString
();
mockMvc
.
perform
(
post
(
"/projectTeam/deleteTeammate"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
deleteTeammate
(
"16127"
,
"101"
,
new
ObjectId
(
"1976ef15874c902c98b8a05d"
));
}
@Test
public
void
testgetProjects
()
throws
Exception
{
List
<
Project
>
projects
=
CreateProjectDetails
();
when
(
projectService
.
getProjects
(
"16127"
)).
thenReturn
(
projects
);
mockMvc
.
perform
(
get
(
"/projectTeam/getProjects"
).
param
(
"employeeId"
,
"16127"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getProjects
(
"16127"
);
}
@Test
public
void
testgetMyTeamDetails
()
throws
Exception
{
List
<
ProjectTeamMate
>
employeesRoles
=
createProjectTeamMate
();
when
(
projectService
.
getMyTeamDetails
(
"16127"
))
.
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getMyTeamDetails"
).
param
(
"employeeId"
,
"16127"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getMyTeamDetails
(
"16127"
);
}
@Test
public
void
testgetUnAssignedEmployees
()
throws
Exception
{
List
<
EmployeeRoles
>
employeesRoles
=
createEmployeeRoles
();
when
(
projectService
.
getUnAssignedEmployees
())
.
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getUnAssignedEmployees"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getUnAssignedEmployees
();
}
@Test
public
void
testgetShiftDetails
()
throws
Exception
{
List
<
ProjectTeamMate
>
employeesRoles
=
createProjectTeamMate
();
when
(
projectService
.
getShiftDetails
(
"09:00-06:00"
))
.
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getShiftDetails"
).
param
(
"shift"
,
"09:00-06:00"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getShiftDetails
(
"09:00-06:00"
);
}
@Test
public
void
testgetProjectAllocations
()
throws
Exception
{
List
<
ProjectTeamMate
>
employeesRoles
=
createProjectTeamMate
();
when
(
projectService
.
getAllProjectDetails
()).
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getProjectAllocations"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getAllProjectDetails
();
}
@Test
public
void
testgetProjectDetails
()
throws
Exception
{
List
<
ProjectTeamMate
>
employeesRoles
=
createProjectTeamMate
();
when
(
projectService
.
getProjectDetails
(
"101"
))
.
thenReturn
(
employeesRoles
);
mockMvc
.
perform
(
get
(
"/projectTeam/getProjectDetails"
).
param
(
"projectId"
,
"101"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getProjectDetails
(
"101"
);
}
@Test
public
void
testgetMyProjectAllocations
()
throws
Exception
{
List
<
ProjectTeamMate
>
projectAllocations
=
createProjectTeamMate
();
System
.
out
.
println
(
projectAllocations
);
when
(
projectService
.
getMyProjectAllocations
(
"16127"
))
.
thenReturn
(
projectAllocations
);
mockMvc
.
perform
(
get
(
"/projectTeam/getMyProjectAllocations"
)
.
param
(
"employeeId"
,
"16127"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getMyProjectAllocations
(
"16127"
);
}
@Test
public
void
testgetEmployeeBillingDetails
()
throws
Exception
{
List
<
TeamMateBilling
>
billings
=
CreateTeamMateBilling
();
System
.
out
.
println
(
billings
);
when
(
projectService
.
getEmployeeBillingDetails
(
"16127"
,
"101"
))
.
thenReturn
(
billings
);
mockMvc
.
perform
(
get
(
"/projectTeam/getEmployeeBillingDetails"
)
.
param
(
"employeeId"
,
"16127"
).
param
(
"projectId"
,
"101"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
projectService
).
getEmployeeBillingDetails
(
"16127"
,
"101"
);
}
private
List
<
TeamMateBilling
>
CreateTeamMateBilling
()
{
List
<
TeamMateBilling
>
data
=
new
ArrayList
<>();
TeamMateBilling
team1
=
new
TeamMateBilling
();
team1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
team1
.
setEmployeeId
(
"16127"
);
team1
.
setEmployeeName
(
"Employee1"
);
team1
.
setProjectId
(
"101"
);
team1
.
setProjectName
(
"MOSAIC"
);
team1
.
setBillingStartDate
(
new
Date
(
2017
-
01
-
10
));
team1
.
setBillingEndDate
(
new
Date
(
2017
-
02
-
10
));
team1
.
setActive
(
true
);
data
.
add
(
team1
);
TeamMateBilling
team2
=
new
TeamMateBilling
();
team2
.
setId
(
new
ObjectId
(
"1976ef15874c902c98b8a05d"
));
team2
.
setEmployeeId
(
"16128"
);
team2
.
setEmployeeName
(
"Employee2"
);
team2
.
setProjectId
(
"102"
);
team2
.
setProjectName
(
"OMS"
);
team2
.
setBillingStartDate
(
new
Date
(
2017
-
01
-
15
));
team2
.
setBillingEndDate
(
new
Date
(
2017
-
02
-
15
));
team2
.
setActive
(
false
);
data
.
add
(
team2
);
return
data
;
}
private
List
<
Project
>
CreateProjectDetails
()
{
List
<
Project
>
data
=
new
ArrayList
<>();
Project
data1
=
new
Project
();
data1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
data1
.
setProjectId
(
"101"
);
data1
.
setProjectName
(
"MOSAIC"
);
data1
.
setManagerId
(
"16110"
);
data1
.
setManagerName
(
"Rajeshekar"
);
data1
.
setStatus
(
"Billable"
);
data1
.
setAccount
(
"Gap"
);
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16101"
);
list
.
add
(
"16102"
);
list
.
add
(
"16103"
);
data1
.
setEmployeeIds
(
list
);
Project
data2
=
new
Project
();
data2
.
setId
(
new
ObjectId
(
"9976ef15874c902c98b8a05d"
));
data2
.
setProjectId
(
"102"
);
data2
.
setProjectName
(
"OMS"
);
data2
.
setManagerId
(
"16111"
);
data2
.
setManagerName
(
"Reshma"
);
data2
.
setStatus
(
"Billable"
);
data2
.
setAccount
(
"Macys"
);
List
<
String
>
lists
=
new
ArrayList
<>();
lists
.
add
(
"16104"
);
lists
.
add
(
"16105"
);
lists
.
add
(
"16106"
);
data2
.
setEmployeeIds
(
lists
);
data
.
add
(
data1
);
data
.
add
(
data2
);
return
data
;
}
private
List
<
ProjectTeamMate
>
createProjectTeamMate
()
{
List
<
ProjectTeamMate
>
data
=
new
ArrayList
<>();
ProjectTeamMate
record1
=
new
ProjectTeamMate
();
record1
.
setId
(
new
ObjectId
(
"3976ef15874c902c98b8a05d"
));
record1
.
setEmployeeId
(
"16127"
);
record1
.
setEmployeeName
(
"Monika Srivastava"
);
record1
.
setEmailId
(
"msrivastava@nisum.com"
);
record1
.
setRole
(
"Employee"
);
record1
.
setShift
(
"09:00-06:00"
);
record1
.
setProjectId
(
"101"
);
record1
.
setProjectName
(
"Mosaic"
);
record1
.
setAccount
(
"Gap"
);
record1
.
setManagerId
(
"16081"
);
record1
.
setManagerName
(
"Rajeshekar"
);
record1
.
setExperience
(
"01 Year"
);
record1
.
setDesignation
(
"Software Engineer"
);
record1
.
setBillableStatus
(
"Non-Billable"
);
record1
.
setMobileNumber
(
"8765588388"
);
ProjectTeamMate
record2
=
new
ProjectTeamMate
();
record2
.
setId
(
new
ObjectId
(
"2976ef15874c902c98b8a05d"
));
record2
.
setEmployeeId
(
"16111"
);
record2
.
setEmployeeName
(
"Vinay Singh"
);
record2
.
setEmailId
(
"vsingh@nisum.com"
);
record2
.
setRole
(
"Employee"
);
record2
.
setShift
(
"09:00-06:00"
);
record2
.
setProjectId
(
"101"
);
record2
.
setProjectName
(
"Mosaic"
);
record2
.
setAccount
(
"Gap"
);
record2
.
setManagerId
(
"16081"
);
record2
.
setManagerName
(
"Rajeshekar"
);
record2
.
setExperience
(
"07 Year"
);
record2
.
setDesignation
(
"Senoir Software Engineer"
);
record2
.
setBillableStatus
(
"Billable"
);
record2
.
setMobileNumber
(
"8765588399"
);
data
.
add
(
record1
);
data
.
add
(
record2
);
return
data
;
}
private
List
<
EmployeeRoles
>
createEmployeeRoles
()
{
List
<
EmployeeRoles
>
data
=
new
ArrayList
<>();
EmployeeRoles
record1
=
new
EmployeeRoles
();
record1
.
setId
(
"5976ef15874c902c98b8a05d"
);
record1
.
setEmployeeId
(
"16127"
);
record1
.
setEmployeeName
(
"Monika Srivastava"
);
record1
.
setEmailId
(
"msrivastava@nisum.com"
);
record1
.
setRole
(
"Employee"
);
record1
.
setShift
(
"09:00-06:00"
);
record1
.
setBaseTechnology
(
"Spring"
);
record1
.
setTechnologyKnown
(
"Java"
);
record1
.
setMobileNumber
(
"9900786755"
);
record1
.
setAlternateMobileNumber
(
"7689009876"
);
record1
.
setPersonalEmailId
(
"msrivastava@gmail.com"
);
record1
.
setCreatedOn
(
new
Date
(
2017
-
11
-
18
));
record1
.
setLastModifiedOn
(
new
Date
(
2017
-
12
-
13
));
EmployeeRoles
record2
=
new
EmployeeRoles
();
record2
.
setId
(
"8976ef15874c902c98b8a05d"
);
record2
.
setEmployeeId
(
"16081"
);
record2
.
setEmployeeName
(
"Rajeshekar"
);
record2
.
setEmailId
(
"manager@nisum.com"
);
record2
.
setRole
(
"Manager"
);
record2
.
setShift
(
"03:00-12:00"
);
record2
.
setBaseTechnology
(
"Hibernate"
);
record2
.
setTechnologyKnown
(
"EJB"
);
record2
.
setMobileNumber
(
"9109897867"
);
record2
.
setAlternateMobileNumber
(
"9129098767"
);
record2
.
setPersonalEmailId
(
"manager@gmail.com"
);
record2
.
setCreatedOn
(
new
Date
(
2017
-
11
-
18
));
record2
.
setLastModifiedOn
(
new
Date
(
2017
-
12
-
21
));
data
.
add
(
record1
);
data
.
add
(
record2
);
return
data
;
}
}
src/test/java/com/nisum/mytime/controllertest/UserControllerTest.java
View file @
963f6644
...
...
@@ -9,9 +9,11 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultHandlers
.
print
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
jsonPath
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
org.bson.types.ObjectId
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -22,6 +24,7 @@ import org.springframework.http.MediaType;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.result.MockMvcResultMatchers
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.nisum.mytime.controller.UserController
;
import
com.nisum.mytime.model.Account
;
...
...
@@ -33,295 +36,358 @@ import com.nisum.mytime.service.UserService;
public
class
UserControllerTest
{
@Mock
UserService
userService
;
@InjectMocks
UserController
userController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
userController
).
build
();
}
@Test
public
void
testgetEmployeeRole
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
null
,
null
,
"user@nisum.com"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2017
-
12
-
23
));
when
(
userService
.
getEmployeesRole
(
"user@nisum.com"
)).
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/user/employee"
).
param
(
"emailId"
,
"user@nisum.com"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeesRole
(
"user@nisum.com"
);
}
@Test
public
void
testassigingEmployeeRole
()
throws
Exception
{
EmployeeRoles
employeeRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05c"
,
"16135"
,
"Monika"
,
"user1@nisum.com"
,
"HR"
,
"Human Resource Lead"
,
"06:00-09:00"
,
"Java/J2EE"
,
"Spring"
,
"8767893452"
,
"5687234567"
,
"user1@gmail.com"
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2017
-
12
-
23
));
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeeRole
);
when
(
userService
.
assigingEmployeeRole
(
anyObject
())).
thenReturn
(
employeeRole
);
mockMvc
.
perform
(
post
(
"/user/assignEmployeeRole"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
assigingEmployeeRole
(
anyObject
());
}
@Test
public
void
testupdateEmployeeRole
()
throws
Exception
{
EmployeeRoles
employeeRole2
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
"67890"
,
"Sonika"
,
"user2@nisum.com"
,
"Manager"
,
"Senior Software Engineer"
,
"09:00am-06:00am"
,
"php"
,
"Hibernate"
,
"9878678956"
,
"9989782210"
,
"user2@gmail.com"
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2017
-
12
-
23
));
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeeRole2
);
when
(
userService
.
updateEmployeeRole
(
anyObject
())).
thenReturn
(
employeeRole2
);
mockMvc
.
perform
(
post
(
"/user/updateEmployeeRole"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
updateEmployeeRole
(
anyObject
());
}
@Test
public
void
testdeleteEmployee
()
throws
Exception
{
mockMvc
.
perform
(
delete
(
"/user/deleteEmployee"
).
param
(
"empId"
,
"16127"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
deleteEmployee
(
"16127"
);
}
@Test
public
void
testgetUserRoles
()
throws
Exception
{
List
<
EmployeeRoles
>
employeesRole3
=
CreateUserRoles
();
when
(
userService
.
getEmployeeRoles
()).
thenReturn
(
employeesRole3
);
mockMvc
.
perform
(
get
(
"/user/getUserRoles"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeeRoles
();
}
@Test
public
void
testgetEmployeeRoleData
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
"16127"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
13
),
new
Date
(
2017
-
12
-
20
));
when
(
userService
.
getEmployeesRoleData
(
"16127"
)).
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/user/getEmployeeRoleData"
).
param
(
"empId"
,
"16127"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
()).
andExpect
(
jsonPath
(
"$.employeeId"
,
is
(
"16127"
)))
.
andDo
(
print
());
verify
(
userService
).
getEmployeesRoleData
(
"16127"
);
}
@Test
public
void
testgetEmployeeRoleDataForEmailIdSearch
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
"16209"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
13
),
new
Date
(
2017
-
12
-
20
));
when
(
userService
.
getEmployeeRoleDataForSearchCriteria
(
"dummy@nisum.com"
,
"emailId"
)).
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/user/getEmployeeRoleDataForSearchCriteria"
).
param
(
"searchId"
,
"dummy@nisum.com"
)
.
param
(
"searchAttribute"
,
"emailId"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
()).
andExpect
(
jsonPath
(
"$.employeeId"
,
is
(
"16209"
)))
.
andDo
(
print
());
verify
(
userService
).
getEmployeeRoleDataForSearchCriteria
(
"dummy@nisum.com"
,
"emailId"
);
}
@Test
public
void
testgetEmployeeRoleDataForEmployeeNameSearch
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
"16209"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
13
),
new
Date
(
2017
-
12
-
20
));
when
(
userService
.
getEmployeeRoleDataForSearchCriteria
(
"Mahesh Kumar Gutam"
,
"employeeName"
)).
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/user/getEmployeeRoleDataForSearchCriteria"
).
param
(
"searchId"
,
"Mahesh Kumar Gutam"
)
.
param
(
"searchAttribute"
,
"employeeName"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
()).
andExpect
(
jsonPath
(
"$.employeeId"
,
is
(
"16209"
)))
.
andDo
(
print
());
verify
(
userService
).
getEmployeeRoleDataForSearchCriteria
(
"Mahesh Kumar Gutam"
,
"employeeName"
);
}
@Test
public
void
testGetEmployeeDetailsForAutocomplete
()
throws
Exception
{
List
<
String
>
details
=
new
ArrayList
<>();
details
.
add
(
"16294"
);
details
.
add
(
"Ashwin Kumar"
);
details
.
add
(
"kashwin@nisum.com"
);
details
.
add
(
"16209"
);
details
.
add
(
"Mahesh Kumar Gutam"
);
details
.
add
(
"mgutam@nisum.com"
);
details
.
add
(
"16143"
);
details
.
add
(
"Ajay"
);
details
.
add
(
"ajayS@nisum.com"
);
details
.
add
(
"16207"
);
details
.
add
(
"Sumith Kumar Lambu"
);
details
.
add
(
"slambu@nisum.com"
);
details
.
add
(
"16111"
);
details
.
add
(
"Mahesh Mudrakolu"
);
details
.
add
(
"mmahesh@nisum.com"
);
when
(
userService
.
getEmployeeDetailsForAutocomplete
()).
thenReturn
(
details
);
mockMvc
.
perform
(
get
(
"/user/getEmployeeDetailsForAutocomplete"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
()).
andDo
(
print
());
verify
(
userService
).
getEmployeeDetailsForAutocomplete
();
}
@Test
public
void
testgetManagers
()
throws
Exception
{
List
<
EmployeeRoles
>
employeesRole4
=
CreateUserRoles
();
System
.
out
.
println
(
employeesRole4
);
when
(
userService
.
getEmployeeRoles
()).
thenReturn
(
employeesRole4
);
mockMvc
.
perform
(
get
(
"/user/getManagers"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeeRoles
();
}
@Test
public
void
testgetAllShifts
()
throws
Exception
{
List
<
Shift
>
shifts
=
CreateShifts
();
when
(
userService
.
getAllShifts
()).
thenReturn
(
shifts
);
mockMvc
.
perform
(
get
(
"/user/getAllShifts"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getAllShifts
();
}
@Test
public
void
testgetAllDesignations
()
throws
Exception
{
List
<
Designation
>
designation
=
CreateDesignations
();
when
(
userService
.
getAllDesignations
()).
thenReturn
(
designation
);
mockMvc
.
perform
(
get
(
"/user/getAllDesignations"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getAllDesignations
();
}
@Test
public
void
testgetTechnologies
()
throws
Exception
{
List
<
Skill
>
skills
=
CreateSkill
();
System
.
out
.
println
(
skills
);
when
(
userService
.
getTechnologies
()).
thenReturn
(
skills
);
mockMvc
.
perform
(
get
(
"/user/getSkills"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getTechnologies
();
}
@Test
public
void
testupdateProfile
()
throws
Exception
{
EmployeeRoles
employeeRole
=
new
EmployeeRoles
(
"5996ef15874c902c98b8a05d"
,
"16127"
,
"Monika Srivastava"
,
"msrivastava@nisum.com"
,
"Employee"
,
"Software Engineer"
,
"09:00-06:00"
,
"Java/J2EE"
,
"Spring"
,
"8765588388"
,
"9978567723"
,
"msrivastava@gmail.com"
,
null
,
new
Date
(
2017
-
01
-
01
),
new
Date
(
2017
-
03
-
01
));
System
.
out
.
println
(
employeeRole
);
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeeRole
);
System
.
out
.
println
(
jsonString
);
when
(
userService
.
updateProfile
(
anyObject
())).
thenReturn
(
employeeRole
);
mockMvc
.
perform
(
post
(
"/user/updateProfile"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
updateProfile
(
anyObject
());
}
@Test
public
void
getAccounts
()
throws
Exception
{
List
<
Account
>
account
=
CreateAccount
();
System
.
out
.
println
(
account
);
when
(
userService
.
getAccounts
()).
thenReturn
(
account
);
mockMvc
.
perform
(
get
(
"/user/getAccounts"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getAccounts
();
}
private
List
<
Account
>
CreateAccount
()
{
List
<
Account
>
data
=
new
ArrayList
<>();
Account
account1
=
new
Account
();
account1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
account1
.
setAccountId
(
"01"
);
account1
.
setAccountName
(
"GAP"
);
account1
.
setAccountProjectSequence
(
1
);
account1
.
setStatus
(
"Active"
);
data
.
add
(
account1
);
Account
account2
=
new
Account
();
account2
.
setId
(
new
ObjectId
(
"2476ef15874c902c98b8a05d"
));
account2
.
setAccountId
(
"02"
);
account2
.
setAccountName
(
"MACYS"
);
account2
.
setAccountProjectSequence
(
2
);
account2
.
setStatus
(
"Non-Active"
);
data
.
add
(
account2
);
return
data
;
}
private
List
<
Skill
>
CreateSkill
()
{
List
<
Skill
>
data
=
new
ArrayList
<>();
Skill
skills1
=
new
Skill
();
skills1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
skills1
.
setSkillId
(
"01"
);
skills1
.
setSkillName
(
"Java"
);
skills1
.
setActiveStatus
(
"Active"
);
data
.
add
(
skills1
);
Skill
skills2
=
new
Skill
();
skills2
.
setId
(
new
ObjectId
(
"2476ef15874c902c98b8a05d"
));
skills2
.
setSkillId
(
"02"
);
skills2
.
setSkillName
(
"Big Data"
);
skills2
.
setActiveStatus
(
"Active"
);
data
.
add
(
skills2
);
return
data
;
}
private
List
<
Designation
>
CreateDesignations
()
{
List
<
Designation
>
data
=
new
ArrayList
<>();
Designation
desig1
=
new
Designation
();
@Mock
UserService
userService
;
@InjectMocks
UserController
userController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
userController
).
build
();
}
@Test
public
void
testgetEmployeeRole
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
null
,
null
,
"user@nisum.com"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2017
-
12
-
23
));
when
(
userService
.
getEmployeesRole
(
"user@nisum.com"
))
.
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/user/employee"
).
param
(
"emailId"
,
"user@nisum.com"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeesRole
(
"user@nisum.com"
);
}
@Test
public
void
testassigingEmployeeRole
()
throws
Exception
{
EmployeeRoles
employeeRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05c"
,
"16135"
,
"Monika"
,
"user1@nisum.com"
,
"HR"
,
"Human Resource Lead"
,
"06:00-09:00"
,
"Java/J2EE"
,
"Spring"
,
"8767893452"
,
"5687234567"
,
"user1@gmail.com"
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2017
-
12
-
23
));
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeeRole
);
when
(
userService
.
assigingEmployeeRole
(
anyObject
()))
.
thenReturn
(
employeeRole
);
mockMvc
.
perform
(
post
(
"/user/assignEmployeeRole"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
assigingEmployeeRole
(
anyObject
());
}
@Test
public
void
testupdateEmployeeRole
()
throws
Exception
{
EmployeeRoles
employeeRole2
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
"67890"
,
"Sonika"
,
"user2@nisum.com"
,
"Manager"
,
"Senior Software Engineer"
,
"09:00am-06:00am"
,
"php"
,
"Hibernate"
,
"9878678956"
,
"9989782210"
,
"user2@gmail.com"
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2017
-
12
-
23
));
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeeRole2
);
when
(
userService
.
updateEmployeeRole
(
anyObject
()))
.
thenReturn
(
employeeRole2
);
mockMvc
.
perform
(
post
(
"/user/updateEmployeeRole"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
updateEmployeeRole
(
anyObject
());
}
@Test
public
void
testdeleteEmployee
()
throws
Exception
{
mockMvc
.
perform
(
delete
(
"/user/deleteEmployee"
).
param
(
"empId"
,
"16127"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
deleteEmployee
(
"16127"
);
}
@Test
public
void
testgetUserRoles
()
throws
Exception
{
List
<
EmployeeRoles
>
employeesRole3
=
CreateUserRoles
();
when
(
userService
.
getEmployeeRoles
()).
thenReturn
(
employeesRole3
);
mockMvc
.
perform
(
get
(
"/user/getUserRoles"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeeRoles
();
}
@Test
public
void
testgetEmployeeRoleData
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
"16127"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
13
),
new
Date
(
2017
-
12
-
20
));
when
(
userService
.
getEmployeesRoleData
(
"16127"
))
.
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/user/getEmployeeRoleData"
).
param
(
"empId"
,
"16127"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andExpect
(
jsonPath
(
"$.employeeId"
,
is
(
"16127"
)))
.
andDo
(
print
());
verify
(
userService
).
getEmployeesRoleData
(
"16127"
);
}
@Test
public
void
testgetEmployeeRoleDataForEmailIdSearch
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
"16209"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
13
),
new
Date
(
2017
-
12
-
20
));
when
(
userService
.
getEmployeeRoleDataForSearchCriteria
(
"dummy@nisum.com"
,
"emailId"
)).
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/user/getEmployeeRoleDataForSearchCriteria"
)
.
param
(
"searchId"
,
"dummy@nisum.com"
)
.
param
(
"searchAttribute"
,
"emailId"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andExpect
(
jsonPath
(
"$.employeeId"
,
is
(
"16209"
)))
.
andDo
(
print
());
verify
(
userService
).
getEmployeeRoleDataForSearchCriteria
(
"dummy@nisum.com"
,
"emailId"
);
}
@Test
public
void
testgetEmployeeRoleDataForEmployeeNameSearch
()
throws
Exception
{
EmployeeRoles
employeesRole
=
new
EmployeeRoles
(
"5976ef15874c902c98b8a05d"
,
"16209"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
13
),
new
Date
(
2017
-
12
-
20
));
when
(
userService
.
getEmployeeRoleDataForSearchCriteria
(
"Mahesh Kumar Gutam"
,
"employeeName"
))
.
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/user/getEmployeeRoleDataForSearchCriteria"
)
.
param
(
"searchId"
,
"Mahesh Kumar Gutam"
)
.
param
(
"searchAttribute"
,
"employeeName"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andExpect
(
jsonPath
(
"$.employeeId"
,
is
(
"16209"
)))
.
andDo
(
print
());
verify
(
userService
).
getEmployeeRoleDataForSearchCriteria
(
"Mahesh Kumar Gutam"
,
"employeeName"
);
}
@Test
public
void
testGetEmployeeDetailsForAutocomplete
()
throws
Exception
{
List
<
String
>
details
=
new
ArrayList
<>();
details
.
add
(
"16294"
);
details
.
add
(
"Ashwin Kumar"
);
details
.
add
(
"kashwin@nisum.com"
);
details
.
add
(
"16209"
);
details
.
add
(
"Mahesh Kumar Gutam"
);
details
.
add
(
"mgutam@nisum.com"
);
details
.
add
(
"16143"
);
details
.
add
(
"Ajay"
);
details
.
add
(
"ajayS@nisum.com"
);
details
.
add
(
"16207"
);
details
.
add
(
"Sumith Kumar Lambu"
);
details
.
add
(
"slambu@nisum.com"
);
details
.
add
(
"16111"
);
details
.
add
(
"Mahesh Mudrakolu"
);
details
.
add
(
"mmahesh@nisum.com"
);
when
(
userService
.
getEmployeeDetailsForAutocomplete
())
.
thenReturn
(
details
);
mockMvc
.
perform
(
get
(
"/user/getEmployeeDetailsForAutocomplete"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andDo
(
print
());
verify
(
userService
).
getEmployeeDetailsForAutocomplete
();
}
@Test
public
void
testgetManagers
()
throws
Exception
{
List
<
EmployeeRoles
>
employeesRole4
=
CreateUserRoles
();
System
.
out
.
println
(
employeesRole4
);
when
(
userService
.
getEmployeeRoles
()).
thenReturn
(
employeesRole4
);
mockMvc
.
perform
(
get
(
"/user/getManagers"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getEmployeeRoles
();
}
@Test
public
void
testgetAllShifts
()
throws
Exception
{
List
<
Shift
>
shifts
=
CreateShifts
();
when
(
userService
.
getAllShifts
()).
thenReturn
(
shifts
);
mockMvc
.
perform
(
get
(
"/user/getAllShifts"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getAllShifts
();
}
@Test
public
void
testgetAllDesignations
()
throws
Exception
{
List
<
Designation
>
designation
=
CreateDesignations
();
when
(
userService
.
getAllDesignations
()).
thenReturn
(
designation
);
mockMvc
.
perform
(
get
(
"/user/getAllDesignations"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getAllDesignations
();
}
@Test
public
void
testgetTechnologies
()
throws
Exception
{
List
<
Skill
>
skills
=
CreateSkill
();
System
.
out
.
println
(
skills
);
when
(
userService
.
getTechnologies
()).
thenReturn
(
skills
);
mockMvc
.
perform
(
get
(
"/user/getSkills"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getTechnologies
();
}
@Test
public
void
testupdateProfile
()
throws
Exception
{
EmployeeRoles
employeeRole
=
new
EmployeeRoles
(
"5996ef15874c902c98b8a05d"
,
"16127"
,
"Monika Srivastava"
,
"msrivastava@nisum.com"
,
"Employee"
,
"Software Engineer"
,
"09:00-06:00"
,
"Java/J2EE"
,
"Spring"
,
"8765588388"
,
"9978567723"
,
"msrivastava@gmail.com"
,
null
,
null
,
null
,
null
,
null
,
new
Date
(
2017
-
01
-
01
),
new
Date
(
2017
-
03
-
01
));
System
.
out
.
println
(
employeeRole
);
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeeRole
);
System
.
out
.
println
(
jsonString
);
when
(
userService
.
updateProfile
(
anyObject
())).
thenReturn
(
employeeRole
);
mockMvc
.
perform
(
post
(
"/user/updateProfile"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
updateProfile
(
anyObject
());
}
@Test
public
void
getAccounts
()
throws
Exception
{
List
<
Account
>
account
=
CreateAccount
();
System
.
out
.
println
(
account
);
when
(
userService
.
getAccounts
()).
thenReturn
(
account
);
mockMvc
.
perform
(
get
(
"/user/getAccounts"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
getAccounts
();
}
private
List
<
Account
>
CreateAccount
()
{
List
<
Account
>
data
=
new
ArrayList
<>();
Account
account1
=
new
Account
();
account1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
account1
.
setAccountId
(
"01"
);
account1
.
setAccountName
(
"GAP"
);
account1
.
setAccountProjectSequence
(
1
);
account1
.
setStatus
(
"Active"
);
data
.
add
(
account1
);
Account
account2
=
new
Account
();
account2
.
setId
(
new
ObjectId
(
"2476ef15874c902c98b8a05d"
));
account2
.
setAccountId
(
"02"
);
account2
.
setAccountName
(
"MACYS"
);
account2
.
setAccountProjectSequence
(
2
);
account2
.
setStatus
(
"Non-Active"
);
data
.
add
(
account2
);
return
data
;
}
private
List
<
Skill
>
CreateSkill
()
{
List
<
Skill
>
data
=
new
ArrayList
<>();
Skill
skills1
=
new
Skill
();
skills1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
skills1
.
setSkillId
(
"01"
);
skills1
.
setSkillName
(
"Java"
);
skills1
.
setActiveStatus
(
"Active"
);
data
.
add
(
skills1
);
Skill
skills2
=
new
Skill
();
skills2
.
setId
(
new
ObjectId
(
"2476ef15874c902c98b8a05d"
));
skills2
.
setSkillId
(
"02"
);
skills2
.
setSkillName
(
"Big Data"
);
skills2
.
setActiveStatus
(
"Active"
);
data
.
add
(
skills2
);
return
data
;
}
private
List
<
Designation
>
CreateDesignations
()
{
List
<
Designation
>
data
=
new
ArrayList
<>();
Designation
desig1
=
new
Designation
();
desig1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
desig1
.
setDesignationId
(
"01"
);
desig1
.
setDesignationName
(
"Manager"
);
desig1
.
setActiveStatus
(
"Active"
);
data
.
add
(
desig1
);
Designation
desig2
=
new
Designation
();
desig2
.
setId
(
new
ObjectId
(
"2476ef15874c902c98b8a05d"
));
desig2
.
setDesignationId
(
"02"
);
desig2
.
setDesignationName
(
"Employee"
);
desig2
.
setActiveStatus
(
"Active"
);
data
.
add
(
desig2
);
return
data
;
}
private
List
<
Shift
>
CreateShifts
()
{
List
<
Shift
>
data
=
new
ArrayList
<>();
Shift
shift1
=
new
Shift
();
shift1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
shift1
.
setShiftId
(
"01"
);
shift1
.
setShiftName
(
"Morning Shift"
);
shift1
.
setActiveStatus
(
"Active"
);
data
.
add
(
shift1
);
Shift
shift2
=
new
Shift
();
shift2
.
setId
(
new
ObjectId
(
"2476ef15874c902c98b8a05d"
));
shift2
.
setShiftId
(
"02"
);
shift2
.
setShiftName
(
"Night Shift"
);
shift2
.
setActiveStatus
(
"Active"
);
data
.
add
(
shift2
);
return
data
;
}
private
List
<
EmployeeRoles
>
CreateUserRoles
()
{
List
<
EmployeeRoles
>
data
=
new
ArrayList
<>();
EmployeeRoles
data1
=
new
EmployeeRoles
();
data1
.
setId
(
"3976ef15874c902c98b8a05d"
);
data1
.
setEmployeeId
(
"16101"
);
data1
.
setEmployeeName
(
"Abc"
);
data1
.
setEmailId
(
"user1@nisum.com"
);
data1
.
setRole
(
"HR"
);
data1
.
setDesignation
(
"Human Resource Manager"
);
data1
.
setShift
(
"09:00-06:00"
);
data1
.
setBaseTechnology
(
"Spring"
);
data1
.
setTechnologyKnown
(
"Jmeter"
);
data1
.
setMobileNumber
(
"9978567809"
);
data1
.
setAlternateMobileNumber
(
"7789092345"
);
data1
.
setPersonalEmailId
(
"user1@gmail.com"
);
data1
.
setCreatedOn
(
new
Date
(
2017
-
11
-
21
));
data1
.
setLastModifiedOn
(
new
Date
(
2017
-
12
-
22
));
EmployeeRoles
data2
=
new
EmployeeRoles
();
data2
.
setId
(
"4976ef15874c902c98b8a05d"
);
data2
.
setEmployeeId
(
"16102"
);
data2
.
setEmployeeName
(
"Xyz"
);
data2
.
setEmailId
(
"user2@nisum.com"
);
data2
.
setRole
(
"Manager"
);
data2
.
setDesignation
(
"Senior Software Engineer"
);
data2
.
setShift
(
"03:00-12:00"
);
data2
.
setBaseTechnology
(
"Hibernate"
);
data2
.
setTechnologyKnown
(
"EJB"
);
data2
.
setMobileNumber
(
"9989087671"
);
data2
.
setAlternateMobileNumber
(
"9999786756"
);
data2
.
setPersonalEmailId
(
"user2@gmail.com"
);
data2
.
setCreatedOn
(
new
Date
(
2017
-
11
-
23
));
data2
.
setLastModifiedOn
(
new
Date
(
2017
-
12
-
22
));
data
.
add
(
data1
);
data
.
add
(
data2
);
return
data
;
}
data
.
add
(
desig1
);
Designation
desig2
=
new
Designation
();
desig2
.
setId
(
new
ObjectId
(
"2476ef15874c902c98b8a05d"
));
desig2
.
setDesignationId
(
"02"
);
desig2
.
setDesignationName
(
"Employee"
);
desig2
.
setActiveStatus
(
"Active"
);
data
.
add
(
desig2
);
return
data
;
}
private
List
<
Shift
>
CreateShifts
()
{
List
<
Shift
>
data
=
new
ArrayList
<>();
Shift
shift1
=
new
Shift
();
shift1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
shift1
.
setShiftId
(
"01"
);
shift1
.
setShiftName
(
"Morning Shift"
);
shift1
.
setActiveStatus
(
"Active"
);
data
.
add
(
shift1
);
Shift
shift2
=
new
Shift
();
shift2
.
setId
(
new
ObjectId
(
"2476ef15874c902c98b8a05d"
));
shift2
.
setShiftId
(
"02"
);
shift2
.
setShiftName
(
"Night Shift"
);
shift2
.
setActiveStatus
(
"Active"
);
data
.
add
(
shift2
);
return
data
;
}
private
List
<
EmployeeRoles
>
CreateUserRoles
()
{
List
<
EmployeeRoles
>
data
=
new
ArrayList
<>();
EmployeeRoles
data1
=
new
EmployeeRoles
();
data1
.
setId
(
"3976ef15874c902c98b8a05d"
);
data1
.
setEmployeeId
(
"16101"
);
data1
.
setEmployeeName
(
"Abc"
);
data1
.
setEmailId
(
"user1@nisum.com"
);
data1
.
setRole
(
"HR"
);
data1
.
setDesignation
(
"Human Resource Manager"
);
data1
.
setShift
(
"09:00-06:00"
);
data1
.
setBaseTechnology
(
"Spring"
);
data1
.
setTechnologyKnown
(
"Jmeter"
);
data1
.
setMobileNumber
(
"9978567809"
);
data1
.
setAlternateMobileNumber
(
"7789092345"
);
data1
.
setPersonalEmailId
(
"user1@gmail.com"
);
data1
.
setCreatedOn
(
new
Date
(
2017
-
11
-
21
));
data1
.
setLastModifiedOn
(
new
Date
(
2017
-
12
-
22
));
EmployeeRoles
data2
=
new
EmployeeRoles
();
data2
.
setId
(
"4976ef15874c902c98b8a05d"
);
data2
.
setEmployeeId
(
"16102"
);
data2
.
setEmployeeName
(
"Xyz"
);
data2
.
setEmailId
(
"user2@nisum.com"
);
data2
.
setRole
(
"Manager"
);
data2
.
setDesignation
(
"Senior Software Engineer"
);
data2
.
setShift
(
"03:00-12:00"
);
data2
.
setBaseTechnology
(
"Hibernate"
);
data2
.
setTechnologyKnown
(
"EJB"
);
data2
.
setMobileNumber
(
"9989087671"
);
data2
.
setAlternateMobileNumber
(
"9999786756"
);
data2
.
setPersonalEmailId
(
"user2@gmail.com"
);
data2
.
setCreatedOn
(
new
Date
(
2017
-
11
-
23
));
data2
.
setLastModifiedOn
(
new
Date
(
2017
-
12
-
22
));
data
.
add
(
data1
);
data
.
add
(
data2
);
return
data
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment