DegreeParametersExtractor extends AbstractParametersExtractor<Degree> { @Override protected Map<String, Object> getParameters(final Degree entity, final Map<String, Object> parameters) { addParameter(entity.getDegreeType(), degreeTypeDao, "degreeType", parameters); addParameter(entity.getPerson(), personDao, "person", parameters); return parameters; }    }
@Test public void testGetParameters() throws Exception { Long personId = 1L; Person person = new Person(); person.setId(personId); Long degreeTypeId = 2L; DegreeType degreeType = new DegreeType(); degreeType.setId(degreeTypeId); Degree entity = new Degree(); entity.setPerson(person); entity.setDegreeType(degreeType); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); expected.put("person", person); expected.put("degreeType", degreeType); when(degreeTypeDao.getEntityById(anyLong())).thenReturn(degreeType); when(personDao.getEntityById(anyLong())).thenReturn(person); Map<String, Object> actual = unit.getParameters(entity); verify(personDao).getEntityById(personId); verify(degreeTypeDao).getEntityById(degreeTypeId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDEfaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Long personId = 1L; Person person = new Person(); person.setId(personId); Long degreeTypeId = 2L; DegreeType degreeType = new DegreeType(); degreeType.setId(degreeTypeId); Degree entity = new Degree(); entity.setPerson(person); entity.setDegreeType(degreeType); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("person", person); expected.put("degreeType", degreeType); when(degreeTypeDao.getEntityById(anyLong())).thenReturn(degreeType); when(personDao.getEntityById(anyLong())).thenReturn(person); Map<String, Object> actual = unit.getParameters(entity); verify(personDao).getEntityById(personId); verify(degreeTypeDao).getEntityById(degreeTypeId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { Degree entity = new Degree(); 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); Degree entity = new Degree(); 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); Degree entity = new Degree(); 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); Degree entity = new Degree(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }