AssetAddressParametersExtractor extends AbstractParametersExtractor<AssetAddress> { @Override public Map<String, Object> getParameters(final AssetAddress entity, final Map<String, Object> parameters) { addParameter(entity.getAdminUnit(), adminUnitDao, "adminUnit", parameters); addParameter(entity.getAsset(), assetDao, "asset", parameters); addParameter(entity.getAddressType(), addressTypeDao, "addressType", parameters); addParameter(entity.getStreetType(), streetTypeDao, "streetType", parameters); addParameter(entity.getZipCode(), "zipCode", parameters); addParameter(entity.getStreet(), "street", parameters); addParameter(entity.getHouse(), "house", parameters); addParameter(entity.getApartment(), "apartment", parameters); return parameters; }  @Override Map<String, Object> getParameters(final AssetAddress entity, final Map<String, Object> parameters);  }
@Test public void testGetParameters() throws Exception { Long adminUnitId = 1L; AdminUnit adminUnit = new AdminUnit(); adminUnit.setId(adminUnitId); Long assetId = 2L; Asset asset = new Asset(); asset.setId(assetId); Long addressTypeId = 3L; AddressType addressType = new AddressType(); addressType.setId(addressTypeId); Long streetTypeId = 4L; StreetType streetType = new StreetType(); streetType.setId(streetTypeId); String zipCode = "zip code"; String street = "street"; String house = "house"; String apartment = "apartment"; AssetAddress entity = new AssetAddress(); entity.setAdminUnit(adminUnit); entity.setAsset(asset); entity.setAddressType(addressType); entity.setStreetType(streetType); entity.setZipCode(zipCode); entity.setStreet(street); entity.setHouse(house); entity.setApartment(apartment); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); expected.put("adminUnit", adminUnit); expected.put("asset", asset); expected.put("addressType", addressType); expected.put("streetType", streetType); expected.put("zipCode", zipCode); expected.put("street", street); expected.put("house", house); expected.put("apartment", apartment); when(adminUnitDao.getEntityById(anyLong())).thenReturn(adminUnit); when(assetDao.getEntityById(anyLong())).thenReturn(asset); when(addressTypeDao.getEntityById(anyLong())).thenReturn(addressType); when(streetTypeDao.getEntityById(anyLong())).thenReturn(streetType); Map<String, Object> actual = unit.getParameters(entity); verify(adminUnitDao).getEntityById(adminUnitId); verify(assetDao).getEntityById(assetId); verify(addressTypeDao).getEntityById(addressTypeId); verify(streetTypeDao).getEntityById(streetTypeId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledSecurity() throws Exception { unit.setActive(false); unit.setSecurity(false); Long adminUnitId = 1L; AdminUnit adminUnit = new AdminUnit(); adminUnit.setId(adminUnitId); Long assetId = 2L; Asset asset = new Asset(); asset.setId(assetId); Long addressTypeId = 3L; AddressType addressType = new AddressType(); addressType.setId(addressTypeId); Long streetTypeId = 4L; StreetType streetType = new StreetType(); streetType.setId(streetTypeId); String zipCode = "zip code"; String street = "street"; String house = "house"; String apartment = "apartment"; AssetAddress entity = new AssetAddress(); entity.setAdminUnit(adminUnit); entity.setAsset(asset); entity.setAddressType(addressType); entity.setStreetType(streetType); entity.setZipCode(zipCode); entity.setStreet(street); entity.setHouse(house); entity.setApartment(apartment); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("adminUnit", adminUnit); expected.put("asset", asset); expected.put("addressType", addressType); expected.put("streetType", streetType); expected.put("zipCode", zipCode); expected.put("street", street); expected.put("house", house); expected.put("apartment", apartment); when(adminUnitDao.getEntityById(anyLong())).thenReturn(adminUnit); when(assetDao.getEntityById(anyLong())).thenReturn(asset); when(addressTypeDao.getEntityById(anyLong())).thenReturn(addressType); when(streetTypeDao.getEntityById(anyLong())).thenReturn(streetType); Map<String, Object> actual = unit.getParameters(entity); verify(adminUnitDao).getEntityById(adminUnitId); verify(assetDao).getEntityById(assetId); verify(addressTypeDao).getEntityById(addressTypeId); verify(streetTypeDao).getEntityById(streetTypeId); assertEquals(expected, actual); }
@Test public void testGetParametersWithEmptyFields() throws Exception { AssetAddress entity = new AssetAddress(); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); Map<String, Object> actual = unit.getParameters(entity); verify(adminUnitDao, times(0)).getEntityById(anyLong()); verify(assetDao, times(0)).getEntityById(anyLong()); verify(addressTypeDao, times(0)).getEntityById(anyLong()); verify(streetTypeDao, times(0)).getEntityById(anyLong()); assertEquals(expected, actual); }
@Test public void testGetParametersWithEmptyFieldsAnd() throws Exception { unit.setActive(false); unit.setSecurity(false); AssetAddress entity = new AssetAddress(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); verify(adminUnitDao, times(0)).getEntityById(anyLong()); verify(assetDao, times(0)).getEntityById(anyLong()); verify(addressTypeDao, times(0)).getEntityById(anyLong()); verify(streetTypeDao, times(0)).getEntityById(anyLong()); assertEquals(expected, actual); }