AssetParametersExtractor extends AbstractParametersExtractor<Asset> { @Override public Map<String, Object> getParameters(final Asset entity, final Map<String, Object> parameters) { addParameter(entity.getDescription(), "description", parameters); addParameter(entity.getEndDate(), "endDate", parameters); addParameter(entity.getBegDate(), "begDate", parameters); addParameter(entity.getProdDate(), "prodDate", parameters); addParameter(entity.getSerialNum(), "serialNum", parameters); addParameter(entity.getInvNum(), "invNum", parameters); addParameter(entity.getName(), "name", parameters); addParameter(entity.getParent(), assetDao, "parent", parameters); addParameter(entity.getOrder(), orderDao, "order", parameters); addParameter(entity.getPartner(), partnetDao, "partner", parameters); addParameter(entity.getEmployee(), employeeDao, "employee", parameters); addParameter(entity.getDepartment(), departmentDao, "department", parameters); addParameter(entity.getAssetType(), assetTypeDao, "assetType", parameters); addParameter(entity.getAssetState(), assetStateDao, "assetState", parameters); addParameter(entity.getAssetStatus(), assetStatusDao, "assetStatus", parameters); return parameters; }  @Override Map<String, Object> getParameters(final Asset entity, final Map<String, Object> parameters);  }
@Test public void testGetParameters() throws Exception { String description = "description"; Date endDate = new Date(); Date begDate = new Date(); Date prodDate = new Date(); String serialNum = "serial num"; String invNum = "inv num"; String name = "name"; Long parentId = 1L; Asset parent = new Asset(); parent.setId(parentId); Long orderId = 2L; Order order = new Order(); order.setId(orderId); Long partnerId = 4L; Partner partner = new Partner(); partner.setId(partnerId); Long departmentId = 5L; Department department = new Department(); department.setId(departmentId); Long assetTypeId = 6L; AssetType assetType = new AssetType(); assetType.setId(assetTypeId); Long employeeId = 7L; Employee employee = new Employee(); employee.setId(employeeId); Long assetStateId = 8L; AssetState assetState = new AssetState(); assetState.setId(assetStateId); Long assetStatusId = 9L; AssetStatus assetStatus = new AssetStatus(); assetStatus.setId(assetStatusId); Asset entity = new Asset(); entity.setDescription(description); entity.setEndDate(endDate); entity.setBegDate(begDate); entity.setProdDate(prodDate); entity.setSerialNum(serialNum); entity.setInvNum(invNum); entity.setName(name); entity.setParent(parent); entity.setOrder(order); entity.setPartner(partner); entity.setEmployee(employee); entity.setDepartment(department); entity.setAssetType(assetType); entity.setAssetState(assetState); entity.setAssetStatus(assetStatus); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("description", description); expected.put("endDate", endDate); expected.put("begDate", begDate); expected.put("prodDate", prodDate); expected.put("serialNum", serialNum); expected.put("invNum", invNum); expected.put("name", name); expected.put("parent", parent); expected.put("order", order); expected.put("partner", partner); expected.put("employee", employee); expected.put("department", department); expected.put("assetType", assetType); expected.put("assetState", assetState); expected.put("assetStatus", assetStatus); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(assetDao.getEntityById(anyLong())).thenReturn(parent); when(orderDao.getEntityById(anyLong())).thenReturn(order); when(partnetDao.getEntityById(anyLong())).thenReturn(partner); when(employeeDao.getEntityById(anyLong())).thenReturn(employee); when(departmentDao.getEntityById(anyLong())).thenReturn(department); when(assetTypeDao.getEntityById(anyLong())).thenReturn(assetType); when(assetStateDao.getEntityById(anyLong())).thenReturn(assetState); when(assetStatusDao.getEntityById(anyLong())).thenReturn(assetStatus); Map<String, Object> actual = unit.getParameters(entity); verify(assetDao).getEntityById(parentId); verify(orderDao).getEntityById(orderId); verify(partnetDao).getEntityById(partnerId); verify(employeeDao).getEntityById(employeeId); verify(departmentDao).getEntityById(departmentId); verify(assetTypeDao).getEntityById(assetTypeId); verify(assetStatusDao).getEntityById(assetStatusId); verify(assetStateDao).getEntityById(assetStateId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDEtauls() throws Exception { unit.setActive(false); unit.setSecurity(false); String description = "description"; Date endDate = new Date(); Date begDate = new Date(); Date prodDate = new Date(); String serialNum = "serial num"; String invNum = "inv num"; String name = "name"; Long parentId = 1L; Asset parent = new Asset(); parent.setId(parentId); Long orderId = 2L; Order order = new Order(); order.setId(orderId); Long partnerId = 4L; Partner partner = new Partner(); partner.setId(partnerId); Long departmentId = 5L; Department department = new Department(); department.setId(departmentId); Long assetTypeId = 6L; AssetType assetType = new AssetType(); assetType.setId(assetTypeId); Long employeeId = 7L; Employee employee = new Employee(); employee.setId(employeeId); Long assetStateId = 8L; AssetState assetState = new AssetState(); assetState.setId(assetStateId); Long assetStatusId = 9L; AssetStatus assetStatus = new AssetStatus(); assetStatus.setId(assetStatusId); Asset entity = new Asset(); entity.setDescription(description); entity.setEndDate(endDate); entity.setBegDate(begDate); entity.setProdDate(prodDate); entity.setSerialNum(serialNum); entity.setInvNum(invNum); entity.setName(name); entity.setParent(parent); entity.setOrder(order); entity.setPartner(partner); entity.setEmployee(employee); entity.setDepartment(department); entity.setAssetType(assetType); entity.setAssetState(assetState); entity.setAssetStatus(assetStatus); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("description", description); expected.put("endDate", endDate); expected.put("begDate", begDate); expected.put("prodDate", prodDate); expected.put("serialNum", serialNum); expected.put("invNum", invNum); expected.put("name", name); expected.put("parent", parent); expected.put("order", order); expected.put("partner", partner); expected.put("employee", employee); expected.put("department", department); expected.put("assetType", assetType); expected.put("assetState", assetState); expected.put("assetStatus", assetStatus); when(assetDao.getEntityById(anyLong())).thenReturn(parent); when(orderDao.getEntityById(anyLong())).thenReturn(order); when(partnetDao.getEntityById(anyLong())).thenReturn(partner); when(employeeDao.getEntityById(anyLong())).thenReturn(employee); when(departmentDao.getEntityById(anyLong())).thenReturn(department); when(assetTypeDao.getEntityById(anyLong())).thenReturn(assetType); when(assetStateDao.getEntityById(anyLong())).thenReturn(assetState); when(assetStatusDao.getEntityById(anyLong())).thenReturn(assetStatus); Map<String, Object> actual = unit.getParameters(entity); verify(assetDao).getEntityById(parentId); verify(orderDao).getEntityById(orderId); verify(partnetDao).getEntityById(partnerId); verify(employeeDao).getEntityById(employeeId); verify(departmentDao).getEntityById(departmentId); verify(assetTypeDao).getEntityById(assetTypeId); verify(assetStatusDao).getEntityById(assetStatusId); verify(assetStateDao).getEntityById(assetStateId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { Asset entity = new Asset(); 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); Asset entity = new Asset(); 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); Asset entity = new Asset(); 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); Asset entity = new Asset(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }