Пример #1
0
  /**
   * Return the first employee that has a long enough name for the test. If no match is found throw
   * a warning exception. See bug 223005
   *
   * @param vectorOfEmployees
   * @param minFirstNameLength
   * @param testName
   * @return
   */
  public Employee getEmployeeWithRequiredNameLength(
      Vector vectorOfEmployees, int minFirstNameLength, String testName) {
    Employee empMatch = null;
    Vector<Employee> employees = vectorOfEmployees;
    String firstName;
    StringBuffer partialFirstName;

    // Loop through the collection of employees to find one that matches our test requirements
    for (int i = 0; i < employees.size(); i++) {
      empMatch = employees.get(i);
      firstName = empMatch.getFirstName();
      // Verify length criteria
      if (firstName.length() >= minFirstNameLength) {
        // exit the for loop - return the last empMatch
        i = employees.size();
      }
    }

    // If we could not find a proper employee for testing - throw a warning
    if (null == empMatch) {
      throw new RuntimeException(
          testName
              + " Setup Failed: unable to find an Employee with firstName size of at least  "
              + minFirstNameLength);
    } else {
      return empMatch;
    }
  }
Пример #2
0
  protected void buildExpectedResults() {
    Vector employees = getSession().readAllObjects(Employee.class);

    Object[] result = new Object[1];
    result[0] = new java.math.BigDecimal(employees.size());
    addResult(result, null);
  }
 /**
  * Verify that the query ran successfully, and that the number of objects returned matches the
  * number of managed employees.
  */
 protected void verify() throws Exception {
   Vector params = new Vector();
   params.add(someManager.getId()); // numberOfManagedEmployees
   try {
     Vector results = (Vector) getSession().executeQuery(query, params);
     if (!(numberOfManagedEmployees == results.size())) {
       throw new TestErrorException(
           results.size()
               + " objects were read from the database, but originially there were, "
               + numberOfManagedEmployees
               + ".");
     }
   } catch (org.eclipse.persistence.exceptions.DatabaseException e) {
     throw new TestErrorException(
         "Custom SQL subquery with parameters failed with a DatabaseException.");
   }
 }
Пример #4
0
 /**
  * Remove the first null element found in the specified vector. Return true if a null element was
  * found and removed. Return false if a null element was not found.
  */
 private boolean removeNullElement(Vector v) {
   for (int i = 0; i < v.size(); i++) {
     if (v.elementAt(i) == null) {
       v.removeElementAt(i);
       return true;
     }
   }
   return false;
 }
Пример #5
0
 /**
  * Assert that the elements in two vectors are equal. If they are not, throw an
  * AssertionFailedError. The order of the elements is ignored.
  *
  * @param message the error message
  * @param expected the expected value of an vector
  * @param actual the actual value of an vector
  */
 protected void assertUnorderedElementsEqual(String message, Vector expected, Vector actual) {
   if (expected == actual) {
     return;
   }
   if (expected.size() != actual.size()) {
     this.assertTrue(this.notEqualsMessage(message, expected, actual), false);
   }
   Vector temp = (Vector) actual.clone();
   for (int i = 0; i < expected.size(); i++) {
     Object e1 = expected.elementAt(i);
     if (e1 == null) { // avoid null pointer exception
       if (!this.removeNullElement(temp)) {
         this.assertTrue(this.notEqualsMessage(message, expected, actual), false);
       }
     } else {
       if (!temp.removeElement(e1)) {
         this.assertTrue(this.notEqualsMessage(message, expected, actual), false);
       }
     }
   }
 }
Пример #6
0
 /**
  * Assert that the elements in two vectors are equal. If they are not, throw an
  * AssertionFailedError. Order of the elements is significant.
  *
  * @param message the error message
  * @param expected the expected value of an vector
  * @param actual the actual value of an vector
  */
 protected void assertElementsEqual(String message, Vector expected, Vector actual) {
   if (expected == actual) {
     return;
   }
   if (expected.size() != actual.size()) {
     this.assertTrue(this.notEqualsMessage(message, expected, actual), false);
   }
   for (int i = 0; i < expected.size(); i++) {
     Object e1 = expected.elementAt(i);
     Object e2 = actual.elementAt(i);
     if (e1 == null) { // avoid null pointer exception
       if (e2 != null) {
         this.assertTrue(this.notEqualsMessage(message, expected, actual), false);
       }
     } else {
       if (!e1.equals(e2)) {
         this.assertTrue(this.notEqualsMessage(message, expected, actual), false);
       }
     }
   }
 }
Пример #7
0
  public Vector getAttributeFromAll(String attributeName, Vector objects) {
    ClassDescriptor descriptor = getSession().getClassDescriptor(getReferenceClass());
    DirectToFieldMapping mapping =
        (DirectToFieldMapping) descriptor.getMappingForAttributeName(attributeName);

    Vector attributes = new Vector();
    Object currentObject;
    for (int i = 0; i < objects.size(); i++) {
      currentObject = objects.elementAt(i);
      if (currentObject.getClass() == ReportQueryResult.class) {
        attributes.addElement(((ReportQueryResult) currentObject).get(attributeName));
      } else {
        attributes.addElement(mapping.getAttributeValueFromObject(currentObject));
      }
    }
    return attributes;
  }
 public void verify() {
   if (results.size() != 6) {
     throw new TestErrorException(
         "The incorrect number of results was returned from a ReportQuery that included a random function.");
   }
 }
  public void test() {

    ReadAllQuery query = new ReadAllQuery();
    ScrollableCursor cursor = null;

    try {
      query.setReferenceClass(Employee.class);
      if (TYPE_SCROLL_INSENSITIVE_isSupported && CONCUR_UPDATABLE_isSupported) {
        query.useScrollableCursor(2);
      } else {
        ScrollableCursorPolicy policy = new ScrollableCursorPolicy();
        if (!TYPE_SCROLL_INSENSITIVE_isSupported) {
          policy.setResultSetType(ScrollableCursorPolicy.TYPE_SCROLL_SENSITIVE);
        }
        if (!CONCUR_UPDATABLE_isSupported) {
          policy.setResultSetConcurrency(ScrollableCursorPolicy.CONCUR_READ_ONLY);
        }
        policy.setPageSize(2);
        query.useScrollableCursor(policy);
      }
      //
      if (configuration != null) {
        ExpressionBuilder builder = new ExpressionBuilder();
        Expression exp = builder.get("salary").greaterThan(50000);
        query.setSelectionCriteria(exp);
        query.conformResultsInUnitOfWork();
      }
      cursor = (ScrollableCursor) getSession().executeQuery(query);

      try {
        // test to see if we can iterate through a list and then iterate
        // in reverse through the same list.
        int totalItems = 0;
        while (cursor.hasNext()) {
          readWithNext.addElement(cursor.next());
          totalItems++;
        }
        while (cursor.hasPrevious()) {
          readWithPrevious.addElement(cursor.previous());
          totalItems--;
        }

        cursorSuccess = (totalItems == 0);

        int size = readWithPrevious.size();
        for (int i = 0; i < readWithNext.size(); i++) {
          cursorSuccess =
              (cursorSuccess
                  && (readWithNext.elementAt(i) == readWithPrevious.elementAt((size - 1) - i)));
        }

      } catch (org.eclipse.persistence.exceptions.QueryException ex) {
        caughtException = ex;
      }

    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
  }