PersonAddressParametersExtractor extends AbstractParametersExtractor<PersonAddress> { @Override public Map<String, Object> getParameters(final PersonAddress entity, final Map<String, Object> parameters) { addParameter(entity.getPerson(), personDao, "person", parameters); addParameter(entity.getAddressType(), addressTypeDao, "addressType", parameters); addParameter(entity.getAdminUnit(), adminUnitDao, "adminUnit", parameters); addParameter(entity.getStreetType(), streetTypeDao, "streetType", parameters); addParameter(entity.getAsset(), assetDao, "asset", parameters); addParameter(entity.getZipCode(), "zipCode", parameters); addParameter(entity.getStreet(), "street", parameters); addParameter(entity.getHouse(), "house", parameters); addParameter(entity.getApartment(), "apartment", parameters); addParameter(entity.getBegDate(), "begDate", parameters); addParameter(entity.getEndDate(), "endDate", parameters); return parameters; }  @Override Map<String, Object> getParameters(final PersonAddress entity, final Map<String, Object> parameters);  }
@Test public void testGetParameters() throws Exception { String zipCode = "zip code"; String street = "street"; String house = "house 1"; String apartment = "appartment 1"; Date begDate = new Date(); Date endDate = new Date(); Long personId = 1L; Person person = new Person(); person.setId(personId); Long addressTypeId = 2L; AddressType addressType = new AddressType(); addressType.setId(addressTypeId); Long adminUnitId = 3L; AdminUnit adminUnit = new AdminUnit(); adminUnit.setId(adminUnitId); Long streetTypeId = 4L; StreetType streetType = new StreetType(); streetType.setId(streetTypeId); Long assetId = 5L; Asset asset = new Asset(); asset.setId(assetId); PersonAddress entity = new PersonAddress(); entity.setPerson(person); entity.setAddressType(addressType); entity.setAdminUnit(adminUnit); entity.setStreetType(streetType); entity.setAsset(asset); entity.setZipCode(zipCode); entity.setStreet(street); entity.setHouse(house); entity.setApartment(apartment); entity.setBegDate(begDate); entity.setEndDate(endDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("person", person); expected.put("addressType", addressType); expected.put("adminUnit", adminUnit); expected.put("streetType", streetType); expected.put("asset", asset); expected.put("zipCode", zipCode); expected.put("street", street); expected.put("house", house); expected.put("apartment", apartment); expected.put("begDate", begDate); expected.put("endDate", endDate); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(personDao.getEntityById(anyLong())).thenReturn(person); when(addressTypeDao.getEntityById(anyLong())).thenReturn(addressType); when(adminUnitDao.getEntityById(anyLong())).thenReturn(adminUnit); when(streetTypeDao.getEntityById(anyLong())).thenReturn(streetType); when(assetDao.getEntityById(anyLong())).thenReturn(asset); Map<String, Object> actual = unit.getParameters(entity); verify(personDao).getEntityById(personId); verify(addressTypeDao).getEntityById(addressTypeId); verify(adminUnitDao).getEntityById(adminUnitId); verify(streetTypeDao).getEntityById(streetTypeId); verify(assetDao).getEntityById(assetId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); String zipCode = "zip code"; String street = "street"; String house = "house 1"; String apartment = "appartment 1"; Date begDate = new Date(); Date endDate = new Date(); Long personId = 1L; Person person = new Person(); person.setId(personId); Long addressTypeId = 2L; AddressType addressType = new AddressType(); addressType.setId(addressTypeId); Long adminUnitId = 3L; AdminUnit adminUnit = new AdminUnit(); adminUnit.setId(adminUnitId); Long streetTypeId = 4L; StreetType streetType = new StreetType(); streetType.setId(streetTypeId); Long assetId = 5L; Asset asset = new Asset(); asset.setId(assetId); PersonAddress entity = new PersonAddress(); entity.setPerson(person); entity.setAddressType(addressType); entity.setAdminUnit(adminUnit); entity.setStreetType(streetType); entity.setAsset(asset); entity.setZipCode(zipCode); entity.setStreet(street); entity.setHouse(house); entity.setApartment(apartment); entity.setBegDate(begDate); entity.setEndDate(endDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("person", person); expected.put("addressType", addressType); expected.put("adminUnit", adminUnit); expected.put("streetType", streetType); expected.put("asset", asset); expected.put("zipCode", zipCode); expected.put("street", street); expected.put("house", house); expected.put("apartment", apartment); expected.put("begDate", begDate); expected.put("endDate", endDate); when(personDao.getEntityById(anyLong())).thenReturn(person); when(addressTypeDao.getEntityById(anyLong())).thenReturn(addressType); when(adminUnitDao.getEntityById(anyLong())).thenReturn(adminUnit); when(streetTypeDao.getEntityById(anyLong())).thenReturn(streetType); when(assetDao.getEntityById(anyLong())).thenReturn(asset); Map<String, Object> actual = unit.getParameters(entity); verify(personDao).getEntityById(personId); verify(addressTypeDao).getEntityById(addressTypeId); verify(adminUnitDao).getEntityById(adminUnitId); verify(streetTypeDao).getEntityById(streetTypeId); verify(assetDao).getEntityById(assetId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { PersonAddress entity = new PersonAddress(); 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); PersonAddress entity = new PersonAddress(); 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); PersonAddress entity = new PersonAddress(); 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); PersonAddress entity = new PersonAddress(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }