PersonFamilyParametersExtractor extends AbstractParametersExtractor<PersonFamily> { @Override protected Map<String, Object> getParameters(final PersonFamily entity, final Map<String, Object> parameters) { addParameter(entity.getPerson(), personDao, "person", parameters); addParameter(entity.getFamilyType(), familyTypeDao, "familyType", parameters); addParameter(entity.getName(), "name", parameters); return parameters; }    }
@Test public void testGetParameters() throws Exception { Long personId = 1L; Person person = new Person(); person.setId(personId); Long familyTypeId = 2L; FamilyType familyType = new FamilyType(); familyType.setId(familyTypeId); String name = "name"; Date birthdate = new Date(); PersonFamily entity = new PersonFamily(); entity.setPerson(person); entity.setFamilyType(familyType); entity.setName(name); entity.setBirthDate(birthdate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("person", person); expected.put("familyType", familyType); expected.put("name", name); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(personDao.getEntityById(anyLong())).thenReturn(person); when(familyTypeDao.getEntityById(anyLong())).thenReturn(familyType); Map<String, Object> actual = unit.getParameters(entity); verify(personDao).getEntityById(personId); verify(familyTypeDao).getEntityById(familyTypeId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Long personId = 1L; Person person = new Person(); person.setId(personId); Long familyTypeId = 2L; FamilyType familyType = new FamilyType(); familyType.setId(familyTypeId); String name = "name"; Date birthdate = new Date(); PersonFamily entity = new PersonFamily(); entity.setPerson(person); entity.setFamilyType(familyType); entity.setName(name); entity.setBirthDate(birthdate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("person", person); expected.put("familyType", familyType); expected.put("name", name); when(personDao.getEntityById(anyLong())).thenReturn(person); when(familyTypeDao.getEntityById(anyLong())).thenReturn(familyType); Map<String, Object> actual = unit.getParameters(entity); verify(personDao).getEntityById(personId); verify(familyTypeDao).getEntityById(familyTypeId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { PersonFamily entity = new PersonFamily(); 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); PersonFamily entity = new PersonFamily(); 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); PersonFamily entity = new PersonFamily(); 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); PersonFamily entity = new PersonFamily(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }