DepartmentContactParametersExtractor extends AbstractParametersExtractor<DepartmentContact> { @Override protected Map<String, Object> getParameters(final DepartmentContact entity, final Map<String, Object> parameters) { addParameter(entity.getDepartment(), departmentDao, "department", parameters); addParameter(entity.getContactType(), contactTypeDao, "contactType", parameters); addParameter(entity.getValue(), "value", parameters); return parameters; }    }
@Test public void testGetParameters() throws Exception { Long departmentId = 1L; Department department = new Department(); department.setId(departmentId); Long contactTypeId = 2L; ContactType contactType = new ContactType(); contactType.setId(contactTypeId); String value = "value"; DepartmentContact entity = new DepartmentContact(); entity.setDepartment(department); entity.setContactType(contactType); entity.setValue(value); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); expected.put("department", department); expected.put("contactType", contactType); expected.put("value", value); when(departmentDao.getEntityById(anyLong())).thenReturn(department); when(contactTypeDao.getEntityById(anyLong())).thenReturn(contactType); Map<String, Object> actual = unit.getParameters(entity); verify(departmentDao).getEntityById(departmentId); verify(contactTypeDao).getEntityById(contactTypeId); assertEquals(expected, actual); }
@Test public void testGetParametersWithEmptyFields() throws Exception { DepartmentContact entity = new DepartmentContact(); 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(contactTypeDao, times(0)).getEntityById(anyLong()); assertEquals(expected, actual); }
@Test public void testGetParametersWithEmptyFieldsAndWithoutDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); DepartmentContact entity = new DepartmentContact(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); verify(departmentDao, times(0)).getEntityById(anyLong()); verify(contactTypeDao, 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 contactTypeId = 2L; ContactType contactType = new ContactType(); contactType.setId(contactTypeId); String value = "value"; DepartmentContact entity = new DepartmentContact(); entity.setDepartment(department); entity.setContactType(contactType); entity.setValue(value); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("department", department); expected.put("contactType", contactType); expected.put("value", value); when(departmentDao.getEntityById(anyLong())).thenReturn(department); when(contactTypeDao.getEntityById(anyLong())).thenReturn(contactType); Map<String, Object> actual = unit.getParameters(entity); verify(departmentDao).getEntityById(departmentId); verify(contactTypeDao).getEntityById(contactTypeId); verify(sessionService, times(0)).getGroups(); assertEquals(expected, actual); }