PersonWorkParametersExtractor extends AbstractParametersExtractor<PersonWork> { @Override public Map<String, Object> getParameters(final PersonWork entity, final Map<String, Object> parameters) { addParameter(entity.getPerson(), personDao, "person", parameters); addParameter(entity.getJobType(), jobTypeDao, "jobType", parameters); addParameter(entity.getSpecStageType(), specStageTypeDao, "specStageType", parameters); addParameter(entity.getOrganizationName(), "organizationName", parameters); addParameter(entity.getPostName(), "postName", parameters); addParameter(entity.getDescription(), "description", parameters); addParameter(entity.getBegDate(), "begDate", parameters); addParameter(entity.getEndDate(), "endDate", parameters); return parameters; }  @Override Map<String, Object> getParameters(final PersonWork entity, final Map<String, Object> parameters);  }
@Test public void testGetParameters() throws Exception { Long personId = 1L; Person person = new Person(); person.setId(personId); Long jobTypeId = 2L; JobType jobType = new JobType(); jobType.setId(jobTypeId); Long specStageTypeId = 3L; SpecStageType specStageType = new SpecStageType(); specStageType.setId(specStageTypeId); String organizationName = "Optigra"; String postName = "java developer"; String description = "aladin"; Date begDate = new Date(); Date endDate = new Date(); PersonWork entity = new PersonWork(); entity.setPerson(person); entity.setJobType(jobType); entity.setSpecStageType(specStageType); entity.setOrganizationName(organizationName); entity.setPostName(postName); entity.setDescription(description); entity.setBegDate(begDate); entity.setEndDate(endDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("person", person); expected.put("jobType", jobType); expected.put("specStageType", specStageType); expected.put("organizationName", organizationName); expected.put("postName", postName); expected.put("description", description); expected.put("begDate", begDate); expected.put("endDate", endDate); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(personDao.getEntityById(anyLong())).thenReturn(person); when(jobTypeDao.getEntityById(anyLong())).thenReturn(jobType); when(specStageTypeDao.getEntityById(anyLong())).thenReturn(specStageType); Map<String, Object> actual = unit.getParameters(entity); verify(personDao).getEntityById(personId); verify(jobTypeDao).getEntityById(jobTypeId); verify(specStageTypeDao).getEntityById(specStageTypeId); assertEquals(expected, actual); }
@Test public void testGetParametersWithEmptyFields() throws Exception { PersonWork entity = new PersonWork(); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); Map<String, Object> actual = unit.getParameters(entity); verify(personDao, times(0)).getEntityById(anyLong()); verify(jobTypeDao, times(0)).getEntityById(anyLong()); verify(specStageTypeDao, times(0)).getEntityById(anyLong()); assertEquals(expected, actual); }
@Test public void testGetParametersWithEmptyFieldsAndWithoutDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); PersonWork entity = new PersonWork(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); verify(personDao, times(0)).getEntityById(anyLong()); verify(jobTypeDao, times(0)).getEntityById(anyLong()); verify(specStageTypeDao, times(0)).getEntityById(anyLong()); assertEquals(expected, actual); }
@Test public void testGetParamteresWithoutSecurity() throws Exception { unit.setSecurity(false); Long personId = 1L; Person person = new Person(); person.setId(personId); Long jobTypeId = 2L; JobType jobType = new JobType(); jobType.setId(jobTypeId); Long specStageTypeId = 3L; SpecStageType specStageType = new SpecStageType(); specStageType.setId(specStageTypeId); String organizationName = "Optigra"; String postName = "java developer"; String description = "aladin"; Date begDate = new Date(); Date endDate = new Date(); PersonWork entity = new PersonWork(); entity.setPerson(person); entity.setJobType(jobType); entity.setSpecStageType(specStageType); entity.setOrganizationName(organizationName); entity.setPostName(postName); entity.setDescription(description); entity.setBegDate(begDate); entity.setEndDate(endDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("person", person); expected.put("jobType", jobType); expected.put("specStageType", specStageType); expected.put("organizationName", organizationName); expected.put("postName", postName); expected.put("description", description); expected.put("begDate", begDate); expected.put("endDate", endDate); expected.put("status", RowStatus.ACTIVE); when(personDao.getEntityById(anyLong())).thenReturn(person); when(jobTypeDao.getEntityById(anyLong())).thenReturn(jobType); when(specStageTypeDao.getEntityById(anyLong())).thenReturn(specStageType); Map<String, Object> actual = unit.getParameters(entity); verify(personDao).getEntityById(personId); verify(jobTypeDao).getEntityById(jobTypeId); verify(specStageTypeDao).getEntityById(specStageTypeId); verify(sessionService, times(0)).getGroups(); assertEquals(expected, actual); }