SpecialtyParametersExtractor extends AbstractParametersExtractor<Specialty> { @Override public Map<String, Object> getParameters(final Specialty entity, final Map<String, Object> parameters) { addParameter(entity.getSpecialtyType(), specialtyTypeDao, "specialtyType", parameters); addParameter(entity.getParent(), specialtyDao, "parent", parameters); addParameter(entity.getAbbrName(), "abbrName", parameters); addParameter(entity.getName(), "name", parameters); addParameter(entity.getCipher(), "cipher", parameters); addParameter(entity.getBegDate(), "begDate", parameters); addParameter(entity.getEndDate(), "endDate", parameters); return parameters; }  @Override Map<String, Object> getParameters(final Specialty entity, final Map<String, Object> parameters);  }
@Test public void testGetParameters() throws Exception { Specialty entity = new Specialty(); Long specialtyTypeId = 1L; SpecialtyType specialtyType = new SpecialtyType(); specialtyType.setId(specialtyTypeId); Long parentId = 2L; Specialty parent = new Specialty(); parent.setId(parentId); String abbrName = "abbr name"; String name = "name1"; String cipher = "cipher1"; Date begDate = new Date(); Date endDate = new Date(); entity.setSpecialtyType(specialtyType); entity.setParent(parent); entity.setAbbrName(abbrName); entity.setName(name); entity.setCipher(cipher); entity.setBegDate(begDate); entity.setEndDate(endDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("specialtyType", specialtyType); expected.put("parent", parent); expected.put("abbrName", abbrName); expected.put("name", name); expected.put("cipher", cipher); expected.put("begDate", begDate); expected.put("endDate", endDate); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(specialtyTypeDao.getEntityById(anyLong())).thenReturn(specialtyType); when(specialtyDao.getEntityById(anyLong())).thenReturn(parent); Map<String, Object> actual = unit.getParameters(entity); verify(specialtyTypeDao).getEntityById(specialtyTypeId); verify(specialtyDao).getEntityById(parentId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Specialty entity = new Specialty(); Long specialtyTypeId = 1L; SpecialtyType specialtyType = new SpecialtyType(); specialtyType.setId(specialtyTypeId); Long parentId = 2L; Specialty parent = new Specialty(); parent.setId(parentId); String abbrName = "abbr name"; String name = "name1"; String cipher = "cipher1"; Date begDate = new Date(); Date endDate = new Date(); entity.setSpecialtyType(specialtyType); entity.setParent(parent); entity.setAbbrName(abbrName); entity.setName(name); entity.setCipher(cipher); entity.setBegDate(begDate); entity.setEndDate(endDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("specialtyType", specialtyType); expected.put("parent", parent); expected.put("abbrName", abbrName); expected.put("name", name); expected.put("cipher", cipher); expected.put("begDate", begDate); expected.put("endDate", endDate); when(specialtyTypeDao.getEntityById(anyLong())).thenReturn(specialtyType); when(specialtyDao.getEntityById(anyLong())).thenReturn(parent); Map<String, Object> actual = unit.getParameters(entity); verify(specialtyTypeDao).getEntityById(specialtyTypeId); verify(specialtyDao).getEntityById(parentId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { Specialty entity = new Specialty(); 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); Specialty entity = new Specialty(); 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); Specialty entity = new Specialty(); 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); Specialty entity = new Specialty(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }