@Test
  // this test calls other methods to execute the checkings
  public void test_generic03() {
    //
    // Setup routings:
    final I_AD_PrinterRouting printerRouting01 =
        helper.createPrinterRouting("test03-printer01", "tray01", -1, 1, 2);
    printerRouting01.setC_DocType_ID(1);
    helper.getDB().save(printerRouting01);

    final I_AD_PrinterRouting printerRouting02 =
        helper.createPrinterRouting("test03-printer02", "tray01", -1, 3, 4);
    printerRouting02.setC_DocType_ID(2);
    helper.getDB().save(printerRouting02);

    final I_AD_PrinterRouting printerRouting03 =
        helper.createPrinterRouting("test03-printer01", "tray01", -1, 5, 6);
    printerRouting03.setC_DocType_ID(3);
    helper.getDB().save(printerRouting03);

    //
    // Create printing queue
    helper.addToPrintQueue("01", 1, 1); // AD_Org_ID=1, C_DocType_ID=1
    helper.addToPrintQueue("02", 1, 2); // AD_Org_ID=1, C_DocType_ID=2
    helper.addToPrintQueue("03", 1, 3); // AD_Org_ID=1, C_DocType_ID=3

    //
    // Setup expected result
    // task 08958: we want the paged in the order of out print job line. i.e. two lines shall *not*
    // be aggregated into one, just because they match.
    // that is because we need a straight forward ordering and that is more important than
    // minimizing the number of print jobs.
    final byte[] pdfDataExpected =
        new PdfCollator()
            .addPages(helper.getPdf("01"), 1, 2)
            .addPages(helper.getPdf("02"), 3, 4)
            .addPages(helper.getPdf("03"), 5, 6)
            .toByteArray();

    final int printJobsCountExpected = 1;

    //
    // Execute Test
    executeGenericTest(printJobsCountExpected, pdfDataExpected);
  }
  @Test
  // this test calls other methods to execute the checkings
  public void test_generic02() {
    //
    // Setup routings:
    final I_AD_PrinterRouting printerRouting01 =
        helper.createPrinterRouting("printer01", "tray01", -1, -1, -1);
    printerRouting01.setAD_Org_ID(1);
    // printerRouting01.setAD_User_ID(1);
    printerRouting01.setC_DocType_ID(1);
    helper.getDB().save(printerRouting01);

    final I_AD_PrinterRouting printerRouting02 =
        helper.createPrinterRouting("printer01", "tray01", -1, 10, 15);
    printerRouting02.setAD_Org_ID(1);
    // printerRouting02.setAD_User_ID(1);
    printerRouting02.setC_DocType_ID(2);
    helper.getDB().save(printerRouting02);

    //
    // Create printing queue
    helper.addToPrintQueue("01", 1, 1); // AD_Org_ID=1, C_DocType_ID=1
    helper.addToPrintQueue("02", 1, 2); // AD_Org_ID=1, C_DocType_ID=2
    helper.addToPrintQueue("03", 1, 1); // AD_Org_ID=1, C_DocType_ID=1

    //
    // Setup expected result
    final byte[] pdfDataExpected =
        new PdfCollator()
            .addPages(helper.getPdf("01"), 1, 20)
            .addPages(helper.getPdf("02"), 10, 15)
            .addPages(helper.getPdf("03"), 1, 20)
            .toByteArray();

    final int printJobsCountExpected = 1;

    //
    // Execute Test
    executeGenericTest(printJobsCountExpected, pdfDataExpected);
  }
  @Test
  public void test_TwoPrintJobs_SecondOneIsUsedBecauseFirstOneFails() {
    //
    // Setup routings
    final I_AD_PrinterRouting routing1 =
        helper.createPrinterRouting("printer01", "tray01", -1, -1, -1);
    routing1.setAD_Org_ID(1);
    helper.getDB().save(routing1);
    final I_AD_PrinterRouting routing2 =
        helper.createPrinterRouting("printer02", "tray01", -1, -1, -1);
    routing2.setAD_Org_ID(2);
    helper.getDB().save(routing2);

    //
    // Create printing queue
    helper.addToPrintQueue("01", 1, -1); // AD_Org_ID=1, C_DocType_ID=N/A
    helper.addToPrintQueue("02", 2, -1); // AD_Org_ID=2, C_DocType_ID=N/A

    //
    // Expect 2 print jobs to be created
    final int printJobsCountActual = helper.createAllPrintJobs();
    Assert.assertEquals("Invalid Print Jobs count", 2, printJobsCountActual);

    final List<I_C_Print_Job> printJobs = helper.getDB().getRecords(I_C_Print_Job.class);
    Assert.assertEquals("Invalid Print Jobs count in database", 2, printJobs.size());

    // Validate PrintJob 1
    final I_C_Print_Job printJob1 = printJobs.get(0);
    {
      final List<I_C_Print_Job_Line> lines =
          IteratorUtils.toList(helper.getDAO().retrievePrintJobLines(printJob1));
      Assert.assertEquals("Job1 - Only one line was expected for " + printJob1, 1, lines.size());

      final I_C_Print_Job_Line line = lines.get(0);
      final I_C_Print_Job_Detail detail = helper.getDAO().retrievePrintJobDetails(line).get(0);
      Assert.assertEquals("Job1 - Invalid routing used", routing1, detail.getAD_PrinterRouting());
    }
    // Validate PrintJob 2
    final I_C_Print_Job printJob2 = printJobs.get(1);
    {
      final List<I_C_Print_Job_Line> lines =
          IteratorUtils.toList(helper.getDAO().retrievePrintJobLines(printJob2));
      Assert.assertEquals("Job2 - Only one line was expected for " + printJob2, 1, lines.size());

      final I_C_Print_Job_Line line = lines.get(0);
      final I_C_Print_Job_Detail detail = helper.getDAO().retrievePrintJobDetails(line).get(0);
      Assert.assertEquals("Job2 - Invalid routing used", routing2, detail.getAD_PrinterRouting());
    }

    //
    // Everything is fine.... now drop the matching for printer01
    // ... this shall produce errors when trying to generate the package for first print job
    {
      final I_AD_Printer_Matching matching =
          helper.getDAO().retrievePrinterMatching(helper.getSessionHostKey(), routing1);
      helper.getDB().delete(matching);
    }

    //
    // Creating next package
    // Expectations: printJob2 is used
    helper.createNextPrintPackageAndTest(
        printJob2, new PdfCollator().addPages(helper.getPdf("02"), 1, 20).toByteArray());

    //
    // Validate PrintJob1 Instructions
    {
      final I_C_Print_Job_Instructions instructions1 =
          helper.getDAO().retrievePrintJobInstructionsForPrintJob(printJob1);
      // task 09028: don't check for the host key..the user shall be able to print this wherever
      // they are logged inAssert.assertEquals("Job1 instructions - Invalid HostKey",
      // helper.getSessionHostKey(), instructions1.getHostKey());
      // Assert.assertEquals("Job1 instructions - Invalid status",
      // X_C_Print_Job_Instructions.STATUS_Error, instructions1.getStatus());
      Assert.assertNotNull(
          "Job1 instructions - Missing error message", instructions1.getErrorMsg());
    }

    //
    // Validate PrintJob2 Instructions
    {
      final I_C_Print_Job_Instructions instructions2 =
          helper.getDAO().retrievePrintJobInstructionsForPrintJob(printJob2);
      // task 09028: don't check for the host key..the user shall be able to print this wherever
      // they are logged in
      // Assert.assertEquals("Job2 instructions - Invalid HostKey", helper.getSessionHostKey(),
      // instructions2.getHostKey());
      Assert.assertEquals(
          "Job2 instructions - Invalid status",
          X_C_Print_Job_Instructions.STATUS_Send,
          instructions2.getStatus());
      Assert.assertNull("Job2 instructions - Missing error message", instructions2.getErrorMsg());
    }

    //
    // Recreate back the HW matching for printer01
    helper.createPrinterConfigAndMatching(
        helper.getSessionHostKey(), "printer01-hw-again", "tray01-hw-again", "printer01", "tray01");

    //
    // Job1 instructions, prepare it again
    {
      final I_C_Print_Job_Instructions instructions1 =
          helper.getDAO().retrievePrintJobInstructionsForPrintJob(printJob1);
      instructions1.setStatus(X_C_Print_Job_Instructions.STATUS_Pending);
      instructions1.setErrorMsg(null);
      InterfaceWrapperHelper.save(instructions1);
    }

    //
    // Creating next package
    // Expectations: printJob1 is used
    {
      helper.createNextPrintPackageAndTest(
          printJob1, new PdfCollator().addPages(helper.getPdf("01"), 1, 20).toByteArray());
    }

    //
    // Validate PrintJob2 Instructions
    {
      final I_C_Print_Job_Instructions instructions1 =
          helper.getDAO().retrievePrintJobInstructionsForPrintJob(printJob1);
      Assert.assertEquals(
          "Job1 instructions - Invalid status",
          X_C_Print_Job_Instructions.STATUS_Send,
          instructions1.getStatus());
      Assert.assertNull("Job1 instructions - Missing error message", instructions1.getErrorMsg());
    }

    //
    // Final assumptions
    assumePrintQueueProcessed();
    assumePrintJobInstructions(X_C_Print_Job_Instructions.STATUS_Send); // everything is Send
    assumePrintJobsProcessed();
    helper.assumeNothingLocked();
  }