protected void buildExpectedResults() { ReadAllQuery query = new ReadAllQuery(); query.setReferenceClass(Employee.class); Vector employees = (Vector) getSession().executeQuery(query); Vector distinctEmployees = new Vector(); // initialize distinctEmployees distinctEmployees.addElement(employees.elementAt(0)); // check employees with duplicate province and add only distinct employees to distinctEmployees for (int i = 1; i < employees.size(); i++) { boolean duplicateFound = false; // iterate through distinctEmployees to check for duplicate provinces, if found, employee not // added for (int j = 0; j < distinctEmployees.size(); j++) { if ((((Employee) employees.elementAt(i)).getAddress().getProvince()) .equals((((Employee) distinctEmployees.elementAt(j)).getAddress().getProvince()))) { duplicateFound = true; } } if (!duplicateFound) { distinctEmployees.addElement(employees.elementAt(i)); } } for (Enumeration e = distinctEmployees.elements(); e.hasMoreElements(); ) { Employee emp = (Employee) e.nextElement(); Object[] result = new Object[1]; result[0] = emp.getAddress().getProvince(); addResult(result, null); } }
private void setArgumentsForTestUsing(Vector employees) { setArguments(new Vector()); Enumeration names = getExpressionParameters().elements(); Enumeration employeeEnum = employees.elements(); while (names.hasMoreElements()) { Employee emp = (Employee) employeeEnum.nextElement(); getArguments().add(emp.getId()); names.nextElement(); } }
protected void buildExpectedResults() { Vector projects = getSession().readAllObjects(LargeProject.class); for (Enumeration e = projects.elements(); e.hasMoreElements(); ) { LargeProject project = (LargeProject) e.nextElement(); if (project.getBudget() > 4000) { Object[] result = new Object[2]; result[0] = project.getName(); result[1] = new Double(project.getBudget()); addResult(result, null); } } }
public void setup() { // JGL: If the arguments are already set by the test, don't // set them again if (!hasArguments()) { setArgumentsForTestUsing(getSomeEmployees()); } ReadAllQuery raq = new ReadAllQuery(); raq.setReferenceClass(Employee.class); raq.setSelectionCriteria(getOriginalObjectExpression()); // Add all the arguments to the query Enumeration enumtr = getExpressionParameters().elements(); while (enumtr.hasMoreElements()) { raq.addArgument((String) enumtr.nextElement()); } // Save the retrieved employees for the verify setOriginalOject(getSession().executeQuery(raq, getArguments())); // Finish the setup super.setup(); }