OrderParametersExtractor extends AbstractParametersExtractor<Order> { @Override public Map<String, Object> getParameters(final Order entity, final Map<String, Object> parameters) { addParameter(entity.getOrderType(), orderTypeDao, "orderType", parameters); addParameter(entity.getEmployee(), employeeDao, "employee", parameters); addParameter(entity.getAsset(), assetDao, "asset", parameters); addParameter(entity.getPartner(), partnerDao, "partner", parameters); addParameter(entity.getOpType(), operationTypeDao, "opType", parameters); addParameter(entity.getReason(), reasonDao, "reason", parameters); addParameter(entity.getParent(), orderDao, "parent", parameters); addParameter(entity.getTimePeriod(), timePeriodDao, "timePeriod", parameters); addParameter(entity.getReasonText(), "reasonText", parameters); addParameter(entity.getDocSeries(), "docSeries", parameters); addParameter(entity.getDocNum(), "docNum", parameters); addParameter(entity.getDocDate(), "docDate", parameters); addParameter(entity.getDocIssued(), "docIssued", parameters); addParameter(entity.getEvDate(), "evDate", parameters); addParameter(entity.getTitle(), "title", parameters); addParameter(entity.getDescription(), "description", parameters); return parameters; }  @Override Map<String, Object> getParameters(final Order entity, final Map<String, Object> parameters);  }
@Test public void testGetParameters() throws Exception { Long orderTypeId = 1L; OrderType orderType = new OrderType(); orderType.setId(orderTypeId); Long employeeId = 2L; Employee employee = new Employee(); employee.setId(employeeId); Long assetId = 3L; Asset asset = new Asset(); asset.setId(assetId); Long partnerId = 4L; Partner partner = new Partner(); partner.setId(partnerId); Long operationTypeId = 5L; OperationType opType = new OperationType(); opType.setId(operationTypeId); Long reasonId = 6L; Reason reason = new Reason(); reason.setId(reasonId); Long parentId = 7L; Order parent = new Order(); parent.setId(parentId); String reasonText = "reason text"; String docSeries = "doc series"; String docNum = "dco num"; Date docDate = new Date(); Date evDate = new Date(); String docIssued = "doc issued"; Order entity = new Order(); entity.setOrderType(orderType); entity.setEmployee(employee); entity.setAsset(asset); entity.setPartner(partner); entity.setOpType(opType); entity.setReason(reason); entity.setParent(parent); entity.setReasonText(reasonText); entity.setDocSeries(docSeries); entity.setDocNum(docNum); entity.setDocDate(docDate); entity.setDocIssued(docIssued); entity.setEvDate(evDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("orderType", orderType); expected.put("employee", employee); expected.put("asset", asset); expected.put("partner", partner); expected.put("opType", opType); expected.put("reason", reason); expected.put("parent", parent); expected.put("reasonText", reasonText); expected.put("docSeries", docSeries); expected.put("docNum", docNum); expected.put("docDate", docDate); expected.put("docIssued", docIssued); expected.put("evDate", evDate); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); when(orderTypeDao.getEntityById(anyLong())).thenReturn(orderType); when(employeeDao.getEntityById(anyLong())).thenReturn(employee); when(assetDao.getEntityById(anyLong())).thenReturn(asset); when(partnerDao.getEntityById(anyLong())).thenReturn(partner); when(operationTypeDao.getEntityById(anyLong())).thenReturn(opType); when(reasonDao.getEntityById(anyLong())).thenReturn(reason); when(orderDao.getEntityById(anyLong())).thenReturn(parent); Map<String, Object> actual = unit.getParameters(entity); verify(orderTypeDao).getEntityById(orderTypeId); verify(employeeDao).getEntityById(employeeId); verify(assetDao).getEntityById(assetId); verify(partnerDao).getEntityById(partnerId); verify(operationTypeDao).getEntityById(operationTypeId); verify(reasonDao).getEntityById(reasonId); verify(orderDao).getEntityById(parentId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDisabledDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Long orderTypeId = 1L; OrderType orderType = new OrderType(); orderType.setId(orderTypeId); Long employeeId = 2L; Employee employee = new Employee(); employee.setId(employeeId); Long assetId = 3L; Asset asset = new Asset(); asset.setId(assetId); Long partnerId = 4L; Partner partner = new Partner(); partner.setId(partnerId); Long operationTypeId = 5L; OperationType opType = new OperationType(); opType.setId(operationTypeId); Long reasonId = 6L; Reason reason = new Reason(); reason.setId(reasonId); Long parentId = 7L; Order parent = new Order(); parent.setId(parentId); String reasonText = "reason text"; String docSeries = "doc series"; String docNum = "dco num"; Date docDate = new Date(); Date evDate = new Date(); String docIssued = "doc issued"; Order entity = new Order(); entity.setOrderType(orderType); entity.setEmployee(employee); entity.setAsset(asset); entity.setPartner(partner); entity.setOpType(opType); entity.setReason(reason); entity.setParent(parent); entity.setReasonText(reasonText); entity.setDocSeries(docSeries); entity.setDocNum(docNum); entity.setDocDate(docDate); entity.setDocIssued(docIssued); entity.setEvDate(evDate); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("orderType", orderType); expected.put("employee", employee); expected.put("asset", asset); expected.put("partner", partner); expected.put("opType", opType); expected.put("reason", reason); expected.put("parent", parent); expected.put("reasonText", reasonText); expected.put("docSeries", docSeries); expected.put("docNum", docNum); expected.put("docDate", docDate); expected.put("docIssued", docIssued); expected.put("evDate", evDate); when(orderTypeDao.getEntityById(anyLong())).thenReturn(orderType); when(employeeDao.getEntityById(anyLong())).thenReturn(employee); when(assetDao.getEntityById(anyLong())).thenReturn(asset); when(partnerDao.getEntityById(anyLong())).thenReturn(partner); when(operationTypeDao.getEntityById(anyLong())).thenReturn(opType); when(reasonDao.getEntityById(anyLong())).thenReturn(reason); when(orderDao.getEntityById(anyLong())).thenReturn(parent); Map<String, Object> actual = unit.getParameters(entity); verify(orderTypeDao).getEntityById(orderTypeId); verify(employeeDao).getEntityById(employeeId); verify(assetDao).getEntityById(assetId); verify(partnerDao).getEntityById(partnerId); verify(operationTypeDao).getEntityById(operationTypeId); verify(reasonDao).getEntityById(reasonId); verify(orderDao).getEntityById(parentId); assertEquals(expected, actual); }
@Test public void testGetParametersWithDefaultEntity() throws Exception { Order entity = new Order(); 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); Order entity = new Order(); 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); Order entity = new Order(); 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 testGetParametersWithDefaultEntityAndDisabledDetaults() throws Exception { unit.setActive(false); unit.setSecurity(false); Order entity = new Order(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }