AdminUnitParametersExtractor extends AbstractParametersExtractor<AdminUnit> { @Override protected Map<String, Object> getParameters(final AdminUnit entity, final Map<String, Object> parameters) { addParameter(entity.getAdminUnitType(), adminUnitTypeDao, "adminUnitType", parameters); addParameter(entity.getParent(), adminUnitDao, "parent", parameters); addParameter(entity.getIdentifier(), "identifier", parameters); addParameter(entity.getIdentifier1(), "identifier1", parameters); addParameter(entity.getIdentifier2(), "identifier2", parameters); addParameter(entity.getIdentifier3(), "identifier3", parameters); addParameter(entity.getName(), "name", parameters); addParameter(entity.getBegDate(), "begDate", parameters); addParameter(entity.getEndDate(), "endDate", parameters); return parameters; }    }
@Test public void testGetParameters() throws Exception { Long adminUnitTypeId = 1L; AdminUnitType adminUnitType = new AdminUnitType(); adminUnitType.setId(adminUnitTypeId); String identifier = "identifier"; String identifier1 = "identifier1"; String identifier2 = "identifier2"; String identifier3 = "identifier3"; String name = "name"; Date begDate = new Date(); Date endDate = new Date(); AdminUnit entity = new AdminUnit(); entity.setAdminUnitType(adminUnitType); entity.setIdentifier(identifier); entity.setIdentifier1(identifier1); entity.setIdentifier2(identifier2); entity.setIdentifier3(identifier3); entity.setName(name); entity.setBegDate(begDate); entity.setEndDate(endDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("adminUnitType", adminUnitType); expected.put("identifier", identifier); expected.put("identifier1", identifier1); expected.put("identifier2", identifier2); expected.put("identifier3", identifier3); expected.put("name", name); expected.put("begDate", begDate); expected.put("endDate", endDate); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(adminUnitTypeDao.getEntityById(anyLong())).thenReturn(adminUnitType); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDEfaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Long adminUnitTypeId = 1L; AdminUnitType adminUnitType = new AdminUnitType(); adminUnitType.setId(adminUnitTypeId); String identifier = "identifier"; String identifier1 = "identifier1"; String identifier2 = "identifier2"; String identifier3 = "identifier3"; String name = "name"; Date begDate = new Date(); Date endDate = new Date(); AdminUnit entity = new AdminUnit(); entity.setAdminUnitType(adminUnitType); entity.setIdentifier(identifier); entity.setIdentifier1(identifier1); entity.setIdentifier2(identifier2); entity.setIdentifier3(identifier3); entity.setName(name); entity.setBegDate(begDate); entity.setEndDate(endDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("adminUnitType", adminUnitType); expected.put("identifier", identifier); expected.put("identifier1", identifier1); expected.put("identifier2", identifier2); expected.put("identifier3", identifier3); expected.put("name", name); expected.put("begDate", begDate); expected.put("endDate", endDate); when(adminUnitTypeDao.getEntityById(anyLong())).thenReturn(adminUnitType); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { AdminUnit entity = new AdminUnit(); 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); AdminUnit entity = new AdminUnit(); 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); AdminUnit entity = new AdminUnit(); 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); AdminUnit entity = new AdminUnit(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }