PublicActivityParametersExtractor extends AbstractParametersExtractor<PublicActivity> { @Override protected Map<String, Object> getParameters(final PublicActivity entity, final Map<String, Object> parameters) { addParameter(entity.getPublicActivityTypeType(), publicActivityTypeDao, "publicActivityType", parameters); addParameter(entity.getTimePeriod(), timePeriodDao, "timePeriod", parameters); addParameter(entity.getName(), "name", parameters); addParameter(entity.getBegDate(), "begDate", parameters); addParameter(entity.getEndDate(), "endDate", parameters); return parameters; }   @Resource(name = "publicActivityTypeDao")
	private Dao<PublicActivityType, PublicActivityType, Long> publicActivityTypeDao; }
@Test public void testGetParameters() throws Exception { Long publicActiveTypeId = 1L; PublicActivityType publicActiveType = new PublicActivityType(); publicActiveType.setId(publicActiveTypeId); Long timePeriodId = 2L; TimePeriod timePeriod = new TimePeriod(); timePeriod.setId(timePeriodId); String name = "name"; Date begDate = new Date(); Date endDate = new Date(); PublicActivity entity = new PublicActivity(); entity.setPublicActivityType(publicActiveType); entity.setTimePeriod(timePeriod); entity.setName(name); entity.setBegDate(begDate); entity.setEndDate(endDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("publicActivityType", publicActiveType); expected.put("timePeriod", timePeriod); expected.put("name", name); expected.put("begDate", begDate); expected.put("endDate", begDate); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(publicActivityTypeDao.getEntityById(anyLong())).thenReturn(publicActiveType); when(timePeriodDao.getEntityById(anyLong())).thenReturn(timePeriod); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Long publicActiveTypeId = 1L; PublicActivityType publicActiveType = new PublicActivityType(); publicActiveType.setId(publicActiveTypeId); Long timePeriodId = 2L; TimePeriod timePeriod = new TimePeriod(); timePeriod.setId(timePeriodId); String name = "name"; Date begDate = new Date(); Date endDate = new Date(); PublicActivity entity = new PublicActivity(); entity.setPublicActivityType(publicActiveType); entity.setTimePeriod(timePeriod); entity.setName(name); entity.setBegDate(begDate); entity.setEndDate(endDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("publicActivityType", publicActiveType); expected.put("timePeriod", timePeriod); expected.put("name", name); expected.put("begDate", begDate); expected.put("endDate", begDate); when(publicActivityTypeDao.getEntityById(anyLong())).thenReturn(publicActiveType); when(timePeriodDao.getEntityById(anyLong())).thenReturn(timePeriod); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { PublicActivity entity = new PublicActivity(); 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); PublicActivity entity = new PublicActivity(); 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); PublicActivity entity = new PublicActivity(); 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); PublicActivity entity = new PublicActivity(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }