EnrolmentBenefitParametersExtractor extends AbstractParametersExtractor<EnrolmentBenefit> { @Override protected Map<String, Object> getParameters(final EnrolmentBenefit entity, final Map<String, Object> parameters) { addParameter(entity.getEnrolment(), enrolmentDao, "enrolment", parameters); addParameter(entity.getBenefit(), benefitDao, "benefit", parameters); addParameter(entity.getPersonPaper(), personPaperDao, "personPaper", parameters); return parameters; }    }
@Test public void testGetParameters() throws Exception { Long personPaperId = 1L; PersonPaper personPaper = new PersonPaper(); personPaper.setId(personPaperId); Long benefitId = 2L; Benefit benefit = new Benefit(); benefit.setId(benefitId); Long enrolmentId = 3L; Enrolment enrolment = new Enrolment(); enrolment.setId(enrolmentId); EnrolmentBenefit entity = new EnrolmentBenefit(); entity.setPersonPaper(personPaper); entity.setBenefit(benefit); entity.setEnrolment(enrolment); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("enrolment", enrolment); expected.put("benefit", benefit); expected.put("personPaper", personPaper); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(personPaperDao.getEntityById(anyLong())).thenReturn(personPaper); when(enrolmentDao.getEntityById(anyLong())).thenReturn(enrolment); when(benefitDao.getEntityById(anyLong())).thenReturn(benefit); Map<String, Object> actual = unit.getParameters(entity); verify(personPaperDao).getEntityById(personPaperId); verify(enrolmentDao).getEntityById(enrolmentId); verify(benefitDao).getEntityById(benefitId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Long personPaperId = 1L; PersonPaper personPaper = new PersonPaper(); personPaper.setId(personPaperId); Long benefitId = 2L; Benefit benefit = new Benefit(); benefit.setId(benefitId); Long enrolmentId = 3L; Enrolment enrolment = new Enrolment(); enrolment.setId(enrolmentId); EnrolmentBenefit entity = new EnrolmentBenefit(); entity.setPersonPaper(personPaper); entity.setBenefit(benefit); entity.setEnrolment(enrolment); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("enrolment", enrolment); expected.put("benefit", benefit); expected.put("personPaper", personPaper); when(personPaperDao.getEntityById(anyLong())).thenReturn(personPaper); when(enrolmentDao.getEntityById(anyLong())).thenReturn(enrolment); when(benefitDao.getEntityById(anyLong())).thenReturn(benefit); Map<String, Object> actual = unit.getParameters(entity); verify(personPaperDao).getEntityById(personPaperId); verify(enrolmentDao).getEntityById(enrolmentId); verify(benefitDao).getEntityById(benefitId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { EnrolmentBenefit entity = new EnrolmentBenefit(); 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); EnrolmentBenefit entity = new EnrolmentBenefit(); 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); EnrolmentBenefit entity = new EnrolmentBenefit(); 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); EnrolmentBenefit entity = new EnrolmentBenefit(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }