Commit ec748ad5 authored by shiva dandem's avatar shiva dandem

Added JUNIT Code coverage for controllers

parent 4319b7a8
......@@ -2,6 +2,7 @@ package com.nisum.myteam.controllertest;
import java.util.Map;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
......@@ -18,7 +19,9 @@ 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.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
......@@ -27,14 +30,14 @@ 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.IAccountService;
import com.nisum.myteam.service.impl.AccountService;
public class AccountControllerTest {
public class AccountControllerTest {
@Mock
AccountService Accountserviceimpl;
private IAccountService accountService;
@InjectMocks
AccountController AccountController;
......@@ -46,81 +49,182 @@ public class AccountControllerTest {
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 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
public void testCreateAccountExists() 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.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
public void testgetAccountNames() throws Exception {
List<Map<Object, Object>> Account = CreateAccountDetails();
when(Accountserviceimpl.getAccountsList()).thenReturn(Account);
mockMvc.perform(get("/account/accountNames")
Account account=new Account();
account.setAccountId("123");
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))
.andExpect(MockMvcResultMatchers.status().isOk());
}
/*
@Test
public void testgetAccount() throws Exception {
List<Account> Account = null;
when(Accountserviceimpl.getAccounts()).thenReturn(Account);
mockMvc.perform(get("/account/accounts")
List<Map<Object, Object>> Account = null;
when(accountService.getAccountsList()).thenReturn(Account);
mockMvc.perform(get("/accounts")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.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 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 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 testdeleteAccount() throws Exception {
mockMvc.perform(
delete("/account/accounts").param("accountId", "Acc002"))
delete("/accounts/Acc002").param("accountId", "Acc002"))
.andExpect(MockMvcResultMatchers.status().isOk());
//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());
verify(Accountserviceimpl).deleteAccount("Acc002");
}
private List<Map<Object,Object>>CreateAccountDetails() {
......@@ -128,7 +232,7 @@ public class AccountControllerTest {
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.setId(new ObjectId("5976ef15874c902c98b8a05d"));
data1.setAccountId("Acc004");
data1.setAccountName("Govt");
data1.setAccountProjectSequence(4);
......@@ -143,7 +247,7 @@ public class AccountControllerTest {
data1.setDeliveryManagers(list);
Account data2 = new Account();
//data2.setId(new ObjectId("9976ef15874c902c98b8a05d"));
data2.setId(new ObjectId("9976ef15874c902c98b8a05d"));
data2.setAccountId("Acc004");
data2.setAccountName("Govt");
data2.setAccountProjectSequence(4);
......@@ -166,5 +270,4 @@ public class AccountControllerTest {
return data;
}
}
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;
}
}
......@@ -24,6 +24,7 @@ import com.nisum.myteam.service.IAttendanceService;
public class AttendanceControllerTest {
@Mock
IAttendanceService attendanceService;
......@@ -38,14 +39,17 @@ public class AttendanceControllerTest {
mockMvc = MockMvcBuilders.standaloneSetup(attendanceController).build();
}
@SuppressWarnings("unchecked")
@Test
public void testemployeeLoginsBasedOnDate() throws Exception {
List<EmpLoginData> message = createLoginData();
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")
.param("toDate", "2017-12-15")).andDo(print()).andExpect(status().isOk());
}
@Test
public void testgeneratePdfReport() throws Exception {
List list = new ArrayList();
......@@ -55,6 +59,16 @@ public class AttendanceControllerTest {
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
public void testattendanciesReport() throws Exception {
List<AttendenceData> lisOfAttendenceData = createAttendenceData();
......@@ -72,6 +86,14 @@ public class AttendanceControllerTest {
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() {
List<AttendenceData> data = new ArrayList<>();
......
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());
}
}
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());
}
}
package com.nisum.myteam.controllertest;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
......@@ -47,61 +48,130 @@ public class DomainControllerTest {
}
@Test
public void testaddDomain() throws Exception {
public void testCreateDomain() throws Exception {
List<String> list = new ArrayList<>();
list.add("16620");
list.add("16632");
String responce=null;
// String response=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))
.thenReturn(domainPeristed);
String jsonvalue = (new ObjectMapper())
.writeValueAsString(domains).toString();
mockMvc.perform(post("/domains")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonvalue))
.andExpect(MockMvcResultMatchers.status().isOk());
}
@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))
public void testCreateDomainForDomainExist() throws Exception {
List<String> list = new ArrayList<>();
list.add("16620");
list.add("16632");
// String response=null;
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());
verify(domainService).getDomainsList();
}
@Test
public void testupdateDomains() throws Exception {
List<String> employeeIds = new ArrayList<>();
employeeIds.add("16649");
employeeIds.add("16650");
employeeIds.add("16651");
String responce=null;
Domain domain = new Domain( "DOM002", "Marketing", "Acc002",
"Active",employeeIds);
// 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();
String jsonString = mapper.writeValueAsString(domain);
when(domainService.update(any())).thenReturn(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());
//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();
String jsonString = mapper.writeValueAsString(domain);
when(domainService.isDomainExists(anyObject()))
.thenReturn(true);
when(domainService.update(any())).thenReturn(domainPeristed);
mockMvc.perform(put("/domains")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonString))
.andExpect(MockMvcResultMatchers.status().isOk());
//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
public void testdeleteDomain() throws Exception {
mockMvc.perform(
delete("/domains").param("domainId", "DOM001"))
mockMvc.perform(delete("/domains/DOM005").param("domainId", "DOM005"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(domainService).delete("DOM001");
verify(domainService).delete("DOM005");
}
......@@ -111,7 +181,7 @@ public class DomainControllerTest {
HashMap<Object,Object> map2 = new HashMap<Object,Object>();
Domain data1 = new Domain();
//data1.setId(new ObjectId("5976ef15874c902c98b8a05d"));
data1.setId(new ObjectId("5976ef15874c902c98b8a05d"));
data1.setDomainId("DOM003");
data1.setDomainName("MOC");
data1.setAccountId("ACC001");
......@@ -126,8 +196,8 @@ public class DomainControllerTest {
Domain data2 = new Domain();
//data2.setId(new ObjectId("9976ef15874c902c98b8a05d"));
data2.setDomainId("DOM004");
data2.setId(new ObjectId("9976ef15874c902c98b8a05d"));
data2.setDomainId("DOM005");
data2.setDomainName("BIGTICKET");
data2.setAccountId("ACC001");
data2.setStatus("Active");
......
package com.nisum.myteam.controllertest;
import static org.mockito.Matchers.any;
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.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
......@@ -42,7 +46,8 @@ public class EmailControllerTest {
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(emailObj);
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
......@@ -57,11 +62,11 @@ public class EmailControllerTest {
}
@Test
/* @Test
public void testdeletePdfReport() throws Exception{
when(mailService.deletePdfReport("eTimeTrackLite1")).thenReturn("Success");
mockMvc.perform(get("/deleteReport/eTimeTrackLite1")).andExpect(MockMvcResultMatchers.status().isOk());
verify(mailService).deletePdfReport("eTimeTrackLite1");
}
} */
}
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.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.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import java.util.ArrayList;
import java.util.Date;
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;
......@@ -29,53 +21,21 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import com.fasterxml.jackson.databind.ObjectMapper;
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.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.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 {
@Mock
IEmployeeService employeeService;
private IEmployeeService empService;
@Mock
IEmployeeRoleService roleMappingService;
private IEmployeeRoleService employeeRoleService;
@InjectMocks
EmployeeController employeeController;
@InjectMocks
EmployeeLocationService empLocationService;
@InjectMocks
ShiftService shiftService;
@InjectMocks
DesignationService designationService;
@InjectMocks
SkillService skillService;
@InjectMocks
OrgLocationService orgLocationService;
@InjectMocks
MasterDataService masterDataService;
private MockMvc mockMvc;
@Before
......@@ -85,473 +45,161 @@ public class EmployeeControllerTest {
}
@Test
public void testgetEmployeeRoleAsAdmin() 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.getEmployeeByEmaillId("mdeekonda@nisum.com")).thenReturn(employeesRole);
mockMvc.perform(get("/user/employee").param("emailId", "mdeekonda@nisum.com"))
public void testCreateEmployee() throws Exception {
Employee employeePersisted = new Employee();
Employee employeeReq = new Employee();
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(employeeReq);
when(empService.createEmployee(employeeReq, "16253")).thenReturn(employeePersisted);
mockMvc.perform(post("/employees/{empId}","16253").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(employeeService).getEmployeeByEmaillId("mdeekonda@nisum.com");
}
@Test
public void testgetEmployeeRoleAsEmp() throws Exception {
Employee employeesRole = new Employee("5b307d7e708ef705c4ca64d8", "16694", "Mahesh Deekonda",
"mdeekonda@nisum.com", "Employee", "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.getEmployeeByEmaillId("mdeekonda@nisum.com")).thenReturn(employeesRole);
when(roleMappingService.getEmployeeRole(employeesRole.getEmployeeId())).thenReturn("Delivery Lead");
mockMvc.perform(get("/user/employee").param("emailId", "mdeekonda@nisum.com"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(employeeService).getEmployeeByEmaillId("mdeekonda@nisum.com");
verify(roleMappingService).getEmployeeRole("16694");
}
@Test
public void testassigingEmployeeRole() throws Exception {
Employee employeeRole = 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");
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(employeeRole);
when(employeeService.createEmployee(anyObject(), anyObject())).thenReturn(employeeRole);
mockMvc.perform(post("/user/assignEmployeeRole").param("empId", "16999")
.contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(employeeService).createEmployee(anyObject(), anyObject());
}
@Test
public void testupdateEmployeeRole() throws Exception {
Employee employeeRole2 = 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");
public void testCreateEmployeeExistsById() throws Exception {
Employee employeePersisted = new Employee();
Employee employeeReq = new Employee();
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(employeeRole2);
when(employeeService.updateEmployee(anyObject(), anyObject())).thenReturn(employeeRole2);
mockMvc.perform(post("/user/updateEmployeeRole").param("empId", "16999")
.contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString))
String jsonString = mapper.writeValueAsString(employeeReq);
when(empService.isEmployeeExistsById("16253")).thenReturn(true);
when(empService.createEmployee(employeeReq, "16253")).thenReturn(employeePersisted);
mockMvc.perform(post("/employees/{empId}","16253").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(employeeService).updateEmployee(anyObject(), anyObject());
}
@Test
public void testdeleteEmployee() throws Exception {
mockMvc.perform(delete("/user/deleteEmployee").param("empId", "16127"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(employeeService).deleteEmployee("16127");
}
@Test
public void testgetUserRoles() throws Exception {
List<Employee> employeesRole3 = CreateUserRoles();
when(employeeService.getActiveEmployees()).thenReturn(employeesRole3);
mockMvc.perform(get("/user/getUserRoles").contentType(MediaType.APPLICATION_JSON_VALUE))
public void testUpdateEmployee() throws Exception {
Employee employeePersisted = new Employee();
Employee employeeReq = new Employee();
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(employeeReq);
when(empService.updateEmployee(employeeReq, "16253")).thenReturn(employeePersisted);
mockMvc.perform(put("/employees/{empId}","16253").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString))
.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");
}
public void testUpdateEmployeeExistsById() throws Exception {
Employee employeePersisted = new Employee();
Employee employeeReq = new Employee();
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(employeeReq);
when(empService.isEmployeeExistsById("16253")).thenReturn(true);
when(empService.updateEmployee(employeeReq, "16253")).thenReturn(employeePersisted);
mockMvc.perform(put("/employees/{empId}","16253").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString))
.andExpect(MockMvcResultMatchers.status().isOk());
@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();
}
public void testDeleteEmployee() throws Exception {
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());
@Test
public void testgetManagers() throws Exception {
List<Employee> employeesRole4 = CreateUserRoles();
System.out.println(employeesRole4);
when(employeeService.getActiveEmployees()).thenReturn(employeesRole4);
mockMvc.perform(get("/user/getManagers")).andExpect(MockMvcResultMatchers.status().isOk());
verify(employeeService).getActiveEmployees();
}
@Test
public void testgetAllShifts() throws Exception {
List<Shift> shifts = CreateShifts();
when(shiftService.getAllShifts()).thenReturn(shifts);
mockMvc.perform(get("/user/getAllShifts")).andExpect(MockMvcResultMatchers.status().isOk());
verify(shiftService).getAllShifts();
}
public void testDeleteEmployeeExistsById() throws Exception {
Employee employeePersisted = new Employee();
Employee employeeReq = new Employee();
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());
@Test
public void testgetAllDesignations() throws Exception {
List<Designation> designation = CreateDesignations();
when(designationService.getAllDesignations()).thenReturn(designation);
mockMvc.perform(get("/user/getAllDesignations")).andExpect(MockMvcResultMatchers.status().isOk());
verify(designationService).getAllDesignations();
}
@Test
public void testgetTechnologies() throws Exception {
List<Skill> skills = CreateSkill();
System.out.println(skills);
when(skillService.getTechnologies()).thenReturn(skills);
mockMvc.perform(get("/user/getSkills")).andExpect(MockMvcResultMatchers.status().isOk());
verify(skillService).getTechnologies();
}
public void testUpdateProfile() throws Exception {
Employee employeePersisted = new Employee();
Employee employeeReq = new Employee();
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(employeeReq);
when(empService.updateProfile(employeeReq)).thenReturn(employeePersisted);
mockMvc.perform(post("/employees/updateProfile").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString))
.andExpect(MockMvcResultMatchers.status().isOk());
@Test
public void testgetLocations() throws Exception {
when(orgLocationService.getLocations()).thenReturn(locations());
mockMvc.perform(get("/user/getLocations")).andExpect(MockMvcResultMatchers.status().isOk());
verify(orgLocationService, atLeastOnce()).getLocations();
}
@Test
public void testupdateProfile() throws Exception {
Employee employeeRole = 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");
System.out.println(employeeRole);
public void testGetEmployeeById() throws Exception {
Employee employeePersisted = new Employee();
Employee employeeReq = new Employee();
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))
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());
verify(employeeService).updateProfile(anyObject());
}
@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
public void testGetEmployeeByStatus() throws Exception {
List<Employee> empRolesList = employeeRoles();
when(employeeService.getEmployeesByStatus("Active")).thenReturn(empRolesList);
mockMvc.perform(get("/user/getEmployeeByStatus").param("status", "Active"))
public void testGetEmployee() throws Exception {
Employee employeePersisted = new Employee();
// Employee employeeReq = new Employee();
Employee employee = null;
when(empService.getEmployeeByEmaillId("s@nisum.com")).thenReturn(employee);
mockMvc.perform(get("/employees/emailId"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(employeeService).getEmployeesByStatus("Active");
}
// @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
public void testgetDeliveryLeads() throws Exception {
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");
public void testGetManagers() throws Exception {
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"))
mockMvc.perform(get("/employees/managers/").param("domainId", "ACC001"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(employeeService).getDeliveryLeads("DOM001");
}
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;
verify(empService).getManagers();
}
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;
@Test
public void testGetActiveEmployees() throws Exception {
}
mockMvc.perform(get("/employees/active").param("domainId", "ACC001"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(empService).getActiveEmployees();
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;
}
@Test
public void testGetAccounts() throws Exception {
mockMvc.perform(get("/employees/accounts/").param("domainId", "ACC001"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(empService).getAccounts();
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;
}
@Test
public void testGetEmployeeByStatus() throws Exception {
List<Employee> employeeList = null;
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(employeeList);
when(empService.getEmployeesByStatus("all")).thenReturn(employeeList);
mockMvc.perform(get("/employees/").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString))
.andExpect(MockMvcResultMatchers.status().isOk());
// verify(empService).getEmployeesByStatus("");
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>();
@Test
public void testGetEmployeeRoleDataForSearchCriteria() throws Exception {
mockMvc.perform(get("/employee/searchCriteria").param("domainId", "ACC001"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(empService).getEmployeeRoleDataForSearchCriteria("", "");
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;
}
}
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;
}
}
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;
}
}
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);
}
}
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();
}
}
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();
}
}
package com.nisum.myteam.controllertest;
//package com.nisum.mytime.controllertest;
//
//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 java.util.ArrayList;
//import java.util.Date;
//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.mytime.controller.ProjectController;
//import com.nisum.mytime.model.Account;
//import com.nisum.mytime.model.EmployeeRoles;
//import com.nisum.mytime.model.Project;
//import com.nisum.mytime.repository.AccountRepo;
//import com.nisum.mytime.service.ProjectService;
//import com.nisum.mytime.service.UserService;
//
//public class ProjectControllerTest {
//
// @Mock
// UserService userService;
//
// @Mock
// ProjectService projectService;
//
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject;
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.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.Date;
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.ProjectController;
import com.nisum.myteam.model.dao.Employee;
import com.nisum.myteam.model.dao.Project;
import com.nisum.myteam.service.IEmployeeService;
import com.nisum.myteam.service.IProjectService;
public class ProjectControllerTest {
@Mock
IProjectService projectService;
@Mock
IEmployeeService employeeService;
// @Mock
// AccountRepo accountRepo;
//
// @InjectMocks
// ProjectController projectController;
//
// private MockMvc mockMvc;
//
// @Before
// public void setup() {
// MockitoAnnotations.initMocks(this);
// mockMvc = MockMvcBuilders.standaloneSetup(projectController).build();
// }
//
// @Test
// public void testgetEmployeeRole() throws Exception {
// EmployeeRoles employeesRole = new EmployeeRoles(
// "5976ef15874c902c98b8a05d", null, null, "user@nisum.com", null,
// null, null, null, null, null, null, null, null, null, null,
// null, null, new Date(2017 - 11 - 12), new Date(2017 - 12 - 12),
// 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");
// when(userService.getEmployeesRole("user@nisum.com"))
// .thenReturn(employeesRole);
// mockMvc.perform(
// get("/project/employee").param("emailId", "user@nisum.com"))
// .andExpect(MockMvcResultMatchers.status().isOk());
// verify(userService).getEmployeesRole("user@nisum.com");
// }
//
// @Test
// public void testaddProject() throws Exception {
// List<String> list = new ArrayList<>();
// list.add("16620");
//
// Project employeeRole1 = new Project(
// new ObjectId("9976ef15874c902c98b8a05d"), "102","Macys", "NisumIndia","Active",list,
// list, "Acc001", "DOM001",new Date(2018 - 06 - 29),
// new Date(2018 - 12 - 20), list);
//
// Account account = new Account( "Acc001", "Macys", 3, "Y","Macys","Retail",list);
//
// when(projectService.addProject(employeeRole1))
// .thenReturn(employeeRole1);
// when(accountRepo.findByAccountId("Acc001")).thenReturn(account);
// String jsonvalue = (new ObjectMapper())
// .writeValueAsString(employeeRole1).toString();
// mockMvc.perform(post("/project/addProject")
// .contentType(MediaType.APPLICATION_JSON_VALUE)
// .content(jsonvalue))
// .andExpect(MockMvcResultMatchers.status().isOk());
// }
//
// @Test
// public void testupdateEmployeeRole() throws Exception {
// List<String> employeeIds = new ArrayList<>();
// List<String> managerIds = new ArrayList<>();
// List<String> deliveryLeadIds = new ArrayList<>();
//
// employeeIds.add("16649");
// employeeIds.add("16650");
// employeeIds.add("16651");
//
//
// managerIds.add("16652");
//
// deliveryLeadIds.add("16653");
// deliveryLeadIds.add("16654");
//
//
// Project project = new Project(new ObjectId("5976ef15874c902c98b8a05d"),"Gap0026",
// "Mosaic", "Move", "Active", employeeIds, managerIds,"Acc002","DOM002"
// ,new Date(2017 - 11 - 29),
// new Date(2017 - 12 - 20),deliveryLeadIds);
// ObjectMapper mapper = new ObjectMapper();
// String jsonString = mapper.writeValueAsString(project);
// when(projectService.updateProject(any())).thenReturn(project);
// }
//
// @Test
// public void testdeleteProject() throws Exception {
// mockMvc.perform(
// delete("/project/deleteProject").param("projectId", "101"))
// .andExpect(MockMvcResultMatchers.status().isOk());
// verify(projectService).deleteProject("101");
// }
//
// @Test
// public void testgetProjects() throws Exception {
// List<HashMap<Object,Object>> projects = CreateProjectDetails();
// when(projectService.getProjects()).thenReturn(projects);
// mockMvc.perform(get("/project/getProjects")
// .contentType(MediaType.APPLICATION_JSON_VALUE))
// .andExpect(MockMvcResultMatchers.status().isOk());
// }
//
// @Test
// public void testgetEmployeeRoleData() throws Exception {
// EmployeeRoles employeesRole = new EmployeeRoles(
// "5976ef15874c902c98b8a05d", null, null, null, null, null, null,
// null, null, null, null, null, null, "user@nisum.com", null,
// null, null, new Date(2017 - 11 - 20), new Date(2107 - 12 - 23),
// 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");
// when(userService.getEmployeesRoleData("16127")) .thenReturn(employeesRole);
// mockMvc.perform(
// get("/project/getEmployeeRoleData").param("empId", "16127")
// .contentType(MediaType.APPLICATION_JSON_VALUE))
// .andExpect(MockMvcResultMatchers.status().isOk());
// verify(userService).getEmployeesRoleData("16127");
// }
//
// private List<HashMap<Object,Object>>CreateProjectDetails() {
// List<HashMap<Object,Object>> data = new ArrayList<HashMap<Object,Object>> ();
// HashMap<Object,Object> map1 = new HashMap<Object,Object>();
// HashMap<Object,Object> map2 = new HashMap<Object,Object>();
//
// Project data1 = new Project();
// data1.setId(new ObjectId("5976ef15874c902c98b8a05d"));
// data1.setProjectId("101");
// data1.setProjectName("MOSAIC");
// data1.setStatus("Billable");
//
// List<String> list = new ArrayList<>();
// list.add("16101");
// list.add("16102");
// list.add("16103");
//
// data1.setEmployeeIds(list);
// map1.put(new ObjectId("5976ef15874c902c98b8a05d"), data1);
//
// Project data2 = new Project();
// data2.setId(new ObjectId("9976ef15874c902c98b8a05d"));
// data2.setProjectId("102");
// 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;
// }
//}
@InjectMocks
ProjectController projectController;
private MockMvc mockMvc;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mockMvc = MockMvcBuilders.standaloneSetup(projectController).build();
}
@Test
public void testgetEmployeeRole() throws Exception {
Project employeePersisted = new Project();
Project Project = new Project();
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(Project);
when(projectService.updateProject(anyObject(), anyString())).thenReturn(Project);
mockMvc.perform(put("/projects/{projectId}","16253").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString))
.andExpect(MockMvcResultMatchers.status().isOk());
}
/* @Test
public void testgetEmployeeRole() throws Exception {
EmployeeRoles employeesRole = new EmployeeRoles(
"5976ef15874c902c98b8a05d", null, null, "user@nisum.com", null,
null, null, null, null, null, null, null, null, null, null,
null, null, new Date(2017 - 11 - 12), new Date(2017 - 12 - 12),
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");
when(userService.getEmployeesRole("user@nisum.com"))
.thenReturn(employeesRole);
mockMvc.perform(
get("/project/employee").param("emailId", "user@nisum.com"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).getEmployeesRole("user@nisum.com");
}
@Test
public void testaddProject() throws Exception {
List<String> list = new ArrayList<>();
list.add("16620");
Project employeeRole1 = new Project(
new ObjectId("9976ef15874c902c98b8a05d"), "102","Macys", "NisumIndia","Active",list,
list, "Acc001", "DOM001",new Date(2018 - 06 - 29),
new Date(2018 - 12 - 20), list);
Account account = new Account( "Acc001", "Macys", 3, "Y","Macys","Retail",list);
when(projectService.addProject(employeeRole1))
.thenReturn(employeeRole1);
when(accountRepo.findByAccountId("Acc001")).thenReturn(account);
String jsonvalue = (new ObjectMapper())
.writeValueAsString(employeeRole1).toString();
mockMvc.perform(post("/project/addProject")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonvalue))
.andExpect(MockMvcResultMatchers.status().isOk());
}
@Test
public void testupdateEmployeeRole() throws Exception {
List<String> employeeIds = new ArrayList<>();
List<String> managerIds = new ArrayList<>();
List<String> deliveryLeadIds = new ArrayList<>();
employeeIds.add("16649");
employeeIds.add("16650");
employeeIds.add("16651");
managerIds.add("16652");
deliveryLeadIds.add("16653");
deliveryLeadIds.add("16654");
Project project = new Project(new ObjectId("5976ef15874c902c98b8a05d"),"Gap0026",
"Mosaic", "Move", "Active", employeeIds, managerIds,"Acc002","DOM002"
,new Date(2017 - 11 - 29),
new Date(2017 - 12 - 20),deliveryLeadIds);
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(project);
when(projectService.updateProject(any())).thenReturn(project);
}
@Test
public void testdeleteProject() throws Exception {
mockMvc.perform(
delete("/project/deleteProject").param("projectId", "101"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(projectService).deleteProject("101");
}
@Test
public void testgetProjects() throws Exception {
List<HashMap<Object,Object>> projects = CreateProjectDetails();
when(projectService.getProjects()).thenReturn(projects);
mockMvc.perform(get("/project/getProjects")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk());
}
@Test
public void testgetEmployeeRoleData() throws Exception {
EmployeeRoles employeesRole = new EmployeeRoles(
"5976ef15874c902c98b8a05d", null, null, null, null, null, null,
null, null, null, null, null, null, "user@nisum.com", null,
null, null, new Date(2017 - 11 - 20), new Date(2107 - 12 - 23),
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");
when(userService.getEmployeesRoleData("16127")) .thenReturn(employeesRole);
mockMvc.perform(
get("/project/getEmployeeRoleData").param("empId", "16127")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).getEmployeesRoleData("16127");
}
private List<HashMap<Object,Object>>CreateProjectDetails() {
List<HashMap<Object,Object>> data = new ArrayList<HashMap<Object,Object>> ();
HashMap<Object,Object> map1 = new HashMap<Object,Object>();
HashMap<Object,Object> map2 = new HashMap<Object,Object>();
Project data1 = new Project();
data1.setId(new ObjectId("5976ef15874c902c98b8a05d"));
data1.setProjectId("101");
data1.setProjectName("MOSAIC");
data1.setStatus("Billable");
List<String> list = new ArrayList<>();
list.add("16101");
list.add("16102");
list.add("16103");
data1.setEmployeeIds(list);
map1.put(new ObjectId("5976ef15874c902c98b8a05d"), data1);
Project data2 = new Project();
data2.setId(new ObjectId("9976ef15874c902c98b8a05d"));
data2.setProjectId("102");
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;
} */
}
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();
}
}
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());
}
}
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();
}
}
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();
}
}
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");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment