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