PersonEnrolmentSubjectParametersExtractor extends AbstractParametersExtractor<PersonEnrolmentSubject> { @Override protected Map<String, Object> getParameters(final PersonEnrolmentSubject entity, final Map<String, Object> parameters) { addParameter(entity.getPerson(), personDao, "person", parameters); addParameter(entity.getPersonPaper(), personPaperDao, "personPaper", parameters); addParameter(entity.getEnrolmentSubject(), enrolmentSubjectDao, "enrolmentSubject", parameters); addParameter(entity.getMark(), "mark", parameters); return parameters; }    }
@Test public void testGetParameters() throws Exception { Long personId = 1L; Person person = new Person(); person.setId(personId); Long personPaperId = 2L; PersonPaper personPaper = new PersonPaper(); personPaper.setId(personPaperId); Long enrolmentSubjectId = 3L; EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(enrolmentSubjectId); Double mark = 2.33; PersonEnrolmentSubject entity = new PersonEnrolmentSubject(); entity.setPerson(person); entity.setPersonPaper(personPaper); entity.setEnrolmentSubject(enrolmentSubject); entity.setMark(mark); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); expected.put("person", person); expected.put("personPaper", personPaper); expected.put("enrolmentSubject", enrolmentSubject); expected.put("mark", mark); when(personDao.getEntityById(anyLong())).thenReturn(person); when(personPaperDao.getEntityById(anyLong())).thenReturn(personPaper); when(enrolmentSubjectDao.getEntityById(anyLong())).thenReturn(enrolmentSubject); Map<String, Object> actual = unit.getParameters(entity); verify(personDao).getEntityById(personId); verify(personPaperDao).getEntityById(personPaperId); verify(enrolmentSubjectDao).getEntityById(enrolmentSubjectId); assertEquals(expected, actual); }
@Test public void testGetParametersWithEmptyFields() throws Exception { PersonEnrolmentSubject entity = new PersonEnrolmentSubject(); 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(personPaperDao, times(0)).getEntityById(anyLong()); verify(enrolmentSubjectDao, times(0)).getEntityById(anyLong()); assertEquals(expected, actual); }
@Test public void testGetParametersWithEmptyFieldsAndWithoutDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); PersonEnrolmentSubject entity = new PersonEnrolmentSubject(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); verify(personDao, times(0)).getEntityById(anyLong()); verify(personPaperDao, times(0)).getEntityById(anyLong()); verify(enrolmentSubjectDao, times(0)).getEntityById(anyLong()); assertEquals(expected, actual); }
@Test public void testGetParametersWithoutSecurity() throws Exception { unit.setSecurity(false); Long personId = 1L; Person person = new Person(); person.setId(personId); Long personPaperId = 2L; PersonPaper personPaper = new PersonPaper(); personPaper.setId(personPaperId); Long enrolmentSubjectId = 3L; EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(enrolmentSubjectId); Double mark = 2.33; PersonEnrolmentSubject entity = new PersonEnrolmentSubject(); entity.setPerson(person); entity.setPersonPaper(personPaper); entity.setEnrolmentSubject(enrolmentSubject); entity.setMark(mark); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("person", person); expected.put("personPaper", personPaper); expected.put("enrolmentSubject", enrolmentSubject); expected.put("mark", mark); when(personDao.getEntityById(anyLong())).thenReturn(person); when(personPaperDao.getEntityById(anyLong())).thenReturn(personPaper); when(enrolmentSubjectDao.getEntityById(anyLong())).thenReturn(enrolmentSubject); Map<String, Object> actual = unit.getParameters(entity); verify(personDao).getEntityById(personId); verify(personPaperDao).getEntityById(personPaperId); verify(enrolmentSubjectDao).getEntityById(enrolmentSubjectId); verify(sessionService, times(0)).getGroups(); assertEquals(expected, actual); }