SubjectParametersExtractor extends AbstractParametersExtractor<Subject> { @Override protected Map<String, Object> getParameters(final Subject entity, final Map<String, Object> parameters) { addParameter(entity.getSubjectType(), subjectTypeDao, "subjectType", parameters); addParameter(entity.getName(), "name", parameters); return parameters; }    }
@Test public void testGetParameters() throws Exception { Long subjectTypeId = 2L; SubjectType subjectType = new SubjectType(); subjectType.setId(subjectTypeId); String name = "name"; Subject entity = new Subject(); entity.setName(name); entity.setSubjectType(subjectType); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("name", name); expected.put("subjectType", subjectType); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(subjectTypeDao.getEntityById(anyLong())).thenReturn(subjectType); Map<String, Object> actualParameters = unit.getParameters(entity); verify(subjectTypeDao).getEntityById(subjectTypeId); assertEquals(expected, actualParameters); }
@Test public void testGetParametersWithDisabledSecurity() throws Exception { unit.setSecurity(false); Long subjectTypeId = 2L; SubjectType subjectType = new SubjectType(); subjectType.setId(subjectTypeId); String name = "name"; Subject entity = new Subject(); entity.setName(name); entity.setSubjectType(subjectType); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("name", name); expected.put("subjectType", subjectType); expected.put("status", RowStatus.ACTIVE); when(subjectTypeDao.getEntityById(anyLong())).thenReturn(subjectType); Map<String, Object> actualParameters = unit.getParameters(entity); verify(subjectTypeDao).getEntityById(subjectTypeId); assertEquals(expected, actualParameters); }
@Test public void testGetParametersWithDisabledStatus() throws Exception { unit.setActive(false); Long subjectTypeId = 2L; SubjectType subjectType = new SubjectType(); subjectType.setId(subjectTypeId); String name = "name"; Subject entity = new Subject(); entity.setName(name); entity.setSubjectType(subjectType); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("name", name); expected.put("subjectType", subjectType); expected.put("userGroups", groups); when(subjectTypeDao.getEntityById(anyLong())).thenReturn(subjectType); Map<String, Object> actualParameters = unit.getParameters(entity); verify(subjectTypeDao).getEntityById(subjectTypeId); assertEquals(expected, actualParameters); }
@Test public void testGetParametersWithDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Long subjectTypeId = 2L; SubjectType subjectType = new SubjectType(); subjectType.setId(subjectTypeId); String name = "name"; Subject entity = new Subject(); entity.setName(name); entity.setSubjectType(subjectType); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("name", name); expected.put("subjectType", subjectType); when(subjectTypeDao.getEntityById(anyLong())).thenReturn(subjectType); Map<String, Object> actualParameters = unit.getParameters(entity); verify(subjectTypeDao).getEntityById(subjectTypeId); assertEquals(expected, actualParameters); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { Subject entity = new Subject(); 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 testGetParametersWithDefaultEntityAndDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Subject entity = new Subject(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }