PublicActivityAwardParametersExtractor extends AbstractParametersExtractor<PublicActivityAward> { @Override protected Map<String, Object> getParameters(final PublicActivityAward entity, final Map<String, Object> parameters) { addParameter(entity.getPublicActivity(), publicActivityDao, "publicActivity", parameters); addParameter(entity.getEnrolmentSubject(), enrolmentSubjectDao, "enrolmentSubject", parameters); addParameter(entity.getAwardName(), "awardName", parameters); addParameter(entity.getBegDate(), "begDate", parameters); addParameter(entity.getEndDate(), "endDate", parameters); return parameters; }   @Resource(name = "publicActivityDao")
	private Dao<PublicActivity, PublicActivity, Long> publicActivityDao; }
@Test public void testGetParameters() throws Exception { Long publicActivityId = 1L; PublicActivity publicActivity = new PublicActivity(); publicActivity.setId(publicActivityId); Long enrolmentSubjectId = 2L; EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(enrolmentSubjectId); String awardname = "award name"; Double bonus = 45.1; Date begDate = new Date(); Date endDate = new Date(); PublicActivityAward entity = new PublicActivityAward(); entity.setPublicActivity(publicActivity); entity.setEnrolmentSubject(enrolmentSubject); entity.setAwardName(awardname); entity.setBonus(bonus); entity.setBegDate(begDate); entity.setEndDate(endDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("publicActivity", publicActivity); expected.put("enrolmentSubject", enrolmentSubject); expected.put("awardName", awardname); expected.put("begDate", begDate); expected.put("endDate", begDate); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(publicActivityDao.getEntityById(anyLong())).thenReturn(publicActivity); when(enrolmentSubjectDao.getEntityById(anyLong())).thenReturn(enrolmentSubject); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Long publicActivityId = 1L; PublicActivity publicActivity = new PublicActivity(); publicActivity.setId(publicActivityId); Long enrolmentSubjectId = 2L; EnrolmentSubject enrolmentSubject = new EnrolmentSubject(); enrolmentSubject.setId(enrolmentSubjectId); String awardname = "award name"; Double bonus = 45.1; Date begDate = new Date(); Date endDate = new Date(); PublicActivityAward entity = new PublicActivityAward(); entity.setPublicActivity(publicActivity); entity.setEnrolmentSubject(enrolmentSubject); entity.setAwardName(awardname); entity.setBonus(bonus); entity.setBegDate(begDate); entity.setEndDate(endDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("publicActivity", publicActivity); expected.put("enrolmentSubject", enrolmentSubject); expected.put("awardName", awardname); expected.put("begDate", begDate); expected.put("endDate", begDate); when(publicActivityDao.getEntityById(anyLong())).thenReturn(publicActivity); when(enrolmentSubjectDao.getEntityById(anyLong())).thenReturn(enrolmentSubject); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { PublicActivityAward entity = new PublicActivityAward(); 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); PublicActivityAward entity = new PublicActivityAward(); 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); PublicActivityAward entity = new PublicActivityAward(); 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); PublicActivityAward entity = new PublicActivityAward(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }