EmployeeParametersExtractor extends AbstractParametersExtractor<Employee> { @Override public Map<String, Object> getParameters(final Employee entity, final Map<String, Object> parameters) { addParameter(entity.getEmployeeType(), employeeTypeDao, "employeeType", parameters); addParameter(entity.getEmployeeStatus(), employeeStatusDao, "employeeStatus", parameters); addParameter(entity.getPerson(), personDao, "person", parameters); addParameter(entity.getGenderType(), genderTypeDao, "genderType", parameters); addParameter(entity.getDepartment(), departmentDao, "department", parameters); addParameter(entity.getPost(), postDao, "post", parameters); addParameter(entity.getJobType(), jobTypeDao, "jobType", parameters); addParameter(entity.getOrder(), orderDao, "order", parameters); addParameter(entity.getParent(), employeeDao, "parent", parameters); addParameter(entity.getName(), "name", parameters); addParameter(entity.getFirstName(), "firstName", parameters); addParameter(entity.getFatherName(), "fatherName", parameters); addParameter(entity.getSurname(), "surname", parameters); addParameter(entity.getBirthDate(), "birthDate", parameters); addParameter(entity.getInvNum(), "invNum", parameters); addParameter(entity.getRate(), "rate", parameters); addParameter(entity.getIsPlurality(), "isPlurality", parameters); addParameter(entity.getIsPensioner(), "isPensioner", parameters); addParameter(entity.getBegDate(), "begDate", parameters); addParameter(entity.getEndDate(), "endDate", parameters); addParameter(entity.getDocSeries(), "docSeries", parameters); addParameter(entity.getDocNum(), "docNum", parameters); addParameter(entity.getPhone(), "phone", parameters); addParameter(entity.getEmail(), "email", parameters); return parameters; }  @Override Map<String, Object> getParameters(final Employee entity, final Map<String, Object> parameters);  }
@Test public void testGetParameters() throws Exception { String docNum = "doc num"; String email = "email@email.com"; Date begDate = new Date(); Date birthDate = new Date(); String docSeries = "doc series"; String surname = "surname"; Double rate = 1.0; String phone = "phone"; String name = "name"; Integer isPlurality = 11; Integer isPensioner = 12; String invNum = "invNum"; String firstName = "first name"; String fatherName = "father name"; Date endDate = new Date(); Department department = new Department(); department.setId(1L); Employee entity = new Employee(); EmployeeStatus employeeStatus = new EmployeeStatus(); employeeStatus.setId(4L); EmployeeType employeeType = new EmployeeType(); employeeType.setId(5L); Post post = new Post(); post.setId(7L); Person person = new Person(); person.setId(9L); Employee parent = new Employee(); parent.setId(11L); Order order = new Order(); order.setId(12L); JobType jobType = new JobType(); jobType.setId(13L); GenderType genderType = new GenderType(); genderType.setId(15L); entity.setPost(post); entity.setPerson(person); entity.setParent(parent); entity.setOrder(order); entity.setJobType(jobType); entity.setGenderType(genderType); entity.setEmployeeType(employeeType); entity.setEmployeeStatus(employeeStatus); entity.setDepartment(department); entity.setSurname(surname); entity.setRate(rate); entity.setPhone(phone); entity.setName(name); entity.setIsPlurality(isPlurality); entity.setIsPensioner(isPensioner); entity.setInvNum(invNum); entity.setFirstName(firstName); entity.setFatherName(fatherName); entity.setEndDate(endDate); entity.setDocSeries(docSeries); entity.setDocNum(docNum); entity.setBegDate(begDate); entity.setBirthDate(birthDate); entity.setEmail(email); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("employeeStatus", employeeStatus); expected.put("employeeType", employeeType); expected.put("post", post); expected.put("person", person); expected.put("parent", parent); expected.put("order", order); expected.put("jobType", jobType); expected.put("genderType", genderType); expected.put("department", department); expected.put("surname", surname); expected.put("rate", rate); expected.put("phone", phone); expected.put("name", name); expected.put("isPlurality", isPlurality); expected.put("isPensioner", isPensioner); expected.put("invNum", invNum); expected.put("firstName", firstName); expected.put("fatherName", fatherName); expected.put("endDate", endDate); expected.put("docSeries", docSeries); expected.put("docNum", docNum); expected.put("begDate", begDate); expected.put("birthDate", birthDate); expected.put("email", email); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(departmentDao.getEntityById(anyLong())).thenReturn(department); when(employeeStatusDao.getEntityById(anyLong())).thenReturn(employeeStatus); when(employeeTypeDao.getEntityById(anyLong())).thenReturn(employeeType); when(postDao.getEntityById(anyLong())).thenReturn(post); when(personDao.getEntityById(anyLong())).thenReturn(person); when(employeeDao.getEntityById(anyLong())).thenReturn(parent); when(orderDao.getEntityById(anyLong())).thenReturn(order); when(jobTypeDao.getEntityById(anyLong())).thenReturn(jobType); when(genderTypeDao.getEntityById(anyLong())).thenReturn(genderType); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); String docNum = "doc num"; String email = "email@email.com"; Date begDate = new Date(); Date birthDate = new Date(); String docSeries = "doc series"; String surname = "surname"; Double rate = 1.0; String phone = "phone"; String name = "name"; Integer isPlurality = 11; Integer isPensioner = 12; String invNum = "invNum"; String firstName = "first name"; String fatherName = "father name"; Date endDate = new Date(); Department department = new Department(); department.setId(1L); Employee entity = new Employee(); EmployeeStatus employeeStatus = new EmployeeStatus(); employeeStatus.setId(4L); EmployeeType employeeType = new EmployeeType(); employeeType.setId(5L); Post post = new Post(); post.setId(7L); Person person = new Person(); person.setId(9L); Employee parent = new Employee(); parent.setId(11L); Order order = new Order(); order.setId(12L); JobType jobType = new JobType(); jobType.setId(13L); GenderType genderType = new GenderType(); genderType.setId(15L); entity.setPost(post); entity.setPerson(person); entity.setParent(parent); entity.setOrder(order); entity.setJobType(jobType); entity.setGenderType(genderType); entity.setEmployeeType(employeeType); entity.setEmployeeStatus(employeeStatus); entity.setDepartment(department); entity.setSurname(surname); entity.setRate(rate); entity.setPhone(phone); entity.setName(name); entity.setIsPlurality(isPlurality); entity.setIsPensioner(isPensioner); entity.setInvNum(invNum); entity.setFirstName(firstName); entity.setFatherName(fatherName); entity.setEndDate(endDate); entity.setDocSeries(docSeries); entity.setDocNum(docNum); entity.setBegDate(begDate); entity.setBirthDate(birthDate); entity.setEmail(email); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("employeeStatus", employeeStatus); expected.put("employeeType", employeeType); expected.put("post", post); expected.put("person", person); expected.put("parent", parent); expected.put("order", order); expected.put("jobType", jobType); expected.put("genderType", genderType); expected.put("department", department); expected.put("surname", surname); expected.put("rate", rate); expected.put("phone", phone); expected.put("name", name); expected.put("isPlurality", isPlurality); expected.put("isPensioner", isPensioner); expected.put("invNum", invNum); expected.put("firstName", firstName); expected.put("fatherName", fatherName); expected.put("endDate", endDate); expected.put("docSeries", docSeries); expected.put("docNum", docNum); expected.put("begDate", begDate); expected.put("birthDate", birthDate); expected.put("email", email); when(departmentDao.getEntityById(anyLong())).thenReturn(department); when(employeeStatusDao.getEntityById(anyLong())).thenReturn(employeeStatus); when(employeeTypeDao.getEntityById(anyLong())).thenReturn(employeeType); when(postDao.getEntityById(anyLong())).thenReturn(post); when(personDao.getEntityById(anyLong())).thenReturn(person); when(employeeDao.getEntityById(anyLong())).thenReturn(parent); when(orderDao.getEntityById(anyLong())).thenReturn(order); when(jobTypeDao.getEntityById(anyLong())).thenReturn(jobType); when(genderTypeDao.getEntityById(anyLong())).thenReturn(genderType); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { Employee entity = new Employee(); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntityAndDisabledSecurity() throws Exception { unit.setSecurity(false); Employee entity = new Employee(); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntityAndDisabledStatus() throws Exception { unit.setActive(false); Employee entity = new Employee(); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("userGroups", groups); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntityAndDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Employee entity = new Employee(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }