Tests for the pureQuery nested bean examples

The test methods call pureQuery methods to instantiate and populate the beans. The test method lists the contents of the beans.

For the full JUnit test class, see JUnit test class for the pureQuery nested beans example.

Test method for nested beans defined by an interface containing the SQL query

In this test, the SQL statement is in the interface SimpleQueryInterface. These nested beans are tested:
    public void test_joinTest1() throws Exception {
        System.out.println("==Test1 nested beans with interface==");
        SimpleQueryInterface data = null;
        data = DataFactory.getData(SimpleQueryInterface.class, jdbcCon);

        System.out.println("==Get Dept data ==");
        List<Dept1> depts = data.joinTest();

        System.out.println("Employees by Dept:");
        for (Dept1 d : depts) {
            System.out.println(d.getDeptCode() + " - " + d.getDeptNameEn());
            List<Emp> employees = d.getDeptEmployees();
            if (!employees.isEmpty()) {
                for (Emp e : employees) {
                    System.out.println("  " + e.getLastName() + ", "
                            + e.getFirstName() + ",  " + e.toString());
                }
            } else {
                System.out.println(" -- No Employees-- ");
            }
        }
    }
This list is a sample for a single department:
7810 - Production and Distribution
  Agostini, Massimo,  ID: 10481
  Boscolo, Gabriella,  ID: 10480
  Ferrari, Arabela,  ID: 10304
  Gallo, Feliti,  ID: 10632
  Lombardi, Isabella,  ID: 10482
  Marino, Gualtier,  ID: 10793
  Medina, Benicio,  ID: 10483
  Morales, Ada,  ID: 10306

Test method for nested beans defined for an inline SQL query

This test lists the employees for each department. These nested beans are tested:
public void test_joinTest2() throws Exception {
        System.out.println("==Test2 nested bean with Inline SQL==");
        Data data = null;
        String myDeptNo = "6820";
        data = DataFactory.getData(jdbcCon);

        List<Dept2> depts = data
            queryList(
               "SELECT E.EMPLOYEE_CODE, E.FIRST_NAME, E.LAST_NAME, E.DATE_HIRED, "
                  + " ORG.ORGANIZATION_CODE, ORG.ORGANIZATION_NAME_EN"
                  + " FROM EMPLOYEE AS E, EMPLOYEE_HISTORY AS EH, ORGANIZATION AS ORG"
                  + " WHERE EH.EMPLOYEE_CODE = E.EMPLOYEE_CODE "
                  + "   AND EH.ORGANIZATION_CODE = ORG.ORGANIZATION_CODE"
                  + "   AND EH.RECORD_END_DATE IS NULL "
                  + " ORDER BY EH.ORGANIZATION_CODE, E.LAST_NAME ",
               Dept2.class);

        System.out.println("Employees by Dept:");
        for (Dept2 d : depts) {
            System.out.println(d.deptCode + " - " + d.deptNameEn);
            List<Emp> employees = d.deptEmployees;
            if (!employees.isEmpty()) {
                for (Emp e : employees) {
                    System.out.println("  " + e.getLastName() + ", "
                            + e.getFirstName() + ",  " + e.toString());
                }
            } else {
                System.out.println(" -- No Employees-- ");
            }
        }
    }
Note: In the test with the inline SQL, you can replace the Dept2 references with references to Dept1. For The Dept2 class, get and set methods define the bean properties. For the Dept1 class, public fields define the bean properties.
This list is a sample for a single department:
7810 - Production and Distribution
  Agostini, Massimo,  ID: 10481
  Boscolo, Gabriella,  ID: 10480
  Ferrari, Arabela,  ID: 10304
  Gallo, Feliti,  ID: 10632
  Lombardi, Isabella,  ID: 10482
  Marino, Gualtier,  ID: 10793
  Medina, Benicio,  ID: 10483
  Morales, Ada,  ID: 10306

Feedback