PersonNameParametersExtractor extends AbstractParametersExtractor<PersonName> { @Override public Map<String, Object> getParameters(final PersonName entity, final Map<String, Object> parameters) { addParameter(entity.getPerson(), personDao, "person", parameters); addParameter(entity.getLanguage(), languageDao, "language", parameters); addParameter(entity.getName(), "name", parameters); addParameter(entity.getFirstName(), "firstName", parameters); addParameter(entity.getFatherName(), "fatherName", parameters); addParameter(entity.getSurname(), "surname", parameters); return parameters; }  @Override Map<String, Object> getParameters(final PersonName entity, final Map<String, Object> parameters);  }
@Test public void testGetParameters() throws Exception { Long personId = 1L; Person person = new Person(); person.setId(personId); Long languageId = 2L; Language language = new Language(); language.setId(languageId); String firstName = "first name"; String fatherName = "father name"; PersonName entity = new PersonName(); entity.setPerson(person); entity.setLanguage(language); entity.setFirstName(firstName); entity.setFatherName(fatherName); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("person", person); expected.put("language", language); expected.put("firstName", firstName); expected.put("fatherName", fatherName); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(languageDao.getEntityById(anyLong())).thenReturn(language); when(personDao.getEntityById(anyLong())).thenReturn(person); Map<String, Object> actual = unit.getParameters(entity); verify(languageDao).getEntityById(languageId); verify(personDao).getEntityById(personId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledSecurity() throws Exception { unit.setActive(false); unit.setSecurity(false); Long personId = 1L; Person person = new Person(); person.setId(personId); Long languageId = 2L; Language language = new Language(); language.setId(languageId); String firstName = "first name"; String fatherName = "father name"; PersonName entity = new PersonName(); entity.setPerson(person); entity.setLanguage(language); entity.setFirstName(firstName); entity.setFatherName(fatherName); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("person", person); expected.put("language", language); expected.put("firstName", firstName); expected.put("fatherName", fatherName); when(languageDao.getEntityById(anyLong())).thenReturn(language); when(personDao.getEntityById(anyLong())).thenReturn(person); Map<String, Object> actual = unit.getParameters(entity); verify(languageDao).getEntityById(languageId); verify(personDao).getEntityById(personId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { PersonName entity = new PersonName(); 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); PersonName entity = new PersonName(); 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); PersonName entity = new PersonName(); 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); PersonName entity = new PersonName(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }