DepartmentSpecialtyParametersExtractor extends AbstractParametersExtractor<DepartmentSpecialty> { @Override protected Map<String, Object> getParameters(final DepartmentSpecialty entity, final Map<String, Object> parameters) { addParameter(entity.getDepartment(), departmentDao, "department", parameters); addParameter(entity.getSpecialty(), specialtyDao, "specialty", parameters); return parameters; }    }
@Test public void testGetParameters() throws Exception { Long departmentId = 1L; Department department = new Department(); department.setId(departmentId); Long specialtyId = 2L; Specialty specialty = new Specialty(); specialty.setId(specialtyId); DepartmentSpecialty entity = new DepartmentSpecialty(); entity.setDepartment(department); entity.setSpecialty(specialty); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); expected.put("department", department); expected.put("specialty", specialty); when(departmentDao.getEntityById(anyLong())).thenReturn(department); when(specialtyDao.getEntityById(anyLong())).thenReturn(specialty); Map<String, Object> actual = unit.getParameters(entity); verify(departmentDao).getEntityById(departmentId); verify(specialtyDao).getEntityById(specialtyId); assertEquals(expected, actual); }
@Test public void testGetParametersWithEmptyFields() throws Exception { DepartmentSpecialty entity = new DepartmentSpecialty(); 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(departmentDao, times(0)).getEntityById(anyLong()); verify(specialtyDao, times(0)).getEntityById(anyLong()); assertEquals(expected, actual); }
@Test public void testGetParametersWithEmptyFieldsAndWithoutDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); DepartmentSpecialty entity = new DepartmentSpecialty(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); verify(departmentDao, times(0)).getEntityById(anyLong()); verify(specialtyDao, times(0)).getEntityById(anyLong()); assertEquals(expected, actual); }
@Test public void testGetParamteresWithoutSecurity() throws Exception { unit.setSecurity(false); Long departmentId = 1L; Department department = new Department(); department.setId(departmentId); Long specialtyId = 2L; Specialty specialty = new Specialty(); specialty.setId(specialtyId); DepartmentSpecialty entity = new DepartmentSpecialty(); entity.setDepartment(department); entity.setSpecialty(specialty); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("department", department); expected.put("specialty", specialty); when(departmentDao.getEntityById(anyLong())).thenReturn(department); when(specialtyDao.getEntityById(anyLong())).thenReturn(specialty); Map<String, Object> actual = unit.getParameters(entity); verify(departmentDao).getEntityById(departmentId); verify(specialtyDao).getEntityById(specialtyId); verify(sessionService, times(0)).getGroups(); assertEquals(expected, actual); }