Commit 963f6644 authored by Rajeshekar's avatar Rajeshekar

Fixed the compilation errors in test cases and now the build is

successful
parent ac5da2a9
......@@ -53,68 +53,94 @@ public class ProjectControllerTest {
mockMvc = MockMvcBuilders.standaloneSetup(projectController).build();
}
@Test
public void testgetEmployeeRole() throws Exception{
EmployeeRoles employeesRole = new EmployeeRoles("5976ef15874c902c98b8a05d",null,null,"user@nisum.com",null, null,null,null,null,null,null,null,null, new Date(2017-11-12),new Date(2017-12-12));
when(userService.getEmployeesRole("user@nisum.com")).thenReturn(employeesRole);
mockMvc.perform(get("/project/employee").param("emailId", "user@nisum.com")).andExpect(MockMvcResultMatchers.status().isOk());
public void testgetEmployeeRole() throws Exception {
EmployeeRoles employeesRole = new EmployeeRoles(
"5976ef15874c902c98b8a05d", null, null, "user@nisum.com", null,
null, null, null, null, null, null, null, null, null, null,
null, null, new Date(2017 - 11 - 12), new Date(2017 - 12 - 12));
when(userService.getEmployeesRole("user@nisum.com"))
.thenReturn(employeesRole);
mockMvc.perform(
get("/project/employee").param("emailId", "user@nisum.com"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).getEmployeesRole("user@nisum.com");
}
@Test
public void testaddProject() throws Exception{
public void testaddProject() throws Exception {
List<String> list = new ArrayList<>();
list.add("16101");
list.add("16102");
list.add("16103");
Project employeeRole1 = new Project(new ObjectId ("9976ef15874c902c98b8a05d"),"102","OMS","16101","Srikanth","Macys","Billable",list);
String jsonvalue =(new ObjectMapper()).writeValueAsString(employeeRole1).toString();
Account account = new Account(new ObjectId("5a4f03661dca211ea7f94c02"),"2", "Macys", 0,"Y");
when(projectService.addProject(employeeRole1)).thenReturn(employeeRole1);
Project employeeRole1 = new Project(
new ObjectId("9976ef15874c902c98b8a05d"), "102", "OMS", "16101",
"Srikanth", "Macys", "Billable", list);
String jsonvalue = (new ObjectMapper())
.writeValueAsString(employeeRole1).toString();
Account account = new Account(new ObjectId("5a4f03661dca211ea7f94c02"),
"2", "Macys", 0, "Y");
when(projectService.addProject(employeeRole1))
.thenReturn(employeeRole1);
when(accountRepo.findByAccountName("Macys")).thenReturn(account);
mockMvc.perform(post("/project/addProject").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonvalue)).andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(post("/project/addProject")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonvalue))
.andExpect(MockMvcResultMatchers.status().isOk());
}
@Test
public void testupdateEmployeeRole() throws Exception{
public void testupdateEmployeeRole() throws Exception {
List<String> list1 = new ArrayList<>();
list1.add("16104");
list1.add("16105");
list1.add("16106");
Project project = new Project(new ObjectId ("5976ef15874c902c98b8a05d"),"101","MOSAIC","16100","Rajeshekar","Gap","Billable",list1);
Project project = new Project(new ObjectId("5976ef15874c902c98b8a05d"),
"101", "MOSAIC", "16100", "Rajeshekar", "Gap", "Billable",
list1);
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(project);
when(projectService.updateProject(any())).thenReturn(project);
mockMvc.perform(post("/project/updateProject").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString)).andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(post("/project/updateProject")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonString))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(projectService).updateProject(any());
}
@Test
public void testdeleteProject() throws Exception{
mockMvc.perform(delete("/project/deleteProject").param("projectId", "101")).andExpect(MockMvcResultMatchers.status().isOk());
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{
public void testgetProjects() throws Exception {
List<Project> projects = CreateProjectDetails();
when(projectService.getProjects()).thenReturn(projects);
mockMvc.perform(get("/project/getProjects").contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(get("/project/getProjects")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(projectService).getProjects();
}
@Test
public void testgetEmployeeRoleData() throws Exception{
EmployeeRoles employeesRole = new EmployeeRoles("5976ef15874c902c98b8a05d","16127",null,null,null,null, null,null,null,null,null,null,null, new Date(2017-11-18),new Date(2017-12-18));
when(userService.getEmployeesRoleData("16127")).thenReturn(employeesRole);
mockMvc.perform(get("/project/getEmployeeRoleData").param("empId", "16127").contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(MockMvcResultMatchers.status().isOk());
public void testgetEmployeeRoleData() throws Exception {
EmployeeRoles employeesRole = new EmployeeRoles(
"5976ef15874c902c98b8a05d", "16127", null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, new Date(2017 - 11 - 18), new Date(2017 - 12 - 18));
when(userService.getEmployeesRoleData("16127"))
.thenReturn(employeesRole);
mockMvc.perform(
get("/project/getEmployeeRoleData").param("empId", "16127")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).getEmployeesRoleData("16127");
}
private List<Project> CreateProjectDetails() {
List<Project> data = new ArrayList<>();
......@@ -132,7 +158,6 @@ public class ProjectControllerTest {
list.add("16103");
data1.setEmployeeIds(list);
Project data2 = new Project();
data2.setId(new ObjectId("9976ef15874c902c98b8a05d"));
data2.setProjectId("102");
......
......@@ -6,9 +6,11 @@ import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.bson.types.ObjectId;
import org.junit.Before;
import org.junit.Test;
......@@ -19,6 +21,7 @@ import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nisum.mytime.controller.ProjectTeamController;
import com.nisum.mytime.model.EmployeeRoles;
......@@ -44,15 +47,20 @@ public class ProjectTeamControllerTest {
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mockMvc = MockMvcBuilders.standaloneSetup(projectTeamController).build();
mockMvc = MockMvcBuilders.standaloneSetup(projectTeamController)
.build();
}
@Test
public void testgetEmployeeRole() throws Exception {
EmployeeRoles employeesRole = new EmployeeRoles("5976ef15874c902c98b8a05d", null, null, null, null, null, null,
null, null, "user@nisum.com", null, null,null, new Date(2017 - 11 - 20), new Date(2107 - 12 - 23));
when(userService.getEmployeesRole("user@nisum.com")).thenReturn(employeesRole);
mockMvc.perform(get("/projectTeam/employee").param("emailId", "user@nisum.com"))
EmployeeRoles employeesRole = new EmployeeRoles(
"5976ef15874c902c98b8a05d", null, null, null, null, null, null,
null, null, null, null, null, null, "user@nisum.com", null,
null, null, new Date(2017 - 11 - 20), new Date(2107 - 12 - 23));
when(userService.getEmployeesRole("user@nisum.com"))
.thenReturn(employeesRole);
mockMvc.perform(
get("/projectTeam/employee").param("emailId", "user@nisum.com"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).getEmployeesRole("user@nisum.com");
}
......@@ -63,42 +71,57 @@ public class ProjectTeamControllerTest {
list.add("16101");
list.add("16102");
list.add("16103");
Project employeeRole1 = new Project(new ObjectId("9976ef15874c902c98b8a05d"), "102", "OMS", "16101", "Srikanth",
"Gap", "Billable", list);
String jsonvalue = (new ObjectMapper()).writeValueAsString(employeeRole1).toString();
when(projectService.addProject(employeeRole1)).thenReturn(employeeRole1);
mockMvc.perform(
post("/projectTeam/addProject").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonvalue))
Project employeeRole1 = new Project(
new ObjectId("9976ef15874c902c98b8a05d"), "102", "OMS", "16101",
"Srikanth", "Gap", "Billable", list);
String jsonvalue = (new ObjectMapper())
.writeValueAsString(employeeRole1).toString();
when(projectService.addProject(employeeRole1))
.thenReturn(employeeRole1);
mockMvc.perform(post("/projectTeam/addProject")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonvalue))
.andExpect(MockMvcResultMatchers.status().isOk());
}
@Test
public void testupdateEmployeeRole() throws Exception {
EmployeeRoles employeesRoles2 = new EmployeeRoles("1976ef15874c902c98b8a05d", "16111", "Vinay Singh",
"vsingh@nisum.com", "Manager", null, "09:00-06:00", "Java/J2EE", "Testing", "8755672341", "8800543678",
"vsingh@gmail.com", null, new Date(2017 - 11 - 29), new Date(2017 - 12 - 20));
EmployeeRoles employeesRoles2 = new EmployeeRoles(
"1976ef15874c902c98b8a05d", "16111", "Vinay Singh",
"vsingh@nisum.com", "Manager", null, "09:00-06:00", "Java/J2EE",
"Testing", "8755672341", "8800543678", "vsingh@gmail.com", null,
null, null, null, null, new Date(2017 - 11 - 29),
new Date(2017 - 12 - 20));
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(employeesRoles2);
when(userService.updateEmployeeRole(any())).thenReturn(employeesRoles2);
mockMvc.perform(post("/projectTeam/updateEmployeeRole").contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonString)).andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(post("/projectTeam/updateEmployeeRole")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonString))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).updateEmployeeRole(any());
}
@Test
public void testdeleteEmployee() throws Exception {
mockMvc.perform(delete("/projectTeam/deleteEmployee").param("empId", "16157"))
mockMvc.perform(
delete("/projectTeam/deleteEmployee").param("empId", "16157"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).deleteEmployee("16157");
}
@Test
public void testgetEmployeeRoleData() throws Exception {
EmployeeRoles employeesRole = new EmployeeRoles("5976ef15874c902c98b8a05d", "16127", null, null, null, null,
null, null, null, null, null, null, null, new Date(2017 - 11 - 20), new Date(2107 - 12 - 23));
when(userService.getEmployeesRoleData("16127")).thenReturn(employeesRole);
mockMvc.perform(get("/projectTeam/getEmployeeRoleData").param("empId", "16127")
.contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(MockMvcResultMatchers.status().isOk());
EmployeeRoles employeesRole = new EmployeeRoles(
"5976ef15874c902c98b8a05d", "16127", null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, new Date(2017 - 11 - 20), new Date(2107 - 12 - 23));
when(userService.getEmployeesRoleData("16127"))
.thenReturn(employeesRole);
mockMvc.perform(
get("/projectTeam/getEmployeeRoleData").param("empId", "16127")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).getEmployeesRoleData("16127");
}
......@@ -106,7 +129,8 @@ public class ProjectTeamControllerTest {
public void testgetManagers() throws Exception {
List<EmployeeRoles> employeesRoles = createEmployeeRoles();
when(userService.getEmployeeRoles()).thenReturn(employeesRoles);
mockMvc.perform(get("/projectTeam/getEmployeesToTeam")).andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(get("/projectTeam/getEmployeesToTeam"))
.andExpect(MockMvcResultMatchers.status().isOk());
}
......@@ -114,52 +138,72 @@ public class ProjectTeamControllerTest {
public void testgetTeamDetails() throws Exception {
List<ProjectTeamMate> employeesRoles = createProjectTeamMate();
when(projectService.getTeamDetails("16127")).thenReturn(employeesRoles);
mockMvc.perform(get("/projectTeam/getTeamDetails").param("employeeId", "16127"))
mockMvc.perform(
get("/projectTeam/getTeamDetails").param("employeeId", "16127"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(projectService).getTeamDetails("16127");
}
@Test
public void testaddEmployeeToTeam() throws Exception {
ProjectTeamMate projectTeamMate = new ProjectTeamMate(new ObjectId("1976ef15874c902c98b8a05d"), "16127",
"Monika Srivastava", "msrivastava@nisum.com", "Employee", "09:00-06:00", "101", "MOSAIC", "GAP",
"16081", "Rajeshekar", "01", "Software Engineer", "Non-Billable", "8765588388",new Date(),new Date(), true);
String jsonvalue = (new ObjectMapper()).writeValueAsString(projectTeamMate).toString();
when(projectService.addProjectTeamMate(projectTeamMate)).thenReturn(projectTeamMate);
mockMvc.perform(
post("/projectTeam/addEmployeeToTeam").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonvalue))
ProjectTeamMate projectTeamMate = new ProjectTeamMate(
new ObjectId("1976ef15874c902c98b8a05d"), "16127",
"Monika Srivastava", "msrivastava@nisum.com", "Employee",
"09:00-06:00", "101", "MOSAIC", "GAP", "16081", "Rajeshekar",
"01", "Software Engineer", "Non-Billable", "8765588388",
new Date(), new Date(), true);
String jsonvalue = (new ObjectMapper())
.writeValueAsString(projectTeamMate).toString();
when(projectService.addProjectTeamMate(projectTeamMate))
.thenReturn(projectTeamMate);
mockMvc.perform(post("/projectTeam/addEmployeeToTeam")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonvalue))
.andExpect(MockMvcResultMatchers.status().isOk());
}
@Test
public void testupdateTeammate() throws Exception {
ProjectTeamMate updatedTeammate = new ProjectTeamMate(new ObjectId("1976ef15874c902c98b8a05d"), "16127",
"Monika Srivastava", "msrivastava@nisum.com", "Employee", "09:00-06:00", "101", "MOSAIC", "GAP",
"16081", "Rajeshekar", "01", "Software Engineer", "Non-Billable", "8765588388",new Date(),new Date(), true);
String jsonvalue = (new ObjectMapper()).writeValueAsString(updatedTeammate).toString();
when(projectService.updateTeammate(updatedTeammate)).thenReturn(updatedTeammate);
mockMvc.perform(
post("/projectTeam/updateTeammate").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonvalue))
ProjectTeamMate updatedTeammate = new ProjectTeamMate(
new ObjectId("1976ef15874c902c98b8a05d"), "16127",
"Monika Srivastava", "msrivastava@nisum.com", "Employee",
"09:00-06:00", "101", "MOSAIC", "GAP", "16081", "Rajeshekar",
"01", "Software Engineer", "Non-Billable", "8765588388",
new Date(), new Date(), true);
String jsonvalue = (new ObjectMapper())
.writeValueAsString(updatedTeammate).toString();
when(projectService.updateTeammate(updatedTeammate))
.thenReturn(updatedTeammate);
mockMvc.perform(post("/projectTeam/updateTeammate")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonvalue))
.andExpect(MockMvcResultMatchers.status().isOk());
}
@Test
public void testdeleteTeammate() throws Exception {
ProjectTeamMate deleteTeamMate = new ProjectTeamMate(new ObjectId("1976ef15874c902c98b8a05d"), "16127",
"Monika Srivastava", "msrivastava@nisum.com", "Employee", "09:00-06:00", "101", "MOSAIC", "GAP",
"16081", "Rajeshekar", "01", "Software Engineer", "Non-Billable", "8765588388",new Date(),new Date(), true);
String jsonvalue = (new ObjectMapper()).writeValueAsString(deleteTeamMate).toString();
mockMvc.perform(
post("/projectTeam/deleteTeammate").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonvalue))
ProjectTeamMate deleteTeamMate = new ProjectTeamMate(
new ObjectId("1976ef15874c902c98b8a05d"), "16127",
"Monika Srivastava", "msrivastava@nisum.com", "Employee",
"09:00-06:00", "101", "MOSAIC", "GAP", "16081", "Rajeshekar",
"01", "Software Engineer", "Non-Billable", "8765588388",
new Date(), new Date(), true);
String jsonvalue = (new ObjectMapper())
.writeValueAsString(deleteTeamMate).toString();
mockMvc.perform(post("/projectTeam/deleteTeammate")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonvalue))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(projectService).deleteTeammate("16127", "101", new ObjectId("1976ef15874c902c98b8a05d"));
verify(projectService).deleteTeammate("16127", "101",
new ObjectId("1976ef15874c902c98b8a05d"));
}
@Test
public void testgetProjects() throws Exception {
List<Project> projects = CreateProjectDetails();
when(projectService.getProjects("16127")).thenReturn(projects);
mockMvc.perform(get("/projectTeam/getProjects").param("employeeId", "16127"))
mockMvc.perform(
get("/projectTeam/getProjects").param("employeeId", "16127"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(projectService).getProjects("16127");
}
......@@ -167,25 +211,30 @@ public class ProjectTeamControllerTest {
@Test
public void testgetMyTeamDetails() throws Exception {
List<ProjectTeamMate> employeesRoles = createProjectTeamMate();
when(projectService.getMyTeamDetails("16127")).thenReturn(employeesRoles);
mockMvc.perform(get("/projectTeam/getMyTeamDetails").param("employeeId", "16127"))
.andExpect(MockMvcResultMatchers.status().isOk());
when(projectService.getMyTeamDetails("16127"))
.thenReturn(employeesRoles);
mockMvc.perform(get("/projectTeam/getMyTeamDetails").param("employeeId",
"16127")).andExpect(MockMvcResultMatchers.status().isOk());
verify(projectService).getMyTeamDetails("16127");
}
@Test
public void testgetUnAssignedEmployees() throws Exception {
List<EmployeeRoles> employeesRoles = createEmployeeRoles();
when(projectService.getUnAssignedEmployees()).thenReturn(employeesRoles);
mockMvc.perform(get("/projectTeam/getUnAssignedEmployees")).andExpect(MockMvcResultMatchers.status().isOk());
when(projectService.getUnAssignedEmployees())
.thenReturn(employeesRoles);
mockMvc.perform(get("/projectTeam/getUnAssignedEmployees"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(projectService).getUnAssignedEmployees();
}
@Test
public void testgetShiftDetails() throws Exception {
List<ProjectTeamMate> employeesRoles = createProjectTeamMate();
when(projectService.getShiftDetails("09:00-06:00")).thenReturn(employeesRoles);
mockMvc.perform(get("/projectTeam/getShiftDetails").param("shift", "09:00-06:00"))
when(projectService.getShiftDetails("09:00-06:00"))
.thenReturn(employeesRoles);
mockMvc.perform(get("/projectTeam/getShiftDetails").param("shift",
"09:00-06:00"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(projectService).getShiftDetails("09:00-06:00");
}
......@@ -194,34 +243,42 @@ public class ProjectTeamControllerTest {
public void testgetProjectAllocations() throws Exception {
List<ProjectTeamMate> employeesRoles = createProjectTeamMate();
when(projectService.getAllProjectDetails()).thenReturn(employeesRoles);
mockMvc.perform(get("/projectTeam/getProjectAllocations")).andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(get("/projectTeam/getProjectAllocations"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(projectService).getAllProjectDetails();
}
@Test
public void testgetProjectDetails() throws Exception {
List<ProjectTeamMate> employeesRoles = createProjectTeamMate();
when(projectService.getProjectDetails("101")).thenReturn(employeesRoles);
mockMvc.perform(get("/projectTeam/getProjectDetails").param("projectId", "101"))
when(projectService.getProjectDetails("101"))
.thenReturn(employeesRoles);
mockMvc.perform(
get("/projectTeam/getProjectDetails").param("projectId", "101"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(projectService).getProjectDetails("101");
}
@Test
public void testgetMyProjectAllocations() throws Exception{
List<ProjectTeamMate> projectAllocations=createProjectTeamMate();
public void testgetMyProjectAllocations() throws Exception {
List<ProjectTeamMate> projectAllocations = createProjectTeamMate();
System.out.println(projectAllocations);
when(projectService.getMyProjectAllocations("16127")).thenReturn(projectAllocations);
mockMvc.perform(get("/projectTeam/getMyProjectAllocations").param("employeeId", "16127")).andExpect(MockMvcResultMatchers.status().isOk());
when(projectService.getMyProjectAllocations("16127"))
.thenReturn(projectAllocations);
mockMvc.perform(get("/projectTeam/getMyProjectAllocations")
.param("employeeId", "16127"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(projectService).getMyProjectAllocations("16127");
}
@Test
public void testgetEmployeeBillingDetails() throws Exception{
List<TeamMateBilling> billings=CreateTeamMateBilling();
public void testgetEmployeeBillingDetails() throws Exception {
List<TeamMateBilling> billings = CreateTeamMateBilling();
System.out.println(billings);
when(projectService.getEmployeeBillingDetails("16127", "101")).thenReturn(billings);
mockMvc.perform(get("/projectTeam/getEmployeeBillingDetails").param("employeeId", "16127").param("projectId", "101"))
when(projectService.getEmployeeBillingDetails("16127", "101"))
.thenReturn(billings);
mockMvc.perform(get("/projectTeam/getEmployeeBillingDetails")
.param("employeeId", "16127").param("projectId", "101"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(projectService).getEmployeeBillingDetails("16127", "101");
}
......@@ -235,8 +292,8 @@ public class ProjectTeamControllerTest {
team1.setEmployeeName("Employee1");
team1.setProjectId("101");
team1.setProjectName("MOSAIC");
team1.setBillingStartDate(new Date(2017-01-10));
team1.setBillingEndDate(new Date(2017-02-10));
team1.setBillingStartDate(new Date(2017 - 01 - 10));
team1.setBillingEndDate(new Date(2017 - 02 - 10));
team1.setActive(true);
data.add(team1);
......@@ -246,8 +303,8 @@ public class ProjectTeamControllerTest {
team2.setEmployeeName("Employee2");
team2.setProjectId("102");
team2.setProjectName("OMS");
team2.setBillingStartDate(new Date(2017-01-15));
team2.setBillingEndDate(new Date(2017-02-15));
team2.setBillingStartDate(new Date(2017 - 01 - 15));
team2.setBillingEndDate(new Date(2017 - 02 - 15));
team2.setActive(false);
data.add(team2);
......
......@@ -9,9 +9,11 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.bson.types.ObjectId;
import org.junit.Before;
import org.junit.Test;
......@@ -22,6 +24,7 @@ import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nisum.mytime.controller.UserController;
import com.nisum.mytime.model.Account;
......@@ -49,37 +52,52 @@ public class UserControllerTest {
@Test
public void testgetEmployeeRole() throws Exception {
EmployeeRoles employeesRole = new EmployeeRoles("5976ef15874c902c98b8a05d", null, null,
"user@nisum.com", null,null,null,null,null,null,null, null, null,new Date(2017-11-20),new Date(2017-12-23));
when(userService.getEmployeesRole("user@nisum.com")).thenReturn(employeesRole);
mockMvc.perform(get("/user/employee").param("emailId", "user@nisum.com"))
EmployeeRoles employeesRole = new EmployeeRoles(
"5976ef15874c902c98b8a05d", null, null, "user@nisum.com", null,
null, null, null, null, null, null, null, null, null, null,
null, null, new Date(2017 - 11 - 20), new Date(2017 - 12 - 23));
when(userService.getEmployeesRole("user@nisum.com"))
.thenReturn(employeesRole);
mockMvc.perform(
get("/user/employee").param("emailId", "user@nisum.com"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).getEmployeesRole("user@nisum.com");
}
@Test
public void testassigingEmployeeRole() throws Exception {
EmployeeRoles employeeRole = new EmployeeRoles("5976ef15874c902c98b8a05c", "16135", "Monika",
"user1@nisum.com", "HR","Human Resource Lead", "06:00-09:00","Java/J2EE","Spring","8767893452","5687234567","user1@gmail.com", null,new Date(2017-11-20),new Date(2017-12-23));
EmployeeRoles employeeRole = new EmployeeRoles(
"5976ef15874c902c98b8a05c", "16135", "Monika",
"user1@nisum.com", "HR", "Human Resource Lead", "06:00-09:00",
"Java/J2EE", "Spring", "8767893452", "5687234567",
"user1@gmail.com", null, null, null, null, null,
new Date(2017 - 11 - 20), new Date(2017 - 12 - 23));
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(employeeRole);
when(userService.assigingEmployeeRole(anyObject())).thenReturn(employeeRole);
mockMvc.perform(
post("/user/assignEmployeeRole").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString))
when(userService.assigingEmployeeRole(anyObject()))
.thenReturn(employeeRole);
mockMvc.perform(post("/user/assignEmployeeRole")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonString))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).assigingEmployeeRole(anyObject());
}
@Test
public void testupdateEmployeeRole() throws Exception {
EmployeeRoles employeeRole2 = new EmployeeRoles("5976ef15874c902c98b8a05d", "67890", "Sonika",
"user2@nisum.com", "Manager","Senior Software Engineer", "09:00am-06:00am","php","Hibernate","9878678956","9989782210","user2@gmail.com", null,new Date(2017-11-20),new Date(2017-12-23));
EmployeeRoles employeeRole2 = new EmployeeRoles(
"5976ef15874c902c98b8a05d", "67890", "Sonika",
"user2@nisum.com", "Manager", "Senior Software Engineer",
"09:00am-06:00am", "php", "Hibernate", "9878678956",
"9989782210", "user2@gmail.com", null, null, null, null, null,
new Date(2017 - 11 - 20), new Date(2017 - 12 - 23));
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(employeeRole2);
when(userService.updateEmployeeRole(anyObject())).thenReturn(employeeRole2);
mockMvc.perform(
post("/user/updateEmployeeRole").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString))
when(userService.updateEmployeeRole(anyObject()))
.thenReturn(employeeRole2);
mockMvc.perform(post("/user/updateEmployeeRole")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonString))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).updateEmployeeRole(anyObject());
}
......@@ -95,57 +113,92 @@ public class UserControllerTest {
public void testgetUserRoles() throws Exception {
List<EmployeeRoles> employeesRole3 = CreateUserRoles();
when(userService.getEmployeeRoles()).thenReturn(employeesRole3);
mockMvc.perform(get("/user/getUserRoles").contentType(MediaType.APPLICATION_JSON_VALUE))
mockMvc.perform(get("/user/getUserRoles")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).getEmployeeRoles();
}
@Test
public void testgetEmployeeRoleData() throws Exception {
EmployeeRoles employeesRole = new EmployeeRoles("5976ef15874c902c98b8a05d", "16127",null, null, null,
null, null,null,null,null,null,null, null,new Date(2017-11-13),new Date(2017-12-20));
when(userService.getEmployeesRoleData("16127")).thenReturn(employeesRole);
mockMvc.perform(get("/user/getEmployeeRoleData").param("empId", "16127").contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk()).andExpect(jsonPath("$.employeeId", is("16127")))
EmployeeRoles employeesRole = new EmployeeRoles(
"5976ef15874c902c98b8a05d", "16127", null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, new Date(2017 - 11 - 13), new Date(2017 - 12 - 20));
when(userService.getEmployeesRoleData("16127"))
.thenReturn(employeesRole);
mockMvc.perform(get("/user/getEmployeeRoleData").param("empId", "16127")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(jsonPath("$.employeeId", is("16127")))
.andDo(print());
verify(userService).getEmployeesRoleData("16127");
}
@Test
public void testgetEmployeeRoleDataForEmailIdSearch() throws Exception {
EmployeeRoles employeesRole = new EmployeeRoles("5976ef15874c902c98b8a05d", "16209", null, null, null, null,
null, null, null, null, null, null, null, new Date(2017 - 11 - 13), new Date(2017 - 12 - 20));
when(userService.getEmployeeRoleDataForSearchCriteria("dummy@nisum.com", "emailId")).thenReturn(employeesRole);
mockMvc.perform(get("/user/getEmployeeRoleDataForSearchCriteria").param("searchId", "dummy@nisum.com")
.param("searchAttribute", "emailId").contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk()).andExpect(jsonPath("$.employeeId", is("16209")))
EmployeeRoles employeesRole = new EmployeeRoles(
"5976ef15874c902c98b8a05d", "16209", null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, new Date(2017 - 11 - 13), new Date(2017 - 12 - 20));
when(userService.getEmployeeRoleDataForSearchCriteria("dummy@nisum.com",
"emailId")).thenReturn(employeesRole);
mockMvc.perform(get("/user/getEmployeeRoleDataForSearchCriteria")
.param("searchId", "dummy@nisum.com")
.param("searchAttribute", "emailId")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(jsonPath("$.employeeId", is("16209")))
.andDo(print());
verify(userService).getEmployeeRoleDataForSearchCriteria("dummy@nisum.com", "emailId");
verify(userService).getEmployeeRoleDataForSearchCriteria(
"dummy@nisum.com", "emailId");
}
@Test
public void testgetEmployeeRoleDataForEmployeeNameSearch() throws Exception {
EmployeeRoles employeesRole = new EmployeeRoles("5976ef15874c902c98b8a05d", "16209", null, null, null, null,
null, null, null, null, null, null, null, new Date(2017 - 11 - 13), new Date(2017 - 12 - 20));
when(userService.getEmployeeRoleDataForSearchCriteria("Mahesh Kumar Gutam", "employeeName")).thenReturn(employeesRole);
mockMvc.perform(get("/user/getEmployeeRoleDataForSearchCriteria").param("searchId", "Mahesh Kumar Gutam")
.param("searchAttribute", "employeeName").contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk()).andExpect(jsonPath("$.employeeId", is("16209")))
public void testgetEmployeeRoleDataForEmployeeNameSearch()
throws Exception {
EmployeeRoles employeesRole = new EmployeeRoles(
"5976ef15874c902c98b8a05d", "16209", null, null, null, null,
null, null, null, null, null, null, null, null, null, null,
null, new Date(2017 - 11 - 13), new Date(2017 - 12 - 20));
when(userService.getEmployeeRoleDataForSearchCriteria(
"Mahesh Kumar Gutam", "employeeName"))
.thenReturn(employeesRole);
mockMvc.perform(get("/user/getEmployeeRoleDataForSearchCriteria")
.param("searchId", "Mahesh Kumar Gutam")
.param("searchAttribute", "employeeName")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(jsonPath("$.employeeId", is("16209")))
.andDo(print());
verify(userService).getEmployeeRoleDataForSearchCriteria("Mahesh Kumar Gutam", "employeeName");
verify(userService).getEmployeeRoleDataForSearchCriteria(
"Mahesh Kumar Gutam", "employeeName");
}
@Test
public void testGetEmployeeDetailsForAutocomplete() throws Exception {
List<String> details = new ArrayList<>();
details.add("16294");details.add("Ashwin Kumar"); details.add("kashwin@nisum.com");
details.add("16209");details.add("Mahesh Kumar Gutam");details.add("mgutam@nisum.com");
details.add("16143");details.add("Ajay");details.add("ajayS@nisum.com");
details.add("16207");details.add("Sumith Kumar Lambu");details.add("slambu@nisum.com");
details.add("16111");details.add("Mahesh Mudrakolu");details.add("mmahesh@nisum.com");
when(userService.getEmployeeDetailsForAutocomplete()).thenReturn(details);
mockMvc.perform(get("/user/getEmployeeDetailsForAutocomplete").contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk()).andDo(print());
details.add("16294");
details.add("Ashwin Kumar");
details.add("kashwin@nisum.com");
details.add("16209");
details.add("Mahesh Kumar Gutam");
details.add("mgutam@nisum.com");
details.add("16143");
details.add("Ajay");
details.add("ajayS@nisum.com");
details.add("16207");
details.add("Sumith Kumar Lambu");
details.add("slambu@nisum.com");
details.add("16111");
details.add("Mahesh Mudrakolu");
details.add("mmahesh@nisum.com");
when(userService.getEmployeeDetailsForAutocomplete())
.thenReturn(details);
mockMvc.perform(get("/user/getEmployeeDetailsForAutocomplete")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(print());
verify(userService).getEmployeeDetailsForAutocomplete();
}
......@@ -154,60 +207,73 @@ public class UserControllerTest {
List<EmployeeRoles> employeesRole4 = CreateUserRoles();
System.out.println(employeesRole4);
when(userService.getEmployeeRoles()).thenReturn(employeesRole4);
mockMvc.perform(get("/user/getManagers")).andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(get("/user/getManagers"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).getEmployeeRoles();
}
@Test
public void testgetAllShifts() throws Exception{
public void testgetAllShifts() throws Exception {
List<Shift> shifts = CreateShifts();
when(userService.getAllShifts()).thenReturn(shifts);
mockMvc.perform(get("/user/getAllShifts")).andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(get("/user/getAllShifts"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).getAllShifts();
}
@Test
public void testgetAllDesignations() throws Exception{
public void testgetAllDesignations() throws Exception {
List<Designation> designation = CreateDesignations();
when(userService.getAllDesignations()).thenReturn(designation);
mockMvc.perform(get("/user/getAllDesignations")).andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(get("/user/getAllDesignations"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).getAllDesignations();
}
@Test
public void testgetTechnologies() throws Exception{
List<Skill> skills=CreateSkill();
public void testgetTechnologies() throws Exception {
List<Skill> skills = CreateSkill();
System.out.println(skills);
when(userService.getTechnologies()).thenReturn(skills);
mockMvc.perform(get("/user/getSkills")).andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(get("/user/getSkills"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).getTechnologies();
}
@Test
public void testupdateProfile() throws Exception{
EmployeeRoles employeeRole = new EmployeeRoles("5996ef15874c902c98b8a05d", "16127", "Monika Srivastava", "msrivastava@nisum.com", "Employee", "Software Engineer", "09:00-06:00", "Java/J2EE", "Spring", "8765588388", "9978567723", "msrivastava@gmail.com", null, new Date(2017-01-01), new Date(2017-03-01));
public void testupdateProfile() throws Exception {
EmployeeRoles employeeRole = new EmployeeRoles(
"5996ef15874c902c98b8a05d", "16127", "Monika Srivastava",
"msrivastava@nisum.com", "Employee", "Software Engineer",
"09:00-06:00", "Java/J2EE", "Spring", "8765588388",
"9978567723", "msrivastava@gmail.com", null, null, null, null,
null, new Date(2017 - 01 - 01), new Date(2017 - 03 - 01));
System.out.println(employeeRole);
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(employeeRole);
System.out.println(jsonString);
when(userService.updateProfile(anyObject())).thenReturn(employeeRole);
mockMvc.perform(post("/user/updateProfile").contentType(MediaType.APPLICATION_JSON_VALUE).content(jsonString)).andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(post("/user/updateProfile")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(jsonString))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).updateProfile(anyObject());
}
@Test
public void getAccounts() throws Exception{
public void getAccounts() throws Exception {
List<Account> account = CreateAccount();
System.out.println(account);
when(userService.getAccounts()).thenReturn(account);
mockMvc.perform(get("/user/getAccounts")).andExpect(MockMvcResultMatchers.status().isOk());
mockMvc.perform(get("/user/getAccounts"))
.andExpect(MockMvcResultMatchers.status().isOk());
verify(userService).getAccounts();
}
private List<Account> CreateAccount() {
List<Account> data = new ArrayList<>();
Account account1=new Account();
Account account1 = new Account();
account1.setId(new ObjectId("5976ef15874c902c98b8a05d"));
account1.setAccountId("01");
account1.setAccountName("GAP");
......@@ -215,7 +281,7 @@ public class UserControllerTest {
account1.setStatus("Active");
data.add(account1);
Account account2=new Account();
Account account2 = new Account();
account2.setId(new ObjectId("2476ef15874c902c98b8a05d"));
account2.setAccountId("02");
account2.setAccountName("MACYS");
......@@ -229,14 +295,14 @@ public class UserControllerTest {
private List<Skill> CreateSkill() {
List<Skill> data = new ArrayList<>();
Skill skills1=new Skill();
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();
Skill skills2 = new Skill();
skills2.setId(new ObjectId("2476ef15874c902c98b8a05d"));
skills2.setSkillId("02");
skills2.setSkillName("Big Data");
......@@ -249,14 +315,14 @@ public class UserControllerTest {
private List<Designation> CreateDesignations() {
List<Designation> data = new ArrayList<>();
Designation desig1=new Designation();
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();
Designation desig2 = new Designation();
desig2.setId(new ObjectId("2476ef15874c902c98b8a05d"));
desig2.setDesignationId("02");
desig2.setDesignationName("Employee");
......@@ -268,14 +334,14 @@ public class UserControllerTest {
private List<Shift> CreateShifts() {
List<Shift> data = new ArrayList<>();
Shift shift1=new Shift();
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();
Shift shift2 = new Shift();
shift2.setId(new ObjectId("2476ef15874c902c98b8a05d"));
shift2.setShiftId("02");
shift2.setShiftName("Night Shift");
......@@ -300,8 +366,8 @@ public class UserControllerTest {
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));
data1.setCreatedOn(new Date(2017 - 11 - 21));
data1.setLastModifiedOn(new Date(2017 - 12 - 22));
EmployeeRoles data2 = new EmployeeRoles();
data2.setId("4976ef15874c902c98b8a05d");
......@@ -316,8 +382,8 @@ public class UserControllerTest {
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));
data2.setCreatedOn(new Date(2017 - 11 - 23));
data2.setLastModifiedOn(new Date(2017 - 12 - 22));
data.add(data1);
data.add(data2);
......
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