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
ec748ad5
Commit
ec748ad5
authored
Jun 24, 2019
by
shiva dandem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added JUNIT Code coverage for controllers
parent
4319b7a8
Changes
19
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
1463 additions
and
763 deletions
+1463
-763
AccountControllerTest.java
...om/nisum/myteam/controllertest/AccountControllerTest.java
+167
-64
AccountControllerTestx.java
...m/nisum/myteam/controllertest/AccountControllerTestx.java
+170
-0
AttendanceControllerTest.java
...nisum/myteam/controllertest/AttendanceControllerTest.java
+23
-1
DashboardControllerTest.java
.../nisum/myteam/controllertest/DashboardControllerTest.java
+45
-0
DesignationControllerTest.java
...isum/myteam/controllertest/DesignationControllerTest.java
+45
-0
DomainControllerTest.java
...com/nisum/myteam/controllertest/DomainControllerTest.java
+97
-27
EmailControllerTest.java
.../com/nisum/myteam/controllertest/EmailControllerTest.java
+10
-5
EmployeeControllerTest.java
...m/nisum/myteam/controllertest/EmployeeControllerTest.java
+123
-475
EmployeeEffortsControllerTest.java
.../myteam/controllertest/EmployeeEffortsControllerTest.java
+90
-0
EmployeeLocationControllerTest.java
...myteam/controllertest/EmployeeLocationControllerTest.java
+65
-0
LoginReportsControllerTest.java
...sum/myteam/controllertest/LoginReportsControllerTest.java
+59
-0
MasterDataControllerTest.java
...nisum/myteam/controllertest/MasterDataControllerTest.java
+40
-0
OrgLocationControllerTest.java
...isum/myteam/controllertest/OrgLocationControllerTest.java
+49
-0
ProjectControllerTest.java
...om/nisum/myteam/controllertest/ProjectControllerTest.java
+203
-191
ReportsControllerTest.java
...om/nisum/myteam/controllertest/ReportsControllerTest.java
+44
-0
ResourceControllerTest.java
...m/nisum/myteam/controllertest/ResourceControllerTest.java
+80
-0
ShiftControllerTest.java
.../com/nisum/myteam/controllertest/ShiftControllerTest.java
+44
-0
SkillControllerTest.java
.../com/nisum/myteam/controllertest/SkillControllerTest.java
+42
-0
UploadXLControllerTest.java
...m/nisum/myteam/controllertest/UploadXLControllerTest.java
+67
-0
No files found.
src/test/java/com/nisum/myteam/controllertest/AccountControllerTest.java
View file @
ec748ad5
...
@@ -2,6 +2,7 @@ package com.nisum.myteam.controllertest;
...
@@ -2,6 +2,7 @@ package com.nisum.myteam.controllertest;
import
java.util.Map
;
import
java.util.Map
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
anyObject
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
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
.
delete
;
...
@@ -18,7 +19,9 @@ import org.junit.Before;
...
@@ -18,7 +19,9 @@ import org.junit.Before;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.Mockito
;
import
org.mockito.MockitoAnnotations
;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.result.MockMvcResultMatchers
;
import
org.springframework.test.web.servlet.result.MockMvcResultMatchers
;
...
@@ -27,14 +30,14 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
...
@@ -27,14 +30,14 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.nisum.myteam.controller.AccountController
;
import
com.nisum.myteam.controller.AccountController
;
import
com.nisum.myteam.model.dao.Account
;
import
com.nisum.myteam.model.dao.Account
;
import
com.nisum.myteam.service.IAccountService
;
import
com.nisum.myteam.service.impl.AccountService
;
import
com.nisum.myteam.service.impl.AccountService
;
public
class
AccountControllerTest
{
public
class
AccountControllerTest
{
@Mock
@Mock
private
IAccountService
accountService
;
AccountService
Accountserviceimpl
;
@InjectMocks
@InjectMocks
AccountController
AccountController
;
AccountController
AccountController
;
...
@@ -46,89 +49,190 @@ public class AccountControllerTest {
...
@@ -46,89 +49,190 @@ public class AccountControllerTest {
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
AccountController
).
build
();
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
AccountController
).
build
();
}
}
//
@Test
// public void createAccountTest()
public
void
testCreateAccount
()
throws
Exception
{
// {
List
<
String
>
list
=
new
ArrayList
<>();
//
list
.
add
(
"16620"
);
// }
list
.
add
(
"16632"
);
Account
responce
=
null
;
Account
account
=
new
Account
(
new
ObjectId
(
"5b62b00950e71a6eecc8c98c"
),
"Acc003"
,
"Nisum"
,
3
,
"Y"
,
"HYD"
,
"RetailS"
,
list
);
when
(
accountService
.
createAccount
(
account
))
.
thenReturn
(
responce
);
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
account
).
toString
();
mockMvc
.
perform
(
post
(
"/accounts"
).
param
(
"action"
,
"N"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
// @Test
@Test
// public void testaddAccount() throws Exception {
public
void
testCreateAccountExists
()
throws
Exception
{
// List<String> list = new ArrayList<>();
List
<
String
>
list
=
new
ArrayList
<>();
// list.add("16620");
list
.
add
(
"16620"
);
// list.add("16632");
list
.
add
(
"16632"
);
// String responce=null;
Account
responce
=
null
;
// Account persistedAccount=null;
Account
account
=
new
Account
(
// Account account = new Account(
new
ObjectId
(
"5b62b00950e71a6eecc8c98c"
),
"Acc003"
,
"Nisum"
,
3
,
// "Acc003", "Nisum", 3,
"Y"
,
"HYD"
,
"RetailS"
,
list
);
// "Y","HYD","RetailS",list);
when
(
accountService
.
isAccountExists
((
Account
)
anyObject
()))
// when(Accountserviceimpl.createAccount(account))
.
thenReturn
(
true
);
// .thenReturn(persistedAccount);
when
(
accountService
.
createAccount
(
account
))
// String jsonvalue = (new ObjectMapper())
.
thenReturn
(
responce
);
// .writeValueAsString(account).toString();
String
jsonvalue
=
(
new
ObjectMapper
())
// mockMvc.perform(post("/account/accounts").param("action","N")
.
writeValueAsString
(
account
).
toString
();
// .contentType(MediaType.APPLICATION_JSON_VALUE)
mockMvc
.
perform
(
post
(
"/accounts"
).
param
(
"action"
,
"N"
)
// .content(jsonvalue))
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
// .andExpect(MockMvcResultMatchers.status().isOk());
.
content
(
jsonvalue
))
// }
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
@Test
public
void
testgetAccountNames
()
throws
Exception
{
public
void
testgetAccountNames
()
throws
Exception
{
List
<
Map
<
Object
,
Object
>>
Account
=
CreateAccountDetails
();
Account
account
=
new
Account
();
when
(
Accountserviceimpl
.
getAccountsList
()).
thenReturn
(
Account
);
account
.
setAccountId
(
"123"
);
mockMvc
.
perform
(
get
(
"/account/accountNames"
)
List
<
Account
>
accounts
=
new
ArrayList
<>();
accounts
.
add
(
account
);
//List<Map<Object, Object>> Account = CreateAccountDetails();
when
(
accountService
.
getAllAccounts
()).
thenReturn
(
accounts
);
mockMvc
.
perform
(
get
(
"/accounts/names"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
}
/*
@Test
@Test
public void testgetAccount() throws Exception {
public void testgetAccount() throws Exception {
List
<
Account
>
Account
=
null
;
List<
Map<Object, Object>
> Account = null;
when
(
Accountserviceimpl
.
getAccounts
()).
thenReturn
(
Account
);
when(
accountService.getAccountsList
()).thenReturn(Account);
mockMvc
.
perform
(
get
(
"/account
/account
s"
)
mockMvc.perform(get("/accounts")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk());
.andExpect(MockMvcResultMatchers.status().isOk());
} */
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testGetAccountsList
()
throws
Exception
{
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16620"
);
list
.
add
(
"16632"
);
// String response=null;
Account
accountPeristed
=
null
;
Account
account
=
new
Account
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
),
"Acc003"
,
"Marketing"
,
2
,
"Active"
,
"abx"
,
"dfv"
,
list
);
when
(
accountService
.
getAccountsList
())
.
thenReturn
((
List
<
Map
<
Object
,
Object
>>)
accountPeristed
);
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
account
).
toString
();
mockMvc
.
perform
(
get
(
"/accounts"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testupdateAccount
()
throws
Exception
{
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16620"
);
list
.
add
(
"16632"
);
Account
responce
=
null
;
Account
account
=
new
Account
(
new
ObjectId
(
"5b62b00950e71a6eecc8c98c"
),
"Acc003"
,
"Nisum"
,
3
,
"Y"
,
"HYD"
,
"RetailS"
,
list
);
when
(
accountService
.
updateAccountAndRolesForDMS
(
account
))
.
thenReturn
(
responce
);
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
account
).
toString
();
mockMvc
.
perform
(
put
(
"/accounts/Acc003"
).
param
(
"action"
,
"Acc003"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testupdateAccountExists
()
throws
Exception
{
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16620"
);
list
.
add
(
"16632"
);
Account
responce
=
null
;
Account
account
=
new
Account
(
new
ObjectId
(
"5b62b00950e71a6eecc8c98c"
),
"Acc003"
,
"Nisum"
,
3
,
"Y"
,
"HYD"
,
"RetailS"
,
list
);
when
(
accountService
.
isAccountExists
((
Account
)
anyObject
())).
thenReturn
(
true
);
when
(
accountService
.
updateAccountAndRolesForDMS
(
account
))
.
thenReturn
(
account
);
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
account
).
toString
();
mockMvc
.
perform
(
put
(
"/accounts/Acc003"
).
param
(
"action"
,
"Acc003"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
}
// @Test
// public void testupdateAccount() throws Exception {
// List<String> list = new ArrayList<>();
// list.add("16620");
// list.add("16632");
// String responce=null;
// Account accountUpdated=null;
// Account account = new Account(
// "Acc003", "Nisum", 3,
// "Y","HYD","RetailS",list);
// when(Accountserviceimpl.createAccount(account))
// .thenReturn(accountUpdated);
// String jsonvalue = (new ObjectMapper())
// .writeValueAsString(account).toString();
// mockMvc.perform(post("/account/accounts").param("action","U")
// .contentType(MediaType.APPLICATION_JSON_VALUE)
// .content(jsonvalue))
// .andExpect(MockMvcResultMatchers.status().isOk());
// }
//
@Test
@Test
public
void
testdeleteAccount
()
throws
Exception
{
public
void
testdeleteAccount
()
throws
Exception
{
mockMvc
.
perform
(
mockMvc
.
perform
(
delete
(
"/account
/accounts
"
).
param
(
"accountId"
,
"Acc002"
))
delete
(
"/account
s/Acc002
"
).
param
(
"accountId"
,
"Acc002"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
Accountserviceimpl
).
deleteAccount
(
"Acc002"
);
//verify(AccountController
).deleteAccount("Acc002");
}
}
@Test
public
void
testGetALLAccounts
()
throws
Exception
{
List
<
Account
>
Account
=
null
;
when
(
accountService
.
getAllAccounts
()).
thenReturn
(
Account
);
mockMvc
.
perform
(
get
(
"/accounts/status"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testGetAccountById
()
throws
Exception
{
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16620"
);
list
.
add
(
"16632"
);
Account
responce
=
null
;
Account
account
=
new
Account
(
new
ObjectId
(
"5b62b00950e71a6eecc8c98c"
),
"Acc003"
,
"Nisum"
,
3
,
"Y"
,
"HYD"
,
"RetailS"
,
list
);
when
(
accountService
.
getAccountById
(
"Acc003"
))
.
thenReturn
(
responce
);
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
account
).
toString
();
mockMvc
.
perform
(
get
(
"/accounts/accountId/Acc003"
).
param
(
"action"
,
"Acc003"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testGetAccountByIdExists
()
throws
Exception
{
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16620"
);
list
.
add
(
"16632"
);
Account
responce
=
null
;
Account
account
=
new
Account
(
new
ObjectId
(
"5b62b00950e71a6eecc8c98c"
),
"Acc003"
,
"Nisum"
,
3
,
"Y"
,
"HYD"
,
"RetailS"
,
list
);
when
(
accountService
.
isAccountExists
(
"Acc003"
))
.
thenReturn
(
true
);
when
(
accountService
.
getAccountById
(
"Acc003"
))
.
thenReturn
(
responce
);
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
account
).
toString
();
mockMvc
.
perform
(
get
(
"/accounts/accountId/Acc003"
).
param
(
"action"
,
"Acc003"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
private
List
<
Map
<
Object
,
Object
>>
CreateAccountDetails
()
{
private
List
<
Map
<
Object
,
Object
>>
CreateAccountDetails
()
{
List
<
Map
<
Object
,
Object
>>
data
=
new
ArrayList
<
Map
<
Object
,
Object
>>
();
List
<
Map
<
Object
,
Object
>>
data
=
new
ArrayList
<
Map
<
Object
,
Object
>>
();
HashMap
<
Object
,
Object
>
map1
=
new
HashMap
<
Object
,
Object
>();
HashMap
<
Object
,
Object
>
map1
=
new
HashMap
<
Object
,
Object
>();
HashMap
<
Object
,
Object
>
map2
=
new
HashMap
<
Object
,
Object
>();
HashMap
<
Object
,
Object
>
map2
=
new
HashMap
<
Object
,
Object
>();
Account
data1
=
new
Account
();
Account
data1
=
new
Account
();
//
data1.setId(new ObjectId("5976ef15874c902c98b8a05d"));
data1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
data1
.
setAccountId
(
"Acc004"
);
data1
.
setAccountId
(
"Acc004"
);
data1
.
setAccountName
(
"Govt"
);
data1
.
setAccountName
(
"Govt"
);
data1
.
setAccountProjectSequence
(
4
);
data1
.
setAccountProjectSequence
(
4
);
...
@@ -143,7 +247,7 @@ public class AccountControllerTest {
...
@@ -143,7 +247,7 @@ public class AccountControllerTest {
data1
.
setDeliveryManagers
(
list
);
data1
.
setDeliveryManagers
(
list
);
Account
data2
=
new
Account
();
Account
data2
=
new
Account
();
//
data2.setId(new ObjectId("9976ef15874c902c98b8a05d"));
data2
.
setId
(
new
ObjectId
(
"9976ef15874c902c98b8a05d"
));
data2
.
setAccountId
(
"Acc004"
);
data2
.
setAccountId
(
"Acc004"
);
data2
.
setAccountName
(
"Govt"
);
data2
.
setAccountName
(
"Govt"
);
data2
.
setAccountProjectSequence
(
4
);
data2
.
setAccountProjectSequence
(
4
);
...
@@ -166,5 +270,4 @@ public class AccountControllerTest {
...
@@ -166,5 +270,4 @@ public class AccountControllerTest {
return
data
;
return
data
;
}
}
}
}
src/test/java/com/nisum/myteam/controllertest/AccountControllerTestx.java
0 → 100644
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
import
java.util.Map
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
verify
;
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
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
put
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
org.bson.types.ObjectId
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
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.myteam.controller.AccountController
;
import
com.nisum.myteam.model.dao.Account
;
import
com.nisum.myteam.service.impl.AccountService
;
public
class
AccountControllerTest
{
@Mock
AccountService
Accountserviceimpl
;
@InjectMocks
AccountController
AccountController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
AccountController
).
build
();
}
//
// public void createAccountTest()
// {
//
// }
// @Test
// public void testaddAccount() throws Exception {
// List<String> list = new ArrayList<>();
// list.add("16620");
// list.add("16632");
// String responce=null;
// Account persistedAccount=null;
// Account account = new Account(
// "Acc003", "Nisum", 3,
// "Y","HYD","RetailS",list);
// when(Accountserviceimpl.createAccount(account))
// .thenReturn(persistedAccount);
// String jsonvalue = (new ObjectMapper())
// .writeValueAsString(account).toString();
// mockMvc.perform(post("/account/accounts").param("action","N")
// .contentType(MediaType.APPLICATION_JSON_VALUE)
// .content(jsonvalue))
// .andExpect(MockMvcResultMatchers.status().isOk());
// }
@Test
public
void
testgetAccountNames
()
throws
Exception
{
List
<
Map
<
Object
,
Object
>>
Account
=
CreateAccountDetails
();
when
(
Accountserviceimpl
.
getAccountsList
()).
thenReturn
(
Account
);
mockMvc
.
perform
(
get
(
"/account/accountNames"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
@Test
public
void
testgetAccount
()
throws
Exception
{
List
<
Account
>
Account
=
null
;
when
(
Accountserviceimpl
.
getAccounts
()).
thenReturn
(
Account
);
mockMvc
.
perform
(
get
(
"/account/accounts"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
// @Test
// public void testupdateAccount() throws Exception {
// List<String> list = new ArrayList<>();
// list.add("16620");
// list.add("16632");
// String responce=null;
// Account accountUpdated=null;
// Account account = new Account(
// "Acc003", "Nisum", 3,
// "Y","HYD","RetailS",list);
// when(Accountserviceimpl.createAccount(account))
// .thenReturn(accountUpdated);
// String jsonvalue = (new ObjectMapper())
// .writeValueAsString(account).toString();
// mockMvc.perform(post("/account/accounts").param("action","U")
// .contentType(MediaType.APPLICATION_JSON_VALUE)
// .content(jsonvalue))
// .andExpect(MockMvcResultMatchers.status().isOk());
// }
//
@Test
public
void
testdeleteAccount
()
throws
Exception
{
mockMvc
.
perform
(
delete
(
"/account/accounts"
).
param
(
"accountId"
,
"Acc002"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
Accountserviceimpl
).
deleteAccount
(
"Acc002"
);
}
private
List
<
Map
<
Object
,
Object
>>
CreateAccountDetails
()
{
List
<
Map
<
Object
,
Object
>>
data
=
new
ArrayList
<
Map
<
Object
,
Object
>>
();
HashMap
<
Object
,
Object
>
map1
=
new
HashMap
<
Object
,
Object
>();
HashMap
<
Object
,
Object
>
map2
=
new
HashMap
<
Object
,
Object
>();
Account
data1
=
new
Account
();
// data1.setId(new ObjectId("5976ef15874c902c98b8a05d"));
data1
.
setAccountId
(
"Acc004"
);
data1
.
setAccountName
(
"Govt"
);
data1
.
setAccountProjectSequence
(
4
);
data1
.
setClientAddress
(
"BNG"
);
data1
.
setIndustryType
(
"Telecom"
);
data1
.
setStatus
(
"Y"
);
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16101"
);
list
.
add
(
"16102"
);
list
.
add
(
"16103"
);
data1
.
setDeliveryManagers
(
list
);
Account
data2
=
new
Account
();
//data2.setId(new ObjectId("9976ef15874c902c98b8a05d"));
data2
.
setAccountId
(
"Acc004"
);
data2
.
setAccountName
(
"Govt"
);
data2
.
setAccountProjectSequence
(
4
);
data2
.
setClientAddress
(
"HYD"
);
data2
.
setIndustryType
(
"Telecom"
);
data2
.
setStatus
(
"Y"
);
List
<
String
>
list2
=
new
ArrayList
<>();
list2
.
add
(
"16103"
);
list2
.
add
(
"16105"
);
list2
.
add
(
"16107"
);
data1
.
setDeliveryManagers
(
list
);
map1
.
put
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
),
data1
);
map2
.
put
(
new
ObjectId
(
"9976ef15874c902c98b8a05d"
),
data2
);
data
.
add
(
map1
);
data
.
add
(
map2
);
return
data
;
}
}
src/test/java/com/nisum/myteam/controllertest/AttendanceControllerTest.java
View file @
ec748ad5
...
@@ -24,6 +24,7 @@ import com.nisum.myteam.service.IAttendanceService;
...
@@ -24,6 +24,7 @@ import com.nisum.myteam.service.IAttendanceService;
public
class
AttendanceControllerTest
{
public
class
AttendanceControllerTest
{
@Mock
@Mock
IAttendanceService
attendanceService
;
IAttendanceService
attendanceService
;
...
@@ -38,13 +39,16 @@ public class AttendanceControllerTest {
...
@@ -38,13 +39,16 @@ public class AttendanceControllerTest {
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
attendanceController
).
build
();
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
attendanceController
).
build
();
}
}
@SuppressWarnings
(
"unchecked"
)
@Test
@Test
public
void
testemployeeLoginsBasedOnDate
()
throws
Exception
{
public
void
testemployeeLoginsBasedOnDate
()
throws
Exception
{
List
<
EmpLoginData
>
message
=
createLoginData
();
List
<
EmpLoginData
>
message
=
createLoginData
();
when
(
attendanceService
.
employeeLoginsBasedOnDate
(
12345
,
"2017-11-15"
,
"2017-12-15"
)).
thenReturn
(
message
);
when
(
attendanceService
.
employeeLoginsBasedOnDate
(
12345
,
"2017-11-15"
,
"2017-12-15"
)).
thenReturn
(
message
);
when
(
attendanceService
.
employeeLoginsBasedOnDate
(
01234
,
"2017-11-15"
,
"2017-12-15"
)).
thenThrow
(
Exception
.
class
);
mockMvc
.
perform
(
get
(
"/attendance/employeeLoginsBasedOnDate?empId="
+
12345
).
param
(
"fromDate"
,
"2017-11-15"
)
mockMvc
.
perform
(
get
(
"/attendance/employeeLoginsBasedOnDate?empId="
+
12345
).
param
(
"fromDate"
,
"2017-11-15"
)
.
param
(
"toDate"
,
"2017-12-15"
)).
andDo
(
print
()).
andExpect
(
status
().
isOk
());
.
param
(
"toDate"
,
"2017-12-15"
)).
andDo
(
print
()).
andExpect
(
status
().
isOk
());
}
}
@Test
@Test
public
void
testgeneratePdfReport
()
throws
Exception
{
public
void
testgeneratePdfReport
()
throws
Exception
{
...
@@ -54,6 +58,16 @@ public class AttendanceControllerTest {
...
@@ -54,6 +58,16 @@ public class AttendanceControllerTest {
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
attendanceService
).
generatePdfReport
(
12345
,
"2017-11-18"
,
"2017-12-18"
);
verify
(
attendanceService
).
generatePdfReport
(
12345
,
"2017-11-18"
,
"2017-12-18"
);
}
}
@Test
public
void
testgeneratePdfReportWithTime
()
throws
Exception
{
List
list
=
new
ArrayList
();
when
(
attendanceService
.
generatePdfReport
(
12345
,
"2017-11-18"
,
"2017-12-18"
,
"12:12:04"
,
"15:12:04"
)).
thenReturn
(
list
);
mockMvc
.
perform
(
get
(
"/attendance/generatePdfReport/12345/2017-11-18/2017-12-18/12:12:04/15:12:04"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
attendanceService
).
generatePdfReport
(
12345
,
"2017-11-18"
,
"2017-12-18"
,
"12:12:04"
,
"15:12:04"
);
}
@Test
@Test
public
void
testattendanciesReport
()
throws
Exception
{
public
void
testattendanciesReport
()
throws
Exception
{
...
@@ -71,6 +85,14 @@ public class AttendanceControllerTest {
...
@@ -71,6 +85,14 @@ public class AttendanceControllerTest {
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
attendanceService
).
fetchEmployeesData
(
"2018-01-01"
,
false
);
verify
(
attendanceService
).
fetchEmployeesData
(
"2018-01-01"
,
false
);
}
}
@Test
public
void
testResyncMonthData
()
throws
Exception
{
when
(
attendanceService
.
fetchEmployeesData
(
"2019-01-02"
,
true
)).
thenReturn
(
true
);
mockMvc
.
perform
(
post
(
"/attendance/resyncMonthData/2019-01-02"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
attendanceService
).
fetchEmployeesData
(
"2019-01-02"
,
true
);
}
private
List
<
AttendenceData
>
createAttendenceData
()
{
private
List
<
AttendenceData
>
createAttendenceData
()
{
List
<
AttendenceData
>
data
=
new
ArrayList
<>();
List
<
AttendenceData
>
data
=
new
ArrayList
<>();
...
...
src/test/java/com/nisum/myteam/controllertest/DashboardControllerTest.java
0 → 100644
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
java.util.List
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.result.MockMvcResultMatchers
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
com.nisum.myteam.controller.DashboardController
;
import
com.nisum.myteam.model.vo.EmployeeDashboardVO
;
import
com.nisum.myteam.service.IDashboardService
;
public
class
DashboardControllerTest
{
@Mock
IDashboardService
dashboardService
;
@InjectMocks
DashboardController
dashboardController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
dashboardController
).
build
();
}
@Test
public
void
testGetEmployeesDashBoard
()
throws
Exception
{
List
<
EmployeeDashboardVO
>
employeeDashBoardList
=
null
;
when
(
dashboardService
.
getEmployeesDashBoard
()).
thenReturn
(
employeeDashBoardList
);
mockMvc
.
perform
(
get
(
"/resources/getEmployeesDashBoard"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
}
src/test/java/com/nisum/myteam/controllertest/DesignationControllerTest.java
0 → 100644
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
java.util.List
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
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.nisum.myteam.controller.DesignationController
;
import
com.nisum.myteam.model.dao.Designation
;
import
com.nisum.myteam.service.IDesignationService
;
public
class
DesignationControllerTest
{
@Mock
IDesignationService
designationService
;
@InjectMocks
DesignationController
designationController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
designationController
).
build
();
}
@Test
public
void
testGetAllDesignations
()
throws
Exception
{
List
<
Designation
>
designation
=
null
;
when
(
designationService
.
getAllDesignations
()).
thenReturn
(
designation
);
mockMvc
.
perform
(
get
(
"/employees/designations/"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
}
src/test/java/com/nisum/myteam/controllertest/DomainControllerTest.java
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
anyObject
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
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
.
delete
;
...
@@ -47,61 +48,130 @@ public class DomainControllerTest {
...
@@ -47,61 +48,130 @@ public class DomainControllerTest {
}
}
@Test
@Test
public
void
test
add
Domain
()
throws
Exception
{
public
void
test
Create
Domain
()
throws
Exception
{
List
<
String
>
list
=
new
ArrayList
<>();
List
<
String
>
list
=
new
ArrayList
<>();
list
.
add
(
"16620"
);
list
.
add
(
"16620"
);
list
.
add
(
"16632"
);
list
.
add
(
"16632"
);
String
responce
=
null
;
// String response=null;
Domain
domainPeristed
=
null
;
Domain
domainPeristed
=
null
;
Domain
domains
=
new
Domain
(
"DOM002"
,
"Marketing"
,
"Acc002"
,
"Active"
,
list
);
Domain
domains
=
new
Domain
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
),
"DOM002"
,
"Marketing"
,
"Acc002"
,
"Active"
,
list
);
when
(
domainService
.
create
(
domains
))
when
(
domainService
.
create
(
domains
))
.
thenReturn
(
domainPeristed
);
.
thenReturn
(
domainPeristed
);
String
jsonvalue
=
(
new
ObjectMapper
())
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
domains
).
toString
();
.
writeValueAsString
(
domains
).
toString
();
mockMvc
.
perform
(
post
(
"/domains"
)
mockMvc
.
perform
(
post
(
"/domains"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonvalue
))
.
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
}
@Test
@Test
public
void
testgetDomains
()
throws
Exception
{
public
void
testCreateDomainForDomainExist
()
throws
Exception
{
//List<HashMap<Object,Object>> domains = CreateDomainDetails();
List
<
String
>
list
=
new
ArrayList
<>();
List
domains
=
CreateDomainDetails
();
list
.
add
(
"16620"
);
when
(
domainService
.
getDomainsList
()).
thenReturn
(
domains
);
list
.
add
(
"16632"
);
mockMvc
.
perform
(
get
(
"/domains"
)
// String response=null;
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
Domain
domainPeristed
=
null
;
Domain
domains
=
new
Domain
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
),
"DOM002"
,
"Marketing"
,
"Acc002"
,
"Active"
,
list
);
when
(
domainService
.
isDomainExists
(
anyObject
()))
.
thenReturn
(
true
);
when
(
domainService
.
create
(
domains
))
.
thenReturn
(
domainPeristed
);
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
domains
).
toString
();
mockMvc
.
perform
(
post
(
"/domains"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonvalue
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
domainService
).
getDomainsList
();
}
}
@Test
@Test
public
void
testupdateDomains
()
throws
Exception
{
public
void
testupdateDomains
()
throws
Exception
{
List
<
String
>
employeeIds
=
new
ArrayList
<>();
List
<
String
>
employeeIds
=
new
ArrayList
<>();
employeeIds
.
add
(
"16649"
);
employeeIds
.
add
(
"16649"
);
employeeIds
.
add
(
"16650"
);
employeeIds
.
add
(
"16650"
);
employeeIds
.
add
(
"16651"
);
// employeeIds.add("16651");
String
responce
=
null
;
// String responce=null;
Domain
domain
=
new
Domain
(
"DOM002"
,
"Marketing"
,
"Acc002"
,
Domain
domainPeristed
=
null
;
"Active"
,
employeeIds
);
Domain
domain
=
new
Domain
(
new
ObjectId
(
"9976ef15874c902c98b8a05d"
),
"DOM005"
,
"Marketing"
,
"ACC001"
,
"Active"
,
employeeIds
);
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
domain
);
when
(
domainService
.
update
(
any
())).
thenReturn
(
domainPeristed
);
String
jsonvalue
=
(
new
ObjectMapper
())
.
writeValueAsString
(
domain
).
toString
();
mockMvc
.
perform
(
put
(
"/domains"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
//verify(domainService).update(any());
}
@Test
public
void
testupdateDomainsForDomainExists
()
throws
Exception
{
List
<
String
>
employeeIds
=
new
ArrayList
<>();
employeeIds
.
add
(
"16649"
);
employeeIds
.
add
(
"16650"
);
// employeeIds.add("16651");
// String responce=null;
Domain
domainPeristed
=
null
;
Domain
domain
=
new
Domain
(
new
ObjectId
(
"9976ef15874c902c98b8a05d"
),
"DOM005"
,
"Marketing"
,
"ACC001"
,
"Active"
,
employeeIds
);
ObjectMapper
mapper
=
new
ObjectMapper
();
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
domain
);
String
jsonString
=
mapper
.
writeValueAsString
(
domain
);
when
(
domainService
.
update
(
any
())).
thenReturn
(
domain
);
when
(
domainService
.
isDomainExists
(
anyObject
()))
mockMvc
.
perform
(
put
(
"/domains"
)
.
thenReturn
(
true
);
when
(
domainService
.
update
(
any
())).
thenReturn
(
domainPeristed
);
mockMvc
.
perform
(
put
(
"/domains"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)
.
content
(
jsonString
))
.
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
domainService
).
update
(
any
());
//verify(domainService).update(any());
}
@Test
public
void
testgetDomains
()
throws
Exception
{
//List<HashMap<Object,Object>> domains = CreateDomainDetails();
List
domains
=
CreateDomainDetails
();
when
(
domainService
.
getDomainsList
()).
thenReturn
(
domains
);
mockMvc
.
perform
(
get
(
"/domains"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
domainService
).
getDomainsList
();
}
@Test
public
void
testgetDomainsUnderAccount
()
throws
Exception
{
/*
List domains = CreateDomainDetails();
when(domainService.getDomainsList()).thenReturn(domains);
mockMvc.perform(get("/domains/{accountId}")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(domainService).getDomainsList(); */
mockMvc
.
perform
(
get
(
"/domains/ACC001"
).
param
(
"domainId"
,
"ACC001"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
domainService
).
getDomainsUnderAccount
(
"ACC001"
);
}
}
@Test
@Test
public
void
testdeleteDomain
()
throws
Exception
{
public
void
testdeleteDomain
()
throws
Exception
{
mockMvc
.
perform
(
mockMvc
.
perform
(
delete
(
"/domains/DOM005"
).
param
(
"domainId"
,
"DOM005"
))
delete
(
"/domains"
).
param
(
"domainId"
,
"DOM001"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
domainService
).
delete
(
"DOM00
1"
);
verify
(
domainService
).
delete
(
"DOM00
5"
);
}
}
...
@@ -111,7 +181,7 @@ public class DomainControllerTest {
...
@@ -111,7 +181,7 @@ public class DomainControllerTest {
HashMap
<
Object
,
Object
>
map2
=
new
HashMap
<
Object
,
Object
>();
HashMap
<
Object
,
Object
>
map2
=
new
HashMap
<
Object
,
Object
>();
Domain
data1
=
new
Domain
();
Domain
data1
=
new
Domain
();
//
data1.setId(new ObjectId("5976ef15874c902c98b8a05d"));
data1
.
setId
(
new
ObjectId
(
"5976ef15874c902c98b8a05d"
));
data1
.
setDomainId
(
"DOM003"
);
data1
.
setDomainId
(
"DOM003"
);
data1
.
setDomainName
(
"MOC"
);
data1
.
setDomainName
(
"MOC"
);
data1
.
setAccountId
(
"ACC001"
);
data1
.
setAccountId
(
"ACC001"
);
...
@@ -126,8 +196,8 @@ public class DomainControllerTest {
...
@@ -126,8 +196,8 @@ public class DomainControllerTest {
Domain
data2
=
new
Domain
();
Domain
data2
=
new
Domain
();
//
data2.setId(new ObjectId("9976ef15874c902c98b8a05d"));
data2
.
setId
(
new
ObjectId
(
"9976ef15874c902c98b8a05d"
));
data2
.
setDomainId
(
"DOM00
4
"
);
data2
.
setDomainId
(
"DOM00
5
"
);
data2
.
setDomainName
(
"BIGTICKET"
);
data2
.
setDomainName
(
"BIGTICKET"
);
data2
.
setAccountId
(
"ACC001"
);
data2
.
setAccountId
(
"ACC001"
);
data2
.
setStatus
(
"Active"
);
data2
.
setStatus
(
"Active"
);
...
...
src/test/java/com/nisum/myteam/controllertest/EmailControllerTest.java
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verifyNoMoreInteractions
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.InjectMocks
;
...
@@ -39,10 +43,11 @@ public class EmailControllerTest {
...
@@ -39,10 +43,11 @@ public class EmailControllerTest {
public
void
testsendAttachmentMail_success
()
throws
Exception
{
public
void
testsendAttachmentMail_success
()
throws
Exception
{
EmailDomain
emailObj
=
new
EmailDomain
(
"12345"
,
"2017-11-18"
,
"2017-12-18"
,
EmailDomain
emailObj
=
new
EmailDomain
(
"12345"
,
"2017-11-18"
,
"2017-12-18"
,
new
String
[]{
"to@nisum.com"
},
new
String
[]{
"cc@nisum.com"
},
new
String
[]{});
new
String
[]{
"to@nisum.com"
},
new
String
[]{
"cc@nisum.com"
},
new
String
[]{});
ObjectMapper
mapper
=
new
ObjectMapper
();
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
emailObj
);
String
jsonString
=
mapper
.
writeValueAsString
(
emailObj
);
when
(
mailService
.
sendEmailWithAttachment
(
any
())).
thenReturn
(
"Success"
);
when
(
mailService
.
sendEmailWithAttachment
(
any
())).
thenReturn
(
"Success"
);
mockMvc
.
perform
(
post
(
"/sendEmail"
).
contentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
).
content
(
jsonString
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
mockMvc
.
perform
(
post
(
"/sendEmail"
).
contentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
.
content
(
jsonString
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
}
@Test
@Test
...
@@ -55,13 +60,13 @@ public class EmailControllerTest {
...
@@ -55,13 +60,13 @@ public class EmailControllerTest {
when
(
mailService
.
sendEmailWithAttachment
(
any
())).
thenReturn
(
"Failure"
);
when
(
mailService
.
sendEmailWithAttachment
(
any
())).
thenReturn
(
"Failure"
);
mockMvc
.
perform
(
post
(
"/sendEmail"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
is4xxClientError
());
mockMvc
.
perform
(
post
(
"/sendEmail"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
is4xxClientError
());
}
}
/* @Test
@Test
public void testdeletePdfReport() throws Exception{
public void testdeletePdfReport() throws Exception{
when(mailService.deletePdfReport("eTimeTrackLite1")).thenReturn("Success");
when(mailService.deletePdfReport("eTimeTrackLite1")).thenReturn("Success");
mockMvc.perform(get("/deleteReport/eTimeTrackLite1")).andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(get("/deleteReport/eTimeTrackLite1")).andExpect(MockMvcResultMatchers.status().isOk());
verify(mailService).deletePdfReport("eTimeTrackLite1");
verify(mailService).deletePdfReport("eTimeTrackLite1");
}
}
*/
}
}
src/test/java/com/nisum/myteam/controllertest/EmployeeControllerTest.java
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
mockito
.
Matchers
.
anyObject
;
import
static
org
.
mockito
.
Mockito
.
atLeastOnce
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
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
.
delete
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
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
.
request
.
MockMvcRequestBuilders
.
put
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
jsonPath
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
org.bson.types.ObjectId
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.InjectMocks
;
...
@@ -29,53 +21,21 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
...
@@ -29,53 +21,21 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.nisum.myteam.controller.EmployeeController
;
import
com.nisum.myteam.controller.EmployeeController
;
import
com.nisum.myteam.model.dao.Account
;
import
com.nisum.myteam.model.dao.Designation
;
import
com.nisum.myteam.model.dao.Domain
;
import
com.nisum.myteam.model.dao.Employee
;
import
com.nisum.myteam.model.dao.Employee
;
import
com.nisum.myteam.model.dao.EmployeeLocation
;
import
com.nisum.myteam.model.dao.MasterData
;
import
com.nisum.myteam.model.dao.OrgLocation
;
import
com.nisum.myteam.model.dao.Shift
;
import
com.nisum.myteam.model.dao.Skill
;
import
com.nisum.myteam.service.IEmployeeRoleService
;
import
com.nisum.myteam.service.IEmployeeRoleService
;
import
com.nisum.myteam.service.IEmployeeService
;
import
com.nisum.myteam.service.IEmployeeService
;
import
com.nisum.myteam.service.impl.DesignationService
;
import
com.nisum.myteam.service.impl.EmployeeLocationService
;
import
com.nisum.myteam.service.impl.MasterDataService
;
import
com.nisum.myteam.service.impl.OrgLocationService
;
import
com.nisum.myteam.service.impl.ShiftService
;
import
com.nisum.myteam.service.impl.SkillService
;
public
class
EmployeeControllerTest
{
public
class
EmployeeControllerTest
{
@Mock
@Mock
IEmployeeService
employee
Service
;
private
IEmployeeService
emp
Service
;
@Mock
@Mock
IEmployeeRoleService
roleMapping
Service
;
private
IEmployeeRoleService
employeeRole
Service
;
@InjectMocks
@InjectMocks
EmployeeController
employeeController
;
EmployeeController
employeeController
;
@InjectMocks
EmployeeLocationService
empLocationService
;
@InjectMocks
ShiftService
shiftService
;
@InjectMocks
DesignationService
designationService
;
@InjectMocks
SkillService
skillService
;
@InjectMocks
OrgLocationService
orgLocationService
;
@InjectMocks
MasterDataService
masterDataService
;
private
MockMvc
mockMvc
;
private
MockMvc
mockMvc
;
@Before
@Before
...
@@ -83,475 +43,163 @@ public class EmployeeControllerTest {
...
@@ -83,475 +43,163 @@ public class EmployeeControllerTest {
MockitoAnnotations
.
initMocks
(
this
);
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
employeeController
).
build
();
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
employeeController
).
build
();
}
}
@Test
@Test
public
void
testgetEmployeeRoleAsAdmin
()
throws
Exception
{
public
void
testCreateEmployee
()
throws
Exception
{
Employee
employeesRole
=
new
Employee
(
"5b307d7e708ef705c4ca64d8"
,
"16694"
,
"Mahesh Deekonda"
,
Employee
employeePersisted
=
new
Employee
();
"mdeekonda@nisum.com"
,
"Admin"
,
"Senior software engineer"
,
null
,
null
,
"Support"
,
"Hyderabad"
,
null
,
Employee
employeeReq
=
new
Employee
();
null
,
null
,
null
,
"ACI - Support"
,
"Active"
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2107
-
12
-
23
),
ObjectMapper
mapper
=
new
ObjectMapper
();
"Male"
,
null
,
new
Date
(
2020
-
01
-
01
),
null
,
new
Date
(
2018
-
01
-
01
),
new
Date
(
2018
-
02
-
15
),
String
jsonString
=
mapper
.
writeValueAsString
(
employeeReq
);
new
Date
(
2018
-
02
-
15
),
null
,
"Mahesh"
,
"Mahesh"
);
when
(
empService
.
createEmployee
(
employeeReq
,
"16253"
)).
thenReturn
(
employeePersisted
);
;
mockMvc
.
perform
(
post
(
"/employees/{empId}"
,
"16253"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
when
(
employeeService
.
getEmployeeByEmaillId
(
"mdeekonda@nisum.com"
)).
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/user/employee"
).
param
(
"emailId"
,
"mdeekonda@nisum.com"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
employeeService
).
getEmployeeByEmaillId
(
"mdeekonda@nisum.com"
);
}
}
@Test
@Test
public
void
testgetEmployeeRoleAsEmp
()
throws
Exception
{
public
void
testCreateEmployeeExistsById
()
throws
Exception
{
Employee
employeesRole
=
new
Employee
(
"5b307d7e708ef705c4ca64d8"
,
"16694"
,
"Mahesh Deekonda"
,
Employee
employeePersisted
=
new
Employee
();
"mdeekonda@nisum.com"
,
"Employee"
,
"Senior software engineer"
,
null
,
null
,
"Support"
,
"Hyderabad"
,
null
,
Employee
employeeReq
=
new
Employee
();
null
,
null
,
null
,
"ACI - Support"
,
"Active"
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2107
-
12
-
23
),
ObjectMapper
mapper
=
new
ObjectMapper
();
"Male"
,
null
,
new
Date
(
2020
-
01
-
01
),
null
,
new
Date
(
2018
-
01
-
01
),
new
Date
(
2018
-
02
-
15
),
String
jsonString
=
mapper
.
writeValueAsString
(
employeeReq
);
new
Date
(
2018
-
02
-
15
),
null
,
"Mahesh"
,
"Mahesh"
);
when
(
empService
.
isEmployeeExistsById
(
"16253"
)).
thenReturn
(
true
);
when
(
employeeService
.
getEmployeeByEmaillId
(
"mdeekonda@nisum.com"
)).
thenReturn
(
employeesRole
);
when
(
empService
.
createEmployee
(
employeeReq
,
"16253"
)).
thenReturn
(
employeePersisted
);
when
(
roleMappingService
.
getEmployeeRole
(
employeesRole
.
getEmployeeId
())).
thenReturn
(
"Delivery Lead"
);
mockMvc
.
perform
(
post
(
"/employees/{empId}"
,
"16253"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
mockMvc
.
perform
(
get
(
"/user/employee"
).
param
(
"emailId"
,
"mdeekonda@nisum.com"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
employeeService
).
getEmployeeByEmaillId
(
"mdeekonda@nisum.com"
);
verify
(
roleMappingService
).
getEmployeeRole
(
"16694"
);
}
}
@Test
@Test
public
void
testassigingEmployeeRole
()
throws
Exception
{
public
void
testUpdateEmployee
()
throws
Exception
{
Employee
employeeRole
=
new
Employee
(
"5976ef15874c902c98b8a05d"
,
null
,
null
,
null
,
null
,
null
,
null
,
Employee
employeePersisted
=
new
Employee
();
null
,
null
,
null
,
null
,
null
,
null
,
"user@nisum.com"
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
20
),
Employee
employeeReq
=
new
Employee
();
new
Date
(
2107
-
12
-
23
),
null
,
null
,
null
,
null
,
new
Date
(
2020
-
01
-
01
),
new
Date
(
2018
-
01
-
01
),
new
Date
(
2018
-
02
-
15
),
new
Date
(
2018
-
02
-
15
),
"Mahesh"
,
"Mahesh"
);
ObjectMapper
mapper
=
new
ObjectMapper
();
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeeRole
);
String
jsonString
=
mapper
.
writeValueAsString
(
employeeReq
);
when
(
employeeService
.
createEmployee
(
anyObject
(),
anyObject
())).
thenReturn
(
employeeRole
);
when
(
empService
.
updateEmployee
(
employeeReq
,
"16253"
)).
thenReturn
(
employeePersisted
);
mockMvc
.
perform
(
post
(
"/user/assignEmployeeRole"
).
param
(
"empId"
,
"16999"
)
mockMvc
.
perform
(
put
(
"/employees/{empId}"
,
"16253"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
employeeService
).
createEmployee
(
anyObject
(),
anyObject
());
}
}
@Test
@Test
public
void
testupdateEmployeeRole
()
throws
Exception
{
public
void
testUpdateEmployeeExistsById
()
throws
Exception
{
Employee
employeeRole2
=
new
Employee
(
"5976ef15874c902c98b8a05d"
,
null
,
null
,
null
,
null
,
null
,
null
,
Employee
employeePersisted
=
new
Employee
();
null
,
null
,
null
,
null
,
null
,
null
,
"user@nisum.com"
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
20
),
Employee
employeeReq
=
new
Employee
();
new
Date
(
2107
-
12
-
23
),
null
,
null
,
null
,
null
,
new
Date
(
2020
-
01
-
01
),
new
Date
(
2018
-
01
-
01
),
new
Date
(
2018
-
02
-
15
),
new
Date
(
2018
-
02
-
15
),
"Mahesh"
,
"Mahesh"
);
ObjectMapper
mapper
=
new
ObjectMapper
();
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeeR
ole2
);
String
jsonString
=
mapper
.
writeValueAsString
(
employeeR
eq
);
when
(
emp
loyeeService
.
updateEmployee
(
anyObject
(),
anyObject
())).
thenReturn
(
employeeRole2
);
when
(
emp
Service
.
isEmployeeExistsById
(
"16253"
)).
thenReturn
(
true
);
mockMvc
.
perform
(
post
(
"/user/updateEmployeeRole"
).
param
(
"empId"
,
"16999"
)
when
(
empService
.
updateEmployee
(
employeeReq
,
"16253"
)).
thenReturn
(
employeePersisted
);
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
mockMvc
.
perform
(
put
(
"/employees/{empId}"
,
"16253"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
employeeService
).
updateEmployee
(
anyObject
(),
anyObject
());
}
}
@Test
@Test
public
void
testdeleteEmployee
()
throws
Exception
{
public
void
testDeleteEmployee
()
throws
Exception
{
mockMvc
.
perform
(
delete
(
"/user/deleteEmployee"
).
param
(
"empId"
,
"16127"
))
Employee
employeePersisted
=
new
Employee
();
Employee
employeeReq
=
new
Employee
();
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeeReq
);
when
(
empService
.
deleteEmployee
(
"16253"
)).
thenReturn
(
employeePersisted
);
mockMvc
.
perform
(
delete
(
"/employees/{empId}"
,
"16253"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
employeeService
).
deleteEmployee
(
"16127"
);
}
}
@Test
@Test
public
void
testgetUserRoles
()
throws
Exception
{
public
void
testDeleteEmployeeExistsById
()
throws
Exception
{
List
<
Employee
>
employeesRole3
=
CreateUserRoles
();
Employee
employeePersisted
=
new
Employee
();
when
(
employeeService
.
getActiveEmployees
()).
thenReturn
(
employeesRole3
);
Employee
employeeReq
=
new
Employee
();
mockMvc
.
perform
(
get
(
"/user/getUserRoles"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeeReq
);
when
(
empService
.
isEmployeeExistsById
(
"16253"
)).
thenReturn
(
true
);
when
(
empService
.
deleteEmployee
(
"16253"
)).
thenReturn
(
employeePersisted
);
mockMvc
.
perform
(
delete
(
"/employees/{empId}"
,
"16253"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
employeeService
).
getActiveEmployees
();
}
@Test
public
void
testgetEmployeeRoleData
()
throws
Exception
{
Employee
employeesRole
=
new
Employee
(
"5b307d7e708ef705c4ca64d8"
,
"16694"
,
"Mahesh Deekonda"
,
"mdeekonda@nisum.com"
,
"Admin"
,
"Senior software engineer"
,
null
,
null
,
"Support"
,
"Hyderabad"
,
null
,
null
,
null
,
null
,
"ACI - Support"
,
"Active"
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2107
-
12
-
23
),
"Male"
,
null
,
new
Date
(
2020
-
01
-
01
),
null
,
new
Date
(
2018
-
01
-
01
),
new
Date
(
2018
-
02
-
15
),
new
Date
(
2018
-
02
-
15
),
null
,
"Mahesh"
,
"Mahesh"
);
when
(
employeeService
.
getEmployeeById
(
"16694"
)).
thenReturn
(
employeesRole
);
mockMvc
.
perform
(
get
(
"/user/getEmployeeRoleData"
).
param
(
"empId"
,
"16694"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
()).
andExpect
(
jsonPath
(
"$.employeeId"
,
is
(
"16694"
)))
.
andDo
(
print
());
verify
(
employeeService
).
getEmployeeById
(
"16694"
);
}
@Test
public
void
testgetEmployeeLocations
()
throws
Exception
{
List
<
EmployeeLocation
>
empLocList
=
new
ArrayList
<
EmployeeLocation
>();
EmployeeLocation
empLocation
=
new
EmployeeLocation
(
new
ObjectId
(
"5b307d7d708ef705c4ca59c4"
),
"16090"
,
"Dharmendra Kumar Jampana"
,
"Hyderabad"
,
new
Date
(
2020
-
01
-
01
),
new
Date
(
2018
-
01
-
01
),
new
Date
(
2018
-
02
-
15
),
new
Date
(
2018
-
02
-
15
),
true
);
empLocList
.
add
(
empLocation
);
when
(
empLocationService
.
getEmployeeLocations
(
"16090"
)).
thenReturn
(
empLocList
);
mockMvc
.
perform
(
get
(
"/user/getEmployeeLocations"
).
param
(
"employeeId"
,
"16090"
)
.
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
empLocationService
).
getEmployeeLocations
(
"16090"
);
}
}
@Test
public
void
testgetEmployeeRoleDataForEmailIdSearch
()
throws
Exception
{
Employee
employeesRole
=
new
Employee
(
"5b307d7d708ef705c4ca5c90"
,
"16209"
,
"Mahesh Kumar Gutam"
,
"dummy@nisum.com"
,
"Employee"
,
"Software Engineer"
,
null
,
null
,
"Sell"
,
"Hyderabad"
,
null
,
null
,
null
,
null
,
"APPS"
,
"Active"
,
"Full Time"
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2107
-
12
-
23
),
"Male"
,
null
,
null
,
null
,
new
Date
(
2020
-
01
-
01
),
new
Date
(
2018
-
01
-
01
),
new
Date
(
2018
-
02
-
15
),
new
Date
(
2018
-
02
-
15
),
"Mahesh"
,
"Mahesh"
);
when
(
employeeService
.
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
(
employeeService
).
getEmployeeRoleDataForSearchCriteria
(
"dummy@nisum.com"
,
"emailId"
);
}
@Test
public
void
testgetEmployeeRoleDataForEmployeeNameSearch
()
throws
Exception
{
Employee
employeesRole
=
new
Employee
(
"5b307d7d708ef705c4ca5c90"
,
"16209"
,
"Mahesh Kumar Gutam"
,
"dummy@nisum.com"
,
"Employee"
,
"Software Engineer"
,
null
,
null
,
"Sell"
,
"Hyderabad"
,
null
,
null
,
null
,
null
,
"APPS"
,
"Active"
,
"Full Time"
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2107
-
12
-
23
),
"Male"
,
null
,
null
,
null
,
new
Date
(
2020
-
01
-
01
),
new
Date
(
2018
-
01
-
01
),
new
Date
(
2018
-
02
-
15
),
new
Date
(
2018
-
02
-
15
),
"Mahesh"
,
"Mahesh"
);
when
(
employeeService
.
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
(
employeeService
).
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
(
employeeService
.
getEmployeeDetailsForAutocomplete
()).
thenReturn
(
details
);
mockMvc
.
perform
(
get
(
"/user/getEmployeeDetailsForAutocomplete"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
()).
andDo
(
print
());
verify
(
employeeService
).
getEmployeeDetailsForAutocomplete
();
}
@Test
@Test
public
void
testgetManagers
()
throws
Exception
{
public
void
testUpdateProfile
()
throws
Exception
{
List
<
Employee
>
employeesRole4
=
CreateUserRoles
();
Employee
employeePersisted
=
new
Employee
();
System
.
out
.
println
(
employeesRole4
);
Employee
employeeReq
=
new
Employee
();
when
(
employeeService
.
getActiveEmployees
()).
thenReturn
(
employeesRole4
);
ObjectMapper
mapper
=
new
ObjectMapper
();
mockMvc
.
perform
(
get
(
"/user/getManagers"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
String
jsonString
=
mapper
.
writeValueAsString
(
employeeReq
);
verify
(
employeeService
).
getActiveEmployees
();
when
(
empService
.
updateProfile
(
employeeReq
)).
thenReturn
(
employeePersisted
);
mockMvc
.
perform
(
post
(
"/employees/updateProfile"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
}
@Test
@Test
public
void
testgetAllShifts
()
throws
Exception
{
public
void
testGetEmployeeById
()
throws
Exception
{
List
<
Shift
>
shifts
=
CreateShifts
();
Employee
employeePersisted
=
new
Employee
();
when
(
shiftService
.
getAllShifts
()).
thenReturn
(
shifts
);
Employee
employeeReq
=
new
Employee
();
mockMvc
.
perform
(
get
(
"/user/getAllShifts"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
ObjectMapper
mapper
=
new
ObjectMapper
();
verify
(
shiftService
).
getAllShifts
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeeReq
);
when
(
empService
.
getEmployeeById
(
""
)).
thenReturn
(
employeePersisted
);
mockMvc
.
perform
(
get
(
"/employees/employeeId/{empId}"
,
"16253"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
}
@Test
@Test
public
void
testgetAllDesignations
()
throws
Exception
{
public
void
testGetEmployee
()
throws
Exception
{
List
<
Designation
>
designation
=
CreateDesignations
();
Employee
employeePersisted
=
new
Employee
();
when
(
designationService
.
getAllDesignations
()).
thenReturn
(
designation
);
// Employee employeeReq = new Employee();
mockMvc
.
perform
(
get
(
"/user/getAllDesignations"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
Employee
employee
=
null
;
verify
(
designationService
).
getAllDesignations
();
when
(
empService
.
getEmployeeByEmaillId
(
"s@nisum.com"
)).
thenReturn
(
employee
);
mockMvc
.
perform
(
get
(
"/employees/emailId"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
}
@Test
@Test
public
void
test
getTechnologie
s
()
throws
Exception
{
public
void
test
GetManager
s
()
throws
Exception
{
List
<
Skill
>
skills
=
CreateSkill
();
System
.
out
.
println
(
skills
);
mockMvc
.
perform
(
get
(
"/employees/managers/"
).
param
(
"domainId"
,
"ACC001"
))
when
(
skillService
.
getTechnologies
()).
thenReturn
(
skills
);
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
()
);
mockMvc
.
perform
(
get
(
"/user/getSkills"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
empService
).
getManagers
();
verify
(
skillService
).
getTechnologies
();
}
}
@Test
@Test
public
void
testgetLocations
()
throws
Exception
{
public
void
testGetActiveEmployees
()
throws
Exception
{
when
(
orgLocationService
.
getLocations
()).
thenReturn
(
locations
());
mockMvc
.
perform
(
get
(
"/user/getLocations"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
mockMvc
.
perform
(
get
(
"/employees/active"
).
param
(
"domainId"
,
"ACC001"
))
verify
(
orgLocationService
,
atLeastOnce
()).
getLocations
();
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
empService
).
getActiveEmployees
();
}
}
@Test
@Test
public
void
testupdateProfile
()
throws
Exception
{
public
void
testGetAccounts
()
throws
Exception
{
Employee
employeeRole
=
new
Employee
(
"5976ef15874c902c98b8a05d"
,
null
,
null
,
null
,
null
,
null
,
null
,
mockMvc
.
perform
(
get
(
"/employees/accounts/"
).
param
(
"domainId"
,
"ACC001"
))
null
,
null
,
null
,
null
,
null
,
null
,
"user@nisum.com"
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2107
-
12
-
23
),
null
,
null
,
null
,
null
,
new
Date
(
2020
-
01
-
01
),
new
Date
(
2018
-
01
-
01
),
new
Date
(
2018
-
02
-
15
),
new
Date
(
2018
-
02
-
15
),
"Mahesh"
,
"Mahesh"
);
System
.
out
.
println
(
employeeRole
);
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeeRole
);
System
.
out
.
println
(
jsonString
);
when
(
employeeService
.
updateProfile
(
anyObject
())).
thenReturn
(
employeeRole
);
mockMvc
.
perform
(
post
(
"/user/updateProfile"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
employeeService
).
updateProfile
(
anyObject
());
verify
(
empService
).
getAccounts
();
}
@Test
public
void
getAccounts
()
throws
Exception
{
List
<
Account
>
account
=
CreateAccount
();
System
.
out
.
println
(
account
);
when
(
employeeService
.
getAccounts
()).
thenReturn
(
account
);
mockMvc
.
perform
(
get
(
"/user/getAccounts"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
employeeService
).
getAccounts
();
}
}
@Test
public
void
testGetMasterData
()
throws
Exception
{
List
<
MasterData
>
masterDataMap
=
masterData
();
when
(
masterDataService
.
getMasterData
()).
thenReturn
(
masterDataMap
);
mockMvc
.
perform
(
get
(
"/user/getMasterData"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
masterDataService
).
getMasterData
();
}
@Test
@Test
public
void
testGetEmployeeByStatus
()
throws
Exception
{
public
void
testGetEmployeeByStatus
()
throws
Exception
{
List
<
Employee
>
empRolesList
=
employeeRoles
();
List
<
Employee
>
employeeList
=
null
;
when
(
employeeService
.
getEmployeesByStatus
(
"Active"
)).
thenReturn
(
empRolesList
);
ObjectMapper
mapper
=
new
ObjectMapper
();
mockMvc
.
perform
(
get
(
"/user/getEmployeeByStatus"
).
param
(
"status"
,
"Active"
))
String
jsonString
=
mapper
.
writeValueAsString
(
employeeList
);
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
when
(
empService
.
getEmployeesByStatus
(
"all"
)).
thenReturn
(
employeeList
);
verify
(
employeeService
).
getEmployeesByStatus
(
"Active"
);
mockMvc
.
perform
(
get
(
"/employees/"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
// verify(empService).getEmployeesByStatus("");
}
}
// @Test
// public void testgetdomains() throws Exception {
//
// when(employeeService.getDomains("Acc001")).thenReturn(domains());
// mockMvc.perform(get("/user/getDomains").param("accountId", "Acc001"))
// .andExpect(MockMvcResultMatchers.status().isOk());
// verify(employeeService).getDomains("Acc001");
//
// }
@Test
@Test
public
void
testgetDeliveryLeads
()
throws
Exception
{
public
void
testGetEmployeeRoleDataForSearchCriteria
()
throws
Exception
{
mockMvc
.
perform
(
get
(
"/employee/searchCriteria"
).
param
(
"domainId"
,
"ACC001"
))
HashMap
<
String
,
String
>
dl1
=
new
HashMap
<
String
,
String
>();
dl1
.
put
(
"employeeName"
,
"Madhuri Bayyagari"
);
dl1
.
put
(
"employeeId"
,
"16620"
);
HashMap
<
String
,
String
>
dl2
=
new
HashMap
<
String
,
String
>();
dl2
.
put
(
"employeeName"
,
"Sridhar Swamy Perumbaduri"
);
dl2
.
put
(
"employeeId"
,
"16630"
);
List
<
HashMap
<
String
,
String
>>
dlList
=
new
ArrayList
<
HashMap
<
String
,
String
>>();
dlList
.
add
(
dl1
);
dlList
.
add
(
dl2
);
when
(
employeeService
.
getDeliveryLeads
(
"DOM001"
)).
thenReturn
(
dlList
);
mockMvc
.
perform
(
get
(
"/user/getDeliveryLeads"
).
param
(
"domainId"
,
"DOM001"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
employeeService
).
getDeliveryLeads
(
"DOM001"
);
verify
(
empService
).
getEmployeeRoleDataForSearchCriteria
(
""
,
""
);
}
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
<
Employee
>
CreateUserRoles
()
{
List
<
Employee
>
data
=
new
ArrayList
<>();
Employee
data1
=
new
Employee
();
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
));
Employee
data2
=
new
Employee
();
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
;
}
private
List
<
MasterData
>
masterData
()
{
List
<
MasterData
>
masterDataList
=
new
ArrayList
<
MasterData
>();
MasterData
md1
=
new
MasterData
();
md1
.
setActiveStatus
(
true
);
md1
.
setId
(
new
ObjectId
(
"5af31b08ed59fba43518ed84"
));
md1
.
setMasterDataId
(
"1"
);
md1
.
setMasterDataName
(
"Java"
);
md1
.
setMasterDataType
(
"skills"
);
md1
.
setComments
(
null
);
MasterData
md2
=
new
MasterData
();
md2
.
setActiveStatus
(
true
);
md2
.
setId
(
new
ObjectId
(
"5af32e8fed59fba43518ed88"
));
md2
.
setMasterDataId
(
"1"
);
md2
.
setMasterDataName
(
"Full Time"
);
md2
.
setMasterDataType
(
"EmpType"
);
md2
.
setComments
(
null
);
masterDataList
.
add
(
md1
);
masterDataList
.
add
(
md2
);
return
masterDataList
;
}
private
List
<
Employee
>
employeeRoles
()
{
List
<
Employee
>
employeeRoles
=
new
ArrayList
<
Employee
>();
Employee
employeesRole1
=
new
Employee
(
"5b307d7d708ef705c4ca5c90"
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
"dummy@nisum.com"
,
null
,
null
,
null
,
new
Date
(
2017
-
11
-
20
),
new
Date
(
2107
-
12
-
23
),
null
,
null
,
null
,
null
,
new
Date
(
2020
-
01
-
01
),
new
Date
(
2018
-
01
-
01
),
new
Date
(
2018
-
02
-
15
),
new
Date
(
2018
-
02
-
15
),
"Mahesh"
,
"Mahesh"
);
Employee
employeesRole2
=
new
Employee
(
"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
),
null
,
null
,
null
,
null
,
new
Date
(
2020
-
01
-
01
),
new
Date
(
2018
-
01
-
01
),
new
Date
(
2018
-
02
-
15
),
new
Date
(
2018
-
02
-
15
),
"Mahesh"
,
"Mahesh"
);
employeeRoles
.
add
(
employeesRole1
);
employeeRoles
.
add
(
employeesRole2
);
return
employeeRoles
;
}
private
List
<
OrgLocation
>
locations
()
{
List
<
OrgLocation
>
empLocation
=
new
ArrayList
<
OrgLocation
>();
OrgLocation
l1
=
new
OrgLocation
(
new
ObjectId
(
"5b307c9c927173017882543b"
),
"IN_HYD"
,
"Hyderabad Appstek Building"
,
"India"
,
"Telangana"
,
"Hyderabad"
,
true
,
"testing"
);
OrgLocation
l2
=
new
OrgLocation
(
new
ObjectId
(
"5b307c9c927173017882543a"
),
"NY_SF"
,
"Pleasonton Gap Office"
,
"USA"
,
"CA"
,
"SanFransisco"
,
true
,
"testing"
);
empLocation
.
add
(
l1
);
empLocation
.
add
(
l2
);
return
empLocation
;
}
private
List
<
Domain
>
domains
()
{
List
<
String
>
dl1
=
new
ArrayList
<
String
>();
dl1
.
add
(
"16120"
);
dl1
.
add
(
"16121"
);
List
<
String
>
dl2
=
new
ArrayList
<
String
>();
dl2
.
add
(
"16122"
);
dl2
.
add
(
"16123"
);
List
<
Domain
>
domains
=
new
ArrayList
<
Domain
>();
Domain
d1
=
new
Domain
(
"DOM001"
,
"Customer"
,
"Acc001"
,
"Active"
,
dl1
);
Domain
d2
=
new
Domain
(
"DOM005"
,
"rajesh"
,
"Acc001"
,
"Active"
,
dl2
);
domains
.
add
(
d1
);
domains
.
add
(
d2
);
return
domains
;
}
}
}
src/test/java/com/nisum/myteam/controllertest/EmployeeEffortsControllerTest.java
0 → 100644
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultHandlers
.
print
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
com.nisum.myteam.controller.EmployeeEffortsController
;
import
com.nisum.myteam.model.EmployeeEfforts
;
import
com.nisum.myteam.service.IEmployeeEffortsService
;
public
class
EmployeeEffortsControllerTest
{
@Mock
IEmployeeEffortsService
employeeEffortService
;
@InjectMocks
EmployeeEffortsController
employeeEffortsController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
employeeEffortsController
).
build
();
}
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testemployeeLoginsBasedOnDateEfforts
()
throws
Exception
{
List
<
EmployeeEfforts
>
employeeEffortsList
=
createLoginData
();
when
(
employeeEffortService
.
getEmployeeEffortsReport
(
"2017-11-18"
,
"2017-12-18"
)).
thenReturn
(
employeeEffortsList
);
//when(employeeEffortService.getEmployeeEffortsReport("2017-11-19", "2017-12-19")).thenThrow(Exception.class);
mockMvc
.
perform
(
get
(
"/employeeEfforts/getWeeklyReport"
).
param
(
"fromDate"
,
"2017-11-18"
)
.
param
(
"toDate"
,
"2017-12-18"
)).
andDo
(
print
()).
andExpect
(
status
().
isOk
());
verify
(
employeeEffortService
).
getEmployeeEffortsReport
(
"2017-11-18"
,
"2017-12-18"
);
}
/* @SuppressWarnings("unchecked")
@Test
public void testemployeeLoginsBasedOnDateEffortsNegative() throws Exception {
List<EmployeeEfforts> employeeEffortsList = createLoginData();
when(employeeEffortService.getEmployeeEffortsReport(null, "2017-12-18")).thenThrow(new Exception());
// doThrow(new Exception()).when(employeeEffortService.getEmployeeEffortsReport("", "2017-12-19"));
//when(employeeEffortService.getEmployeeEffortsReport("", "2017-12-19")).thenThrow(Exception.class);
mockMvc.perform(get("/employeeEfforts/getWeeklyReport").param("fromDate", "")
.param("toDate", "2017-12-18")).andExpect(status().isOk());
//verify(employeeEffortService).getEmployeeEffortsReport("", "2017-12-18");
}
*/
private
List
<
EmployeeEfforts
>
createLoginData
()
{
List
<
EmployeeEfforts
>
data
=
new
ArrayList
<>();
EmployeeEfforts
data1
=
new
EmployeeEfforts
();
data1
.
setId
(
"5976ef15874c902c98b8a05b"
);
data1
.
setEmployeeId
(
"12345"
);
data1
.
setEmployeeName
(
"Xyz"
);
data1
.
setTotalHoursSpentInWeek
(
"55"
);
data1
.
setProjectName
(
"Macys"
);
data1
.
setAccountName
(
"Nisum"
);
data1
.
setFunctionalOrg
(
"Customer"
);
EmployeeEfforts
data2
=
new
EmployeeEfforts
();
data2
.
setId
(
"5976ef15874c902c98b8a05c"
);
data2
.
setEmployeeId
(
"01234"
);
data2
.
setEmployeeName
(
"Abc"
);
data2
.
setTotalHoursSpentInWeek
(
"55"
);
data2
.
setProjectName
(
"Macys"
);
data2
.
setAccountName
(
"Nisum"
);
data2
.
setFunctionalOrg
(
"Customer"
);
data
.
add
(
data1
);
data
.
add
(
data2
);
return
data
;
}
}
src/test/java/com/nisum/myteam/controllertest/EmployeeLocationControllerTest.java
0 → 100644
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
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.nisum.myteam.controller.EmployeeLocationController
;
import
com.nisum.myteam.model.dao.EmployeeLocation
;
import
com.nisum.myteam.service.IEmployeeLocationService
;
public
class
EmployeeLocationControllerTest
{
@Mock
IEmployeeLocationService
empLocationService
;
@InjectMocks
EmployeeLocationController
employeeLocationController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
employeeLocationController
).
build
();
}
@Test
public
void
testgetEmployeeLocations
()
throws
Exception
{
List
<
EmployeeLocation
>
employeeLocationDetails
=
createEmplyeeLocationData
();
when
(
empLocationService
.
getEmployeeLocations
(
"16127"
)).
thenReturn
(
employeeLocationDetails
);
mockMvc
.
perform
(
get
(
"/employees/locations/16127"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
empLocationService
).
getEmployeeLocations
(
"16127"
);
}
private
List
<
EmployeeLocation
>
createEmplyeeLocationData
()
{
List
<
EmployeeLocation
>
data
=
new
ArrayList
<>();
EmployeeLocation
record1
=
new
EmployeeLocation
();
record1
.
setEmployeeId
(
"16127"
);
record1
.
setEmployeeName
(
"Monika Srivastava"
);
EmployeeLocation
record2
=
new
EmployeeLocation
();
record2
.
setEmployeeId
(
"16157"
);
record2
.
setEmployeeName
(
"Syed Parveen"
);
data
.
add
(
record1
);
data
.
add
(
record2
);
return
data
;
}
}
src/test/java/com/nisum/myteam/controllertest/LoginReportsControllerTest.java
0 → 100644
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verifyNoMoreInteractions
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
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.nisum.myteam.controller.LoginReportsController
;
import
com.nisum.myteam.service.ILoginReportsService
;
public
class
LoginReportsControllerTest
{
@Mock
ILoginReportsService
reportsService
;
@InjectMocks
LoginReportsController
loginReportsController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
loginReportsController
).
build
();
}
/* @Test
public void testdeletePdfReport() throws Exception {
String response = "Success!!";
when(reportsService.deletePdfReport("LoginData")).thenReturn(response);
mockMvc.perform(post("/deleteReport/LoginData"))
.andExpect(MockMvcResultMatchers.status().isOk()).andExpect(null);
verify(reportsService).deletePdfReport("LoginData");
} */
@Test
public
void
testdeletePdfReport
()
throws
Exception
{
String
fileName
=
"MyTime"
;
String
response
=
"hh"
;
when
(
reportsService
.
deletePdfReport
(
fileName
))
.
thenReturn
(
response
);
mockMvc
.
perform
(
get
(
"/deleteReport/{fileName}"
,
fileName
).
contentType
(
MediaType
.
TEXT_PLAIN_VALUE
)
.
content
(
fileName
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
()).
andExpect
(
content
().
string
(
"hh"
));
verify
(
reportsService
,
times
(
1
)).
deletePdfReport
(
fileName
);
verifyNoMoreInteractions
(
reportsService
);
}
}
src/test/java/com/nisum/myteam/controllertest/MasterDataControllerTest.java
0 → 100644
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
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.nisum.myteam.controller.MasterDataController
;
import
com.nisum.myteam.service.IMasterDataService
;
public
class
MasterDataControllerTest
{
@Mock
IMasterDataService
masterDataService
;
@InjectMocks
MasterDataController
masterDataController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
masterDataController
).
build
();
}
@Test
public
void
testGetMasterData
()
throws
Exception
{
mockMvc
.
perform
(
get
(
"/getMasterData"
).
param
(
"domainId"
,
"ACC001"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
masterDataService
).
getMasterData
();
}
}
src/test/java/com/nisum/myteam/controllertest/OrgLocationControllerTest.java
0 → 100644
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
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.nisum.myteam.controller.OrgLocationController
;
import
com.nisum.myteam.service.IOrgLocationService
;
public
class
OrgLocationControllerTest
{
@Mock
IOrgLocationService
orgLocationService
;
@InjectMocks
OrgLocationController
orgLocationController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
orgLocationController
).
build
();
}
@Test
public
void
testgetDomainsUnderAccount
()
throws
Exception
{
/*
List domains = CreateDomainDetails();
when(domainService.getDomainsList()).thenReturn(domains);
mockMvc.perform(get("/domains/{accountId}")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(domainService).getDomainsList(); */
mockMvc
.
perform
(
get
(
"/organization/locations/"
).
param
(
"domainId"
,
"ACC001"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
orgLocationService
).
getLocations
();
}
}
src/test/java/com/nisum/myteam/controllertest/ProjectControllerTest.java
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
package
com
.
nisum
.
myteam
.
controllertest
;
//package com.nisum.mytime.controllertest;
//
import
static
org
.
mockito
.
Matchers
.
any
;
//import static org.mockito.Matchers.any;
import
static
org
.
mockito
.
Matchers
.
anyObject
;
//import static org.mockito.Mockito.verify;
import
static
org
.
mockito
.
Matchers
.
anyString
;
//import static org.mockito.Mockito.when;
import
static
org
.
mockito
.
Mockito
.
verify
;
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import
static
org
.
mockito
.
Mockito
.
when
;
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
delete
;
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
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
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
put
;
//import java.util.Date;
//import java.util.HashMap;
import
java.util.ArrayList
;
//import java.util.List;
import
java.util.Date
;
//
import
java.util.HashMap
;
//import org.bson.types.ObjectId;
import
java.util.List
;
//import org.junit.Before;
//import org.junit.Test;
import
org.bson.types.ObjectId
;
//import org.mockito.InjectMocks;
import
org.junit.Before
;
//import org.mockito.Mock;
import
org.junit.Test
;
//import org.mockito.MockitoAnnotations;
import
org.mockito.InjectMocks
;
//import org.springframework.http.MediaType;
import
org.mockito.Mock
;
//import org.springframework.test.web.servlet.MockMvc;
import
org.mockito.MockitoAnnotations
;
//import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import
org.springframework.http.MediaType
;
//import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import
org.springframework.test.web.servlet.MockMvc
;
//
import
org.springframework.test.web.servlet.result.MockMvcResultMatchers
;
//import com.fasterxml.jackson.databind.ObjectMapper;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
//import com.nisum.mytime.controller.ProjectController;
//import com.nisum.mytime.model.Account;
import
com.fasterxml.jackson.databind.ObjectMapper
;
//import com.nisum.mytime.model.EmployeeRoles;
import
com.nisum.myteam.controller.ProjectController
;
//import com.nisum.mytime.model.Project;
import
com.nisum.myteam.model.dao.Employee
;
//import com.nisum.mytime.repository.AccountRepo;
import
com.nisum.myteam.model.dao.Project
;
//import com.nisum.mytime.service.ProjectService;
import
com.nisum.myteam.service.IEmployeeService
;
//import com.nisum.mytime.service.UserService;
import
com.nisum.myteam.service.IProjectService
;
//
//public class ProjectControllerTest {
//
public
class
ProjectControllerTest
{
// @Mock
// UserService userService;
@Mock
//
IProjectService
projectService
;
// @Mock
// ProjectService projectService;
@Mock
//
IEmployeeService
employeeService
;
// @Mock
// AccountRepo accountRepo;
// @Mock
//
// AccountRepo accountRepo;
// @InjectMocks
// ProjectController projectController;
@InjectMocks
//
ProjectController
projectController
;
// private MockMvc mockMvc;
//
private
MockMvc
mockMvc
;
// @Before
// public void setup() {
@Before
// MockitoAnnotations.initMocks(this);
public
void
setup
()
{
// mockMvc = MockMvcBuilders.standaloneSetup(projectController).build();
MockitoAnnotations
.
initMocks
(
this
);
// }
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
projectController
).
build
();
//
}
// @Test
// public void testgetEmployeeRole() throws Exception {
@Test
// EmployeeRoles employeesRole = new EmployeeRoles(
public
void
testgetEmployeeRole
()
throws
Exception
{
// "5976ef15874c902c98b8a05d", null, null, "user@nisum.com", null,
Project
employeePersisted
=
new
Project
();
// null, null, null, null, null, null, null, null, null, null,
Project
Project
=
new
Project
();
// null, null, new Date(2017 - 11 - 12), new Date(2017 - 12 - 12),
ObjectMapper
mapper
=
new
ObjectMapper
();
// null,
String
jsonString
=
mapper
.
writeValueAsString
(
Project
);
// null, null,null,new Date(2020 - 01 - 01),new Date(2018 - 01 - 01),new Date(2018 - 02 - 15),new Date(2018 - 02 - 15),"Mahesh","Mahesh");
when
(
projectService
.
updateProject
(
anyObject
(),
anyString
())).
thenReturn
(
Project
);
// when(userService.getEmployeesRole("user@nisum.com"))
mockMvc
.
perform
(
put
(
"/projects/{projectId}"
,
"16253"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
// .thenReturn(employeesRole);
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
// mockMvc.perform(
}
// get("/project/employee").param("emailId", "user@nisum.com"))
// .andExpect(MockMvcResultMatchers.status().isOk());
/* @Test
// verify(userService).getEmployeesRole("user@nisum.com");
public void testgetEmployeeRole() throws Exception {
// }
EmployeeRoles employeesRole = new EmployeeRoles(
//
"5976ef15874c902c98b8a05d", null, null, "user@nisum.com", null,
// @Test
null, null, null, null, null, null, null, null, null, null,
// public void testaddProject() throws Exception {
null, null, new Date(2017 - 11 - 12), new Date(2017 - 12 - 12),
// List<String> list = new ArrayList<>();
null,
// list.add("16620");
null, null,null,new Date(2020 - 01 - 01),new Date(2018 - 01 - 01),new Date(2018 - 02 - 15),new Date(2018 - 02 - 15),"Mahesh","Mahesh");
//
when(userService.getEmployeesRole("user@nisum.com"))
// Project employeeRole1 = new Project(
.thenReturn(employeesRole);
// new ObjectId("9976ef15874c902c98b8a05d"), "102","Macys", "NisumIndia","Active",list,
mockMvc.perform(
// list, "Acc001", "DOM001",new Date(2018 - 06 - 29),
get("/project/employee").param("emailId", "user@nisum.com"))
// new Date(2018 - 12 - 20), list);
.andExpect(MockMvcResultMatchers.status().isOk());
//
verify(userService).getEmployeesRole("user@nisum.com");
// Account account = new Account( "Acc001", "Macys", 3, "Y","Macys","Retail",list);
}
//
// when(projectService.addProject(employeeRole1))
@Test
// .thenReturn(employeeRole1);
public void testaddProject() throws Exception {
// when(accountRepo.findByAccountId("Acc001")).thenReturn(account);
List<String> list = new ArrayList<>();
// String jsonvalue = (new ObjectMapper())
list.add("16620");
// .writeValueAsString(employeeRole1).toString();
// mockMvc.perform(post("/project/addProject")
Project employeeRole1 = new Project(
// .contentType(MediaType.APPLICATION_JSON_VALUE)
new ObjectId("9976ef15874c902c98b8a05d"), "102","Macys", "NisumIndia","Active",list,
// .content(jsonvalue))
list, "Acc001", "DOM001",new Date(2018 - 06 - 29),
// .andExpect(MockMvcResultMatchers.status().isOk());
new Date(2018 - 12 - 20), list);
// }
//
Account account = new Account( "Acc001", "Macys", 3, "Y","Macys","Retail",list);
// @Test
// public void testupdateEmployeeRole() throws Exception {
when(projectService.addProject(employeeRole1))
// List<String> employeeIds = new ArrayList<>();
.thenReturn(employeeRole1);
// List<String> managerIds = new ArrayList<>();
when(accountRepo.findByAccountId("Acc001")).thenReturn(account);
// List<String> deliveryLeadIds = new ArrayList<>();
String jsonvalue = (new ObjectMapper())
//
.writeValueAsString(employeeRole1).toString();
// employeeIds.add("16649");
mockMvc.perform(post("/project/addProject")
// employeeIds.add("16650");
.contentType(MediaType.APPLICATION_JSON_VALUE)
// employeeIds.add("16651");
.content(jsonvalue))
//
.andExpect(MockMvcResultMatchers.status().isOk());
//
}
// managerIds.add("16652");
//
@Test
// deliveryLeadIds.add("16653");
public void testupdateEmployeeRole() throws Exception {
// deliveryLeadIds.add("16654");
List<String> employeeIds = new ArrayList<>();
//
List<String> managerIds = new ArrayList<>();
//
List<String> deliveryLeadIds = new ArrayList<>();
// Project project = new Project(new ObjectId("5976ef15874c902c98b8a05d"),"Gap0026",
// "Mosaic", "Move", "Active", employeeIds, managerIds,"Acc002","DOM002"
employeeIds.add("16649");
// ,new Date(2017 - 11 - 29),
employeeIds.add("16650");
// new Date(2017 - 12 - 20),deliveryLeadIds);
employeeIds.add("16651");
// ObjectMapper mapper = new ObjectMapper();
// String jsonString = mapper.writeValueAsString(project);
// when(projectService.updateProject(any())).thenReturn(project);
managerIds.add("16652");
// }
//
deliveryLeadIds.add("16653");
// @Test
deliveryLeadIds.add("16654");
// public void testdeleteProject() throws Exception {
// mockMvc.perform(
// delete("/project/deleteProject").param("projectId", "101"))
Project project = new Project(new ObjectId("5976ef15874c902c98b8a05d"),"Gap0026",
// .andExpect(MockMvcResultMatchers.status().isOk());
"Mosaic", "Move", "Active", employeeIds, managerIds,"Acc002","DOM002"
// verify(projectService).deleteProject("101");
,new Date(2017 - 11 - 29),
// }
new Date(2017 - 12 - 20),deliveryLeadIds);
//
ObjectMapper mapper = new ObjectMapper();
// @Test
String jsonString = mapper.writeValueAsString(project);
// public void testgetProjects() throws Exception {
when(projectService.updateProject(any())).thenReturn(project);
// List<HashMap<Object,Object>> projects = CreateProjectDetails();
}
// when(projectService.getProjects()).thenReturn(projects);
// mockMvc.perform(get("/project/getProjects")
@Test
// .contentType(MediaType.APPLICATION_JSON_VALUE))
public void testdeleteProject() throws Exception {
// .andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(
// }
delete("/project/deleteProject").param("projectId", "101"))
//
.andExpect(MockMvcResultMatchers.status().isOk());
// @Test
verify(projectService).deleteProject("101");
// public void testgetEmployeeRoleData() throws Exception {
}
// EmployeeRoles employeesRole = new EmployeeRoles(
// "5976ef15874c902c98b8a05d", null, null, null, null, null, null,
@Test
// null, null, null, null, null, null, "user@nisum.com", null,
public void testgetProjects() throws Exception {
// null, null, new Date(2017 - 11 - 20), new Date(2107 - 12 - 23),
List<HashMap<Object,Object>> projects = CreateProjectDetails();
// null,
when(projectService.getProjects()).thenReturn(projects);
// null, null,null,new Date(2020 - 01 - 01),new Date(2018 - 01 - 01),new Date(2018 - 02 - 15),new Date(2018 - 02 - 15),"Mahesh","Mahesh");
mockMvc.perform(get("/project/getProjects")
// when(userService.getEmployeesRoleData("16127")) .thenReturn(employeesRole);
.contentType(MediaType.APPLICATION_JSON_VALUE))
// mockMvc.perform(
.andExpect(MockMvcResultMatchers.status().isOk());
// get("/project/getEmployeeRoleData").param("empId", "16127")
}
// .contentType(MediaType.APPLICATION_JSON_VALUE))
// .andExpect(MockMvcResultMatchers.status().isOk());
@Test
// verify(userService).getEmployeesRoleData("16127");
public void testgetEmployeeRoleData() throws Exception {
// }
EmployeeRoles employeesRole = new EmployeeRoles(
//
"5976ef15874c902c98b8a05d", null, null, null, null, null, null,
// private List<HashMap<Object,Object>>CreateProjectDetails() {
null, null, null, null, null, null, "user@nisum.com", null,
// List<HashMap<Object,Object>> data = new ArrayList<HashMap<Object,Object>> ();
null, null, new Date(2017 - 11 - 20), new Date(2107 - 12 - 23),
// HashMap<Object,Object> map1 = new HashMap<Object,Object>();
null,
// HashMap<Object,Object> map2 = new HashMap<Object,Object>();
null, null,null,new Date(2020 - 01 - 01),new Date(2018 - 01 - 01),new Date(2018 - 02 - 15),new Date(2018 - 02 - 15),"Mahesh","Mahesh");
//
when(userService.getEmployeesRoleData("16127")) .thenReturn(employeesRole);
// Project data1 = new Project();
mockMvc.perform(
// data1.setId(new ObjectId("5976ef15874c902c98b8a05d"));
get("/project/getEmployeeRoleData").param("empId", "16127")
// data1.setProjectId("101");
.contentType(MediaType.APPLICATION_JSON_VALUE))
// data1.setProjectName("MOSAIC");
.andExpect(MockMvcResultMatchers.status().isOk());
// data1.setStatus("Billable");
verify(userService).getEmployeesRoleData("16127");
//
}
// List<String> list = new ArrayList<>();
// list.add("16101");
private List<HashMap<Object,Object>>CreateProjectDetails() {
// list.add("16102");
List<HashMap<Object,Object>> data = new ArrayList<HashMap<Object,Object>> ();
// list.add("16103");
HashMap<Object,Object> map1 = new HashMap<Object,Object>();
//
HashMap<Object,Object> map2 = new HashMap<Object,Object>();
// data1.setEmployeeIds(list);
// map1.put(new ObjectId("5976ef15874c902c98b8a05d"), data1);
Project data1 = new Project();
//
data1.setId(new ObjectId("5976ef15874c902c98b8a05d"));
// Project data2 = new Project();
data1.setProjectId("101");
// data2.setId(new ObjectId("9976ef15874c902c98b8a05d"));
data1.setProjectName("MOSAIC");
// data2.setProjectId("102");
data1.setStatus("Billable");
// data2.setProjectName("OMS");
// data2.setStatus("Non-Billable");
List<String> list = new ArrayList<>();
// List<String> lists = new ArrayList<>();
list.add("16101");
// lists.add("16104");
list.add("16102");
// lists.add("16105");
list.add("16103");
// lists.add("16106");
// data2.setEmployeeIds(lists);
data1.setEmployeeIds(list);
// map2.put(new ObjectId("9976ef15874c902c98b8a05d"), data2);
map1.put(new ObjectId("5976ef15874c902c98b8a05d"), data1);
//
// data.add(map1);
Project data2 = new Project();
// data.add(map2);
data2.setId(new ObjectId("9976ef15874c902c98b8a05d"));
//
data2.setProjectId("102");
// return data;
data2.setProjectName("OMS");
// }
data2.setStatus("Non-Billable");
//}
List<String> lists = new ArrayList<>();
lists.add("16104");
lists.add("16105");
lists.add("16106");
data2.setEmployeeIds(lists);
map2.put(new ObjectId("9976ef15874c902c98b8a05d"), data2);
data.add(map1);
data.add(map2);
return data;
} */
}
src/test/java/com/nisum/myteam/controllertest/ReportsControllerTest.java
0 → 100644
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
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.nisum.myteam.controller.ReportsController
;
import
com.nisum.myteam.service.IEmployeeService
;
import
com.nisum.myteam.service.IResourceService
;
public
class
ReportsControllerTest
{
@Mock
IEmployeeService
employeeService
;
@Mock
IResourceService
resourceService
;
@InjectMocks
ReportsController
reportsController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
reportsController
).
build
();
}
@Test
public
void
testGetEmployeesByFunctionalGroup
()
throws
Exception
{
// mockMvc.perform(get("/getEmployeesByFunctionalGroup1").param("domainId", "ACC001"))
// .andExpect(MockMvcResultMatchers.status().isOk());
// verify(masterDataService).getMasterData();
}
}
src/test/java/com/nisum/myteam/controllertest/ResourceControllerTest.java
0 → 100644
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
import
java.util.List
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
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.myteam.controller.ResourceController
;
import
com.nisum.myteam.model.dao.Employee
;
import
com.nisum.myteam.model.dao.Resource
;
import
com.nisum.myteam.repository.EmployeeVisaRepo
;
import
com.nisum.myteam.service.IEmployeeService
;
import
com.nisum.myteam.service.IProjectService
;
import
com.nisum.myteam.service.impl.ResourceService
;
public
class
ResourceControllerTest
{
@Mock
IEmployeeService
employeeService
;
@Mock
IProjectService
projectService
;
@Mock
EmployeeVisaRepo
employeeVisaRepo
;
@Mock
ResourceService
resourceService
;
@InjectMocks
ResourceController
resourceController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
resourceController
).
build
();
}
@Test
public
void
testCreateResource
()
throws
Exception
{
// Resource employeeList = null;
// when(resourceService.validateBillingStartEndDateAgainstProjectStartEndDate(null, null)).thenReturn(true);
// when(resourceService.validateBillingStartDateAgainstDOJ(null)).thenReturn(true);
// when(resourceService.isResourceAssignedToAnyProject(null)).thenReturn(false);
// when(resourceService.validateAllocationAgainstPrevAllocation(null)).thenReturn(true);
// when(resourceService.addResource(null, null)).thenReturn(employeeList);
//
// mockMvc.perform(post("/resources").param("domainId", "ACC001"))
// .andExpect(MockMvcResultMatchers.status().isOk());
//
Resource
employeePersisted
=
new
Resource
();
Resource
employeeReq
=
new
Resource
();
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jsonString
=
mapper
.
writeValueAsString
(
employeeReq
);
// when(resourceService.validateBillingStartEndDateAgainstProjectStartEndDate(null, null)).thenReturn(true);
// when(resourceService.validateBillingStartDateAgainstDOJ(null)).thenReturn(true);
// when(resourceService.isResourceAssignedToAnyProject(null)).thenReturn(false);
// when(resourceService.validateAllocationAgainstPrevAllocation(null)).thenReturn(true);
when
(
resourceService
.
addResource
(
null
,
null
)).
thenReturn
(
employeePersisted
);
mockMvc
.
perform
(
post
(
"/resources"
).
contentType
(
MediaType
.
APPLICATION_JSON_VALUE
).
content
(
jsonString
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
}
}
src/test/java/com/nisum/myteam/controllertest/ShiftControllerTest.java
0 → 100644
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
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.nisum.myteam.controller.ShiftController
;
import
com.nisum.myteam.service.IShiftService
;
public
class
ShiftControllerTest
{
@Mock
IShiftService
shiftService
;
@InjectMocks
ShiftController
shiftController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
shiftController
).
build
();
}
@Test
public
void
testgetAllShifts
()
throws
Exception
{
// List<String> shiftsList = shiftList();
// List<Shift> Response=null;
// when(shiftService.getAllShifts()).thenReturn(Response);
mockMvc
.
perform
(
get
(
"/employees/shifts/"
).
param
(
"domainId"
,
"ACC001"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
shiftService
).
getAllShifts
();
}
}
src/test/java/com/nisum/myteam/controllertest/SkillControllerTest.java
0 → 100644
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.MockitoAnnotations
;
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.nisum.myteam.controller.SkillController
;
import
com.nisum.myteam.service.ISkillService
;
public
class
SkillControllerTest
{
@Mock
ISkillService
skillService
;
@InjectMocks
SkillController
skillController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
skillController
).
build
();
}
@Test
public
void
testGetTechnologies
()
throws
Exception
{
// List<String> shiftsList = shiftList();
// List<Shift> Response=null;
// when(shiftService.getAllShifts()).thenReturn(Response);
mockMvc
.
perform
(
get
(
"/employees/skills/"
).
param
(
"domainId"
,
"ACC001"
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
skillService
).
getTechnologies
();
}
}
src/test/java/com/nisum/myteam/controllertest/UploadXLControllerTest.java
0 → 100644
View file @
ec748ad5
package
com
.
nisum
.
myteam
.
controllertest
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
post
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.poi.util.IOUtils
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.Mockito
;
import
org.mockito.MockitoAnnotations
;
import
org.springframework.http.MediaType
;
import
org.springframework.mock.web.MockMultipartFile
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.result.MockMvcResultMatchers
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.nisum.myteam.controller.UploadXLController
;
import
com.nisum.myteam.service.IUploadXLService
;
public
class
UploadXLControllerTest
{
@Mock
IUploadXLService
uploadService
;
@InjectMocks
UploadXLController
uploadXLController
;
private
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
MockitoAnnotations
.
initMocks
(
this
);
mockMvc
=
MockMvcBuilders
.
standaloneSetup
(
uploadXLController
).
build
();
}
@Test
public
void
testExportDataFromFile
()
throws
Exception
{
//List list = new ArrayList();
String
result
=
"resl"
;
//MultipartFile file = null;
byte
[]
content
=
new
byte
[
5
];
File
file
=
new
File
(
"src/test/java/input.txt"
);
FileInputStream
input
=
new
FileInputStream
(
file
);
MultipartFile
multipartFile
=
new
MockMultipartFile
(
"file"
,
file
.
getName
(),
"text/plain"
,
IOUtils
.
toByteArray
(
input
));
when
(
uploadService
.
importDataFromExcelFile
(
multipartFile
,
""
)).
thenReturn
(
result
);
mockMvc
.
perform
(
post
(
"/employee/fileUpload"
).
contentType
(
MediaType
.
MULTIPART_FORM_DATA_VALUE
)
.
content
(
result
))
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
()).
andExpect
(
content
().
string
(
result
));
//verify(uploadService).importDataFromExcelFile(file, "16253");
}
}
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