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); }
/** A clean way to specify which tests run on which platforms. */ public boolean isPlatformSupported(DatabasePlatform platform) { boolean supported = false; boolean notSupported = false; if ((unsupportedPlatforms == null) && (supportedPlatforms == null)) { return true; } if (supportedPlatforms != null) { for (Iterator iterator = supportedPlatforms.iterator(); iterator.hasNext(); ) { Class platformClass = (Class) iterator.next(); if (platformClass.isInstance(platform)) { supported = true; } } } else { supported = true; } if (unsupportedPlatforms != null) { for (Iterator iterator = unsupportedPlatforms.iterator(); iterator.hasNext(); ) { Class platformClass = (Class) iterator.next(); if (platformClass.isInstance(platform)) { notSupported = true; } } } return supported && (!notSupported); }
public static BinaryOperatorWithParameterTest getNumericParameterDivideTestWithBracketsAfterComparison() { BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest(); theTest.setName("Divide with parameter test with brackets after comparison"); String parameterName = "amountToDivide"; theTest.setExpressionParameters(new Vector()); theTest.getExpressionParameters().add(parameterName); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = ExpressionBuilder.fromConstant(new Integer(20000), builder) .greaterThan( ExpressionMath.divide( builder.get("salary"), (builder.getParameter(parameterName)))); theTest.setOriginalObjectExpression(whereClause); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE 20000 > (emp.salary / ?1)"; theTest.setEjbqlString(ejbqlString); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); theTest.setArgumentNames(myArgumentNames); theTest.setArguments(new Vector()); theTest.getArguments().addElement(new Integer(2)); return theTest; }
public static BinaryOperatorWithParameterTest getNumericParameterDivideTest() { BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest(); theTest.setName("Divide with parameter test"); String parameterName = "amountToDivide"; theTest.setExpressionParameters(new Vector()); theTest.getExpressionParameters().add(parameterName); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = ExpressionMath.divide(builder.get("salary"), (builder.getParameter(parameterName))) .lessThanEqual(20000); theTest.setOriginalObjectExpression(whereClause); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE emp.salary / ?1 <= 20000"; theTest.setEjbqlString(ejbqlString); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); theTest.setArgumentNames(myArgumentNames); theTest.setArguments(new Vector()); theTest.getArguments().addElement(new Integer(2)); return theTest; }
public static BinaryOperatorWithParameterTest getNumericParameterMultiplyTestWithBracketsBeforeComparison() { BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest(); theTest.setName("Multiply with parameter test with brackets before comparison"); String parameterName = "amountToMultiply"; theTest.setExpressionParameters(new Vector()); theTest.getExpressionParameters().add(parameterName); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = ExpressionMath.multiply(builder.get("salary"), (builder.getParameter(parameterName))) .lessThanEqual(100000); theTest.setOriginalObjectExpression(whereClause); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE (emp.salary * ?1) <= 100000"; theTest.setEjbqlString(ejbqlString); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); theTest.setArgumentNames(myArgumentNames); theTest.setArguments(new Vector()); theTest.getArguments().addElement(new Integer(2)); return theTest; }
/** * 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; } }
/** * 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; }
public static Vector testInstancesWithBindingAndNoCalendarPrinting() { Vector tests = new Vector(calendarStrings.length); for (int i = 0; i < calendarStrings.length; i++) { tests.add( new CalendarToTSTZWithBindingTest( i + (calendarStrings.length + 1), calendarStrings[i], false)); } return tests; }
/** Vector. */ public void test() throws Exception { Vector vector = new Vector(10); for (int index = 0; index < size; index++) { vector.add(new Integer(index)); } for (int index = 0; index < size; index++) { Object result = vector.get(index); } }
public void test() { // read data back from database literally in order to check contents of database rather than the // driver's TIMESTAMPTZ String sql = "select TEST_ID, to_char(TSTZ_DATA,'MM/DD/YYYY hh24:mi:ss TZR') as TSTZ_DATA FROM " + commonDescriptor().getTableName() + " where TEST_ID = " + getTestId(); Vector result = getSession().executeSQL(sql); if (result != null & !result.isEmpty()) { this.result = (DatabaseRecord) result.firstElement(); } }
public void test() { int size = getCacheIdentityMap().getMaxSize() * factor; for (int i = 0; i < size; i++) { BigDecimal id = new java.math.BigDecimal(i); Employee employee = new Employee(); Vector pk = new Vector(1); employee.setId(id); employee.setFirstName("Joe"); employee.setLastName("Blow"); pk.add(id); getPrimaryKeys().add(pk); getCacheIdentityMap().put(primaryKeys, employee, null, 0); } }
/** * 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."); } }
/** getObject. */ public void test() throws Exception { PreparedStatement statement = connection.prepareStatement(sql); ResultSet result = statement.executeQuery(); int size = result.getMetaData().getColumnCount(); Vector rows = new Vector(); while (result.next()) { Vector row = new Vector(size); for (int column = 1; column <= size; column++) { Object value = result.getObject(column); value = ConversionManager.getDefaultManager().convertObject(value, ClassConstants.SQLDATE); row.add(value); } rows.add(row); } result.close(); statement.close(); }
protected void verify() throws TestException { RecordMetaData record = (RecordMetaData) records.firstElement(); if (!CobolTestModel.compareCompositeObjects( record, CobolTestModel.getComplexPicStatementRecord())) { TestErrorException exception = new TestErrorException("The records do not match."); setTestException(exception); } }
public void addDescriptors(DatabaseSession session) { Vector descriptors = new Vector(); descriptors.addElement(LockInCache.descriptor()); descriptors.addElement(LockInObject.descriptor()); descriptors.addElement(TimestampInCache.descriptor()); descriptors.addElement(TimestampInObject.descriptor()); descriptors.addElement(TimestampVersion.descriptor()); descriptors.addElement(TimestampInAggregateObject.descriptor()); // descriptors.addElement(ObjectVersion.descriptor()); descriptors.addElement(LockInAggregateObject.descriptor()); // descriptors.addElement(ChangedRow.descriptor()); (session).addDescriptors(descriptors); (session).addDescriptors(new RockBandProject()); (session).addDescriptors(new AnimalProject()); }
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; }
/* * This verify method presumes that the stored procedure in EmployeeCustomSQLSystem.buildSQLInsertProcedure * has not changed and still returns an output parameter VERSION with value 952 */ public void verify() { if (this.events.isEmpty()) { throw new TestErrorException("No session events were thrown and some were expected"); } else { if (((Number) ((DatabaseRecord) ((SessionEvent) events.firstElement()).getResult()) .get("EMPLOYEE.VERSION")) .intValue() != 952) { throw new TestErrorException("Wrong value returned"); } if (((WriteObjectQuery) ((SessionEvent) events.firstElement()).getQuery()).getObject() == null) { throw new TestErrorException("Object not set"); } } }
public void test() { Vector sessions = new Vector(); try { for (int i = 0; i < stressLevel; i++) { Session session = new Project(getSession().getDatasourceLogin().clone()).createDatabaseSession(); ((DatabaseSession) session).login(); sessions.addElement(session); } getSession().readObject(Address.class); } finally { for (Enumeration sessionEnum = sessions.elements(); sessionEnum.hasMoreElements(); ) { ((DatabaseSession) sessionEnum.nextElement()).logout(); } } getSession().readObject(Address.class); }
public ReadAllBindAllParametersTest() { v = new Vector(2); v.addElement(new BigDecimal(1001)); v.addElement(new BigDecimal(1002)); setName("ReadAllBindAllParametersTest"); setDescription( "Tests all combinations of shouldBindAllParameters attributes on Session and Query"); }
protected void test() { for (int i = 0; i <= 1; i++) { getSession().getPlatform().setShouldBindAllParameters(i != 0); for (int j = 0; j <= 2; j++) { query = new ReadAllQuery(Employee.class); ExpressionBuilder builder = new ExpressionBuilder(); Vector vExp = new Vector(2); vExp.add(builder.getParameter("p1")); query.addArgument("p1"); vExp.add(builder.getParameter("p2")); query.addArgument("p2"); Expression exp = builder.get("id").in(vExp); query.setSelectionCriteria(exp); switch (j) { case 0: // nothing to do - just test the default: // query.bindAllParameters == Undefined break; case 1: // query.bindAllParameters == False query.setShouldBindAllParameters(false); break; case 2: // query.bindAllParameters == True query.setShouldBindAllParameters(true); break; } // clear the writer's buffer ((StringWriter) getSession().getLog()).getBuffer().setLength(0); try { getSession().executeQuery(query, v); } catch (DatabaseException e) { throw new TestProblemException("executeQuery threw DatabaseException"); } if (shouldBind() != wasBound()) { return; } } } }
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(); } }
public static BinaryOperatorWithParameterTest getNumericTwoParameterMultipleOperatorsWithBracketsAroundMultiply() { BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest(); theTest.setName("Multiple operators with two parameters with brackets around multiply"); String parameterNameForDivide = "amountToDivide"; String parameterNameForMultiply = "amountToMultiply"; theTest.setExpressionParameters(new Vector()); theTest.getExpressionParameters().add(parameterNameForDivide); theTest.getExpressionParameters().add(parameterNameForMultiply); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = builder .get("salary") .greaterThan( ExpressionMath.subtract( ExpressionMath.add( ExpressionBuilder.fromConstant(new Integer(50000), builder), 10000), ExpressionMath.divide( ExpressionBuilder.fromConstant(new Integer(10000), builder), ExpressionMath.multiply( builder.getParameter(parameterNameForMultiply), builder.getParameter(parameterNameForDivide))))); theTest.setOriginalObjectExpression(whereClause); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE emp.salary > (50000 + 10000 - 10000 / (?1 * ?2))"; theTest.setEjbqlString(ejbqlString); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); myArgumentNames.add("2"); theTest.setArgumentNames(myArgumentNames); theTest.setArguments(new Vector()); theTest.getArguments().addElement(new Integer(2)); theTest.getArguments().addElement(new Integer(5)); return theTest; }
/** * 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 void test() { Vector primaryKeys = new Vector(); primaryKeys.add(new java.math.BigDecimal(4)); CacheKey cacheKey = getAbstractSession() .getIdentityMapAccessorInstance() .acquireDeferredLock( primaryKeys, Employee.class, getSession().getDescriptor(Employee.class), false); CacheKey cacheKey2 = getAbstractSession() .getIdentityMapAccessorInstance() .acquireDeferredLock( primaryKeys, Employee.class, getSession().getDescriptor(Employee.class), false); if (cacheKey != cacheKey2) { throw new TestErrorException( "WeakIdentityMap failed to return same cachkey for successive calls for same primary key and class"); } // must release because the deferred lock is not removed on an initialize identity map cacheKey.releaseDeferredLock(); cacheKey2.releaseDeferredLock(); }
public static BinaryOperatorWithParameterTest getNumericParameterLessThanEqualTest() { BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest(); theTest.setName("Less than equal to with parameter test"); String parameterName = "id"; theTest.setExpressionParameters(new Vector()); theTest.getExpressionParameters().add(parameterName); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = builder.get("id").lessThanEqual(builder.getParameter(parameterName)); theTest.setOriginalObjectExpression(whereClause); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE "; ejbqlString = ejbqlString + "emp.id <= ?1 "; theTest.setEjbqlString(ejbqlString); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); theTest.setArgumentNames(myArgumentNames); return theTest; }
public void setup() { if ((getSession().getLogin().getPlatform().isSQLServer())) { throw new TestWarningException( "This test is not supported on SQL Server. Because 'LENGTH' is not a recognized function name on SQL Server."); } Vector employees = getSomeEmployees(); Employee emp = (Employee) employees.firstElement(); String ejbqlString; ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE "; ejbqlString = ejbqlString + emp.getFirstName().length(); ejbqlString = ejbqlString + " = LENGTH(emp.firstName)"; ejbqlString = ejbqlString + " AND "; ejbqlString = ejbqlString + emp.getLastName().length(); ejbqlString = ejbqlString + " = LENGTH(emp.lastName)"; setEjbqlString(ejbqlString); setOriginalOject(emp); super.setup(); }
protected void changeUnitOfWorkWorkingCopy() { Employee employee = (Employee) this.unitOfWorkWorkingCopy; AddressDescription addressDescription = employee.getAddressDescription(); ProjectDescription projectDescription = employee.getProjectDescription(); Language language; Vector languages; // Root object changed employee.setFirstName(null); employee.setLastName(null); // Third level aggregate object changed addressDescription.setPeriodDescription(null); // 1 to 1 mapped object changed projectDescription.getComputer().setValue(null); // 1 level aggregate's 1:M mapping projectDescription.getResponsibilities().setValue(null); languages = (Vector) projectDescription.getLanguages().getValue(); language = (Language) languages.firstElement(); language.setLanguage(null); // 1 level aggregate's M:M mapping, adding a new element // languages.addElement(null); }
public static BinaryOperatorWithParameterTest getNumericTwoParameterMultipleOperatorsWithBracketsAroundPlusMinus() { BinaryOperatorWithParameterTest theTest = new BinaryOperatorWithParameterTest(); theTest.setName("Multiple operators with two parameters with brackets around plus/minus"); String parameterNameForDivide = "amountToDivide"; String parameterNameForMultiply = "amountToMultiply"; theTest.setExpressionParameters(new Vector()); theTest.getExpressionParameters().add(parameterNameForDivide); theTest.getExpressionParameters().add(parameterNameForMultiply); ExpressionBuilder builder = new ExpressionBuilder(); Expression whereClause = ExpressionMath.multiply( ExpressionMath.divide( ExpressionMath.subtract(ExpressionMath.add(builder.get("salary"), 10), 20), builder.getParameter(parameterNameForDivide)), builder.getParameter(parameterNameForMultiply)) .greaterThanEqual(70000); theTest.setOriginalObjectExpression(whereClause); String ejbqlString = "SELECT OBJECT(emp) FROM Employee emp WHERE (emp.salary + 10 - 20) / ?1 * ?2 >= 70000"; theTest.setEjbqlString(ejbqlString); Vector myArgumentNames = new Vector(); myArgumentNames.add("1"); myArgumentNames.add("2"); theTest.setArgumentNames(myArgumentNames); theTest.setArguments(new Vector()); theTest.getArguments().addElement(new Integer(2)); theTest.getArguments().addElement(new Integer(3)); return theTest; }
/** * 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); } } } }
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."); } }