示例#1
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;
 }
示例#2
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);
       }
     }
   }
 }
  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;
  }
示例#4
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);
       }
     }
   }
 }
示例#5
0
  public void test() {
    if (Helper.compareBigDecimals(new BigDecimal(0.01), new BigDecimal(0.001))) {
      throw new TestErrorException("Failed to compare two different BigDecimal numbers.");
    }
    if (Helper.compareBigDecimals(new BigDecimal(1.01), new BigDecimal(01.001))) {
      throw new TestErrorException("Failed to compare two equal BigDecimal numbers.");
    }

    String path = "c:\\test1\\test2\\test3\\";
    String expectedString = "c:\\\\test1\\\\test2\\\\test3\\\\";
    if (!Helper.doubleSlashes(path).equals(expectedString)) {
      throw new TestErrorException(
          "Failed to replace single slash with double slashes from the String.");
    }

    String vowels = "lalelilolule";
    expectedString = "llllll";
    if (!Helper.removeVowels(vowels).equals(expectedString)) {
      throw new TestErrorException("Failed to remove vowels from String.");
    }

    String excessCharacterString = "1x2x3x";
    expectedString = "123x";
    if (!Helper.removeCharacterToFit(excessCharacterString, 'x', 4).equals(expectedString)) {
      throw new TestErrorException("Failed to remove Character to fit String.");
    }

    Helper.printTimeFromMilliseconds(100);
    Helper.printTimeFromMilliseconds(10000);
    Helper.printTimeFromMilliseconds(100000);

    if (!(Helper.getInstanceFromClass(this.getClass()) instanceof BasicTest)) {
      throw new TestErrorException("Failed to get instance from Class.");
    }

    if (!(Helper.isPrimitiveWrapper(Character.class)
        && Helper.isPrimitiveWrapper(Boolean.class)
        && Helper.isPrimitiveWrapper(Byte.class)
        && Helper.isPrimitiveWrapper(Short.class)
        && Helper.isPrimitiveWrapper(Integer.class)
        && Helper.isPrimitiveWrapper(Long.class)
        && Helper.isPrimitiveWrapper(Float.class)
        && Helper.isPrimitiveWrapper(Double.class))) {
      throw new TestErrorException("Failed to check if a class is a primitive wrapper.");
    }

    java.util.Vector aVector = new java.util.Vector();
    Object elem = new BasicTest();
    aVector.addElement(elem);

    if (!Helper.makeVectorFromObject(aVector).equals(aVector)) {
      throw new TestErrorException("Failed to make a java.util.Vector from a java.util.Vector.");
    }

    HashSet set = new HashSet();
    set.add(elem);
    if (!Helper.makeVectorFromObject(set).equals(aVector)) {
      throw new TestErrorException("Failed to make a java.util.Vector from a java.util.Set.");
    }

    aVector.add(null);
    if (!Helper.removeNullElement(aVector)) {
      throw new TestErrorException("Failed to remove the first null element from java.util.Vector");
    }

    aVector.clear();
    for (int i = 0; i < 3; i++) {
      aVector.add(i, new Integer(i));
    }

    Vector reverseVector = Helper.reverseVector(aVector);
    for (int i = 0; i < 3; i++) {
      if (((Integer) reverseVector.elementAt(i)).intValue() != (2 - i)) {
        throw new TestErrorException("Failed to reverse elements of java.util.Vector");
      }
    }
  }
  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();
      }
    }
  }