EnrolmentEnrolmentSubjectParametersExtractor extends AbstractParametersExtractor<EnrolmentEnrolmentSubject> { @Override protected Map<String, Object> getParameters(final EnrolmentEnrolmentSubject entity, final Map<String, Object> parameters) { addParameter(entity.getEnrolmentSubject(), enrolmentSubjectDao, "enrolmentSubject", parameters); addParameter(entity.getEnrolment(), enrolmentDao, "enrolment", parameters); addParameter(entity.getPersonEnrolmentSubject(), persinEnrolmentSubjectDao, "personEnrolmentSubject", parameters); addParameter(entity.getMark(), "mark", parameters); return parameters; }    }
@Test public void testGetParameters() throws Exception { Long enrolmentSubjectId = 1L; EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(enrolmentSubjectId); Long enrolmentId = 2L; Enrolment enrolment = new Enrolment(); enrolment.setId(enrolmentId); Long personEnrolmentSubjectId = 3L; PersonEnrolmentSubject personEnrolmentSubject = new PersonEnrolmentSubject(); personEnrolmentSubject.setId(personEnrolmentSubjectId); Double mark = 4d; EnrolmentEnrolmentSubject entity = new EnrolmentEnrolmentSubject(); entity.setEnrolment(enrolment); entity.setEnrolmentSubject(enrolmentSubject); entity.setPersonEnrolmentSubject(personEnrolmentSubject); entity.setMark(mark); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("enrolmentSubject", enrolmentSubject); expected.put("enrolment", enrolment); expected.put("personEnrolmentSubject", personEnrolmentSubject); expected.put("mark", mark); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(enrolmentSubjectDao.getEntityById(anyLong())).thenReturn(enrolmentSubject); when(enrolmentDao.getEntityById(anyLong())).thenReturn(enrolment); when(personEnrolmentSubjectDao.getEntityById(anyLong())).thenReturn(personEnrolmentSubject); Map<String, Object> actual = unit.getParameters(entity); verify(enrolmentSubjectDao).getEntityById(enrolmentSubjectId); verify(enrolmentDao).getEntityById(enrolmentId); verify(personEnrolmentSubjectDao).getEntityById(personEnrolmentSubjectId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Long enrolmentSubjectId = 1L; EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(enrolmentSubjectId); Long enrolmentId = 2L; Enrolment enrolment = new Enrolment(); enrolment.setId(enrolmentId); Long personEnrolmentSubjectId = 3L; PersonEnrolmentSubject personEnrolmentSubject = new PersonEnrolmentSubject(); personEnrolmentSubject.setId(personEnrolmentSubjectId); Double mark = 4d; EnrolmentEnrolmentSubject entity = new EnrolmentEnrolmentSubject(); entity.setEnrolment(enrolment); entity.setEnrolmentSubject(enrolmentSubject); entity.setPersonEnrolmentSubject(personEnrolmentSubject); entity.setMark(mark); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("enrolmentSubject", enrolmentSubject); expected.put("enrolment", enrolment); expected.put("personEnrolmentSubject", personEnrolmentSubject); expected.put("mark", mark); when(enrolmentSubjectDao.getEntityById(anyLong())).thenReturn(enrolmentSubject); when(enrolmentDao.getEntityById(anyLong())).thenReturn(enrolment); when(personEnrolmentSubjectDao.getEntityById(anyLong())).thenReturn(personEnrolmentSubject); Map<String, Object> actual = unit.getParameters(entity); verify(enrolmentSubjectDao).getEntityById(enrolmentSubjectId); verify(enrolmentDao).getEntityById(enrolmentId); verify(personEnrolmentSubjectDao).getEntityById(personEnrolmentSubjectId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { EnrolmentEnrolmentSubject entity = new EnrolmentEnrolmentSubject(); 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); EnrolmentEnrolmentSubject entity = new EnrolmentEnrolmentSubject(); 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); EnrolmentEnrolmentSubject entity = new EnrolmentEnrolmentSubject(); 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); EnrolmentEnrolmentSubject entity = new EnrolmentEnrolmentSubject(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }