OrderResourceConverter extends AbstractConverter<OrderResource, Order> { @Override public Order convert(final OrderResource source, final Order target) { if (source.getOrderTypeId() != null) { OrderType orderType = new OrderType(); orderType.setId(source.getOrderTypeId()); target.setOrderType(orderType); } if (source.getEmployeeId() != null) { Employee employee = new Employee(); employee.setId(source.getEmployeeId()); target.setEmployee(employee); } if (source.getAssetId() != null) { Asset asset = new Asset(); asset.setId(source.getAssetId()); target.setAsset(asset); } if (source.getPartnerId() != null) { Partner partner = new Partner(); partner.setId(source.getPartnerId()); target.setPartner(partner); } if (source.getOperationTypeId() != null) { OperationType operationType = new OperationType(); operationType.setId(source.getOperationTypeId()); target.setOpType(operationType); } if (source.getDepartmentId() != null) { Department department = new Department(); department.setId(source.getDepartmentId()); target.setDepartment(department); } if (source.getReasonId() != null) { Reason reason = new Reason(); reason.setId(source.getReasonId()); target.setReason(reason); } if (source.getParentId() != null) { Order parent = new Order(); parent.setId(source.getParentId()); target.setParent(parent); } if (source.getTimePeriodId() != null) { TimePeriod timePeriod = new TimePeriod(); timePeriod.setId(source.getTimePeriodId()); target.setTimePeriod(timePeriod); } target.setReasonText(source.getReasonText()); target.setDocSeries(source.getDocSeries()); target.setDocNum(source.getDocNum()); target.setDocDate(source.getDocDate()); target.setDocIssued(source.getDocIssued()); target.setEvDate(source.getEvDate()); target.setDescription(source.getDescription()); target.setTitle(source.getTitle()); return target; }  @Override Order convert(final OrderResource source, final Order target); @Override Order convert(final OrderResource source);  }
@Test public void testConvert() 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 departmentId = 6L; Department department = new Department(); department.setId(departmentId); Long reasonId = 7L; Reason reason = new Reason(); reason.setId(reasonId); Long parentId = 8L; Order parent = new Order(); parent.setId(parentId); String reasonText = "reasonText"; String docSeries = "docSeries"; String docNum = "docnum"; Date docDate = new Date(); String docIssued = "docIssued"; Date evDate = new Date(); Order expected = new Order(); expected.setOrderType(orderType); expected.setEmployee(employee); expected.setAsset(asset); expected.setPartner(partner); expected.setOpType(opType); expected.setDepartment(department); expected.setReason(reason); expected.setParent(parent); expected.setReasonText(reasonText); expected.setDocSeries(docSeries); expected.setDocNum(docNum); expected.setDocDate(docDate); expected.setDocIssued(docIssued); expected.setEvDate(evDate); OrderResource source = new OrderResource(); source.setOrderTypeId(orderTypeId); source.setEmployeeId(employeeId); source.setAssetId(assetId); source.setPartnerId(partnerId); source.setOperationTypeId(operationTypeId); source.setDepartmentId(departmentId); source.setReasonId(reasonId); source.setParentId(parentId); source.setReasonText(reasonText); source.setDocSeries(docSeries); source.setDocNum(docNum); source.setDocDate(docDate); source.setDocIssued(docIssued); source.setEvDate(evDate); Order actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String reasonText = "reasonText"; String docSeries = "docSeries"; String docNum = "docnum"; Date docDate = new Date(); String docIssued = "docIssued"; Date evDate = new Date(); Order expected = new Order(); expected.setReasonText(reasonText); expected.setDocSeries(docSeries); expected.setDocNum(docNum); expected.setDocDate(docDate); expected.setDocIssued(docIssued); expected.setEvDate(evDate); OrderResource source = new OrderResource(); source.setReasonText(reasonText); source.setDocSeries(docSeries); source.setDocNum(docNum); source.setDocDate(docDate); source.setDocIssued(docIssued); source.setEvDate(evDate); Order actual = unit.convert(source); assertEquals(expected, actual); }