public void test() { // Make a query an search Number greaterThan "00005" ExpressionBuilder phone = new ExpressionBuilder(); Expression exp = phone.get("areaCode").equal(613); ReadAllQuery query = new ReadAllQuery(PhoneNumber.class); query.setSelectionCriteria(exp); query.conformResultsInUnitOfWork(); // set Conforming query.addOrdering(phone.get("owner").get("id").descending()); query.addOrdering(phone.get("type").descending()); UnitOfWork uow = getSession().acquireUnitOfWork(); Vector v = (Vector) uow.executeQuery(query); Vector v2 = (Vector) uow.executeQuery(query); if (!v.equals(v2)) { throw new TestErrorException("Order not maintained when conforming:" + v + " != " + v2); } }
public void testOrderByExpression() { EntityManager em = createEntityManager(); ReadAllQuery raq = new ReadAllQuery(PhoneNumber.class, new ExpressionBuilder()); Expression whereClause = raq.getExpressionBuilder().get("owner").get("address").get("province").equal("ONT"); raq.setSelectionCriteria(whereClause); raq.addOrdering(raq.getExpressionBuilder().get("areaCode")); raq.addOrdering(raq.getExpressionBuilder().get("type")); List expectedResult = (List) getServerSession().executeQuery(raq); String ejbqlString = "SELECT p FROM Employee e JOIN e.phoneNumbers p JOIN e.address a WHERE a.province = 'ONT' " + "ORDER BY p.areaCode, p.type"; List result = em.createQuery(ejbqlString).getResultList(); Assert.assertEquals("OrderBy expression test failed: data validation error", result.size(), 13); Assert.assertTrue( "OrderBy expression test failed", comparer.compareObjects(expectedResult, result)); }
private void addOuterJoinOrderByTest() { ExpressionBuilder emp = new ExpressionBuilder(); ReadAllExpressionTest test = new ReadAllOuterJoinExpressionTest(Employee.class, 12); test.setName("OuterJoinOrderByTest"); test.setDescription("Test order by with outer joins"); ReadAllQuery query = new ReadAllQuery(Employee.class); query.addOrdering(emp.getAllowingNull("address").get("city")); test.setQuery(query); addTest(test); }
private void addOuterJoinAcrossInheritanceTest() { ExpressionBuilder emp = new ExpressionBuilder(); ReadAllExpressionTest test = new ReadAllOuterJoinExpressionTest( org.eclipse.persistence.testing.models.inheritance.Person.class, 1); test.setName("OuterJoinAcrossInheritanceTest"); test.setDescription("Test joining with outer joins across inheritance"); ReadAllQuery query = new ReadAllQuery(org.eclipse.persistence.testing.models.inheritance.Person.class); // This test used to make no sense... // query.setSelectionCriteria(emp.getAllowingNull("representitive").get("name").equalOuterJoin("Richard")); query.addOrdering(emp.getAllowingNull("representitive").get("name")); test.setQuery(query); addTest(test); }
/** * Load the last test result from the test result database. Find only the results run on the same * machine and database. Compare the current test run result with the previous results do * determine if the test passes or fails. */ public static void verify(PerformanceRegressionTest test) { // Ensures all tests pass to reset baseline, // Required when tests or environment change to be slower to avoid failures. if (reset) { throw new TestWarningException("Reseting baseline."); } Session session = LoadBuildSystem.getSystem().getSession(); // Query all previous successful test results for this test on the same machine and database. // Find only the baseline version, or last version run different than current version. // If you need to compare results against the current version you must change the TopLink // version string. ReadAllQuery query = new ReadAllQuery(TestResult.class); ExpressionBuilder result = new ExpressionBuilder(); query.setSelectionCriteria( result .get("name") .equal(test.getName()) .and( result .get("loadBuildSummary") .get("machine") .equal(LoadBuildSystem.getSummary().getMachine())) .and( result .get("loadBuildSummary") .get("loginChoice") .equal(LoadBuildSystem.getSummary().getLoginChoice()))); // Allow comparing to a set version through a system property. String currentVersion = LoadBuildSystem.getSummary().getToplinkVersion(); String baselineVersion = null; if (System.getProperties().containsKey("toplink.loadbuild.baseline-version")) { baselineVersion = System.getProperties().getProperty("toplink.loadbuild.baseline-version"); // System properties cannot store spaces so need to replace them from \b. baselineVersion = baselineVersion.replace('_', ' '); ((PerformanceComparisonTestResult) ((TestCase) test).getTestResult()).baselineVersion = baselineVersion; } else { // Compare against the last successful version. ReportQuery reportQuery = new ReportQuery(TestResult.class, query.getExpressionBuilder()); reportQuery.useDistinct(); reportQuery.returnSingleValue(); reportQuery.addAttribute("version", result.get("loadBuildSummary").get("toplinkVersion")); reportQuery.setSelectionCriteria( query .getSelectionCriteria() .and( (result.get("outcome").equal(TestResult.PASSED)) .or(result.get("outcome").equal(TestResult.WARNING))) .and(result.get("loadBuildSummary").get("toplinkVersion").notEqual(currentVersion))); reportQuery.addOrdering(result.get("loadBuildSummary").get("timestamp").descending()); baselineVersion = (String) session.executeQuery(reportQuery); } query.setSelectionCriteria( query .getSelectionCriteria() .and(result.get("loadBuildSummary").get("toplinkVersion").equal(baselineVersion))); query.addOrdering(result.get("loadBuildSummary").get("timestamp").descending()); query.setMaxRows(10); query.useCursoredStream(1, 1); CursoredStream stream = (CursoredStream) session.executeQuery(query); if (!stream.hasMoreElements()) { throw new TestWarningException("No previous test result to compare performance with."); } TestResult lastResult = (TestResult) stream.nextElement(); double lastCount = lastResult.getTestTime(); PerformanceComparisonTestResult testResult = (PerformanceComparisonTestResult) ((TestCase) test).getTestResult(); testResult.getBaselineVersionResults().add(new Double(lastCount)); // Average last 5 runs. int numberOfRuns = 0; while (stream.hasMoreElements() && (numberOfRuns < 4)) { TestResult nextResult = (TestResult) stream.nextElement(); testResult.getBaselineVersionResults().add(new Double(nextResult.getTestTime())); numberOfRuns++; } stream.close(); double baselineAverage = PerformanceComparisonTestResult.averageResults(testResult.getBaselineVersionResults()); double currentCount = ((TestCase) test).getTestResult().getTestTime(); testResult.baselineVersion = lastResult.getLoadBuildSummary().getToplinkVersion(); testResult.percentageDifferenceLastRun = PerformanceComparisonTestResult.percentageDifference(currentCount, lastCount); // Query the current version last 5 runs for averaging. query = new ReadAllQuery(TestResult.class); result = new ExpressionBuilder(); query.setSelectionCriteria( result .get("name") .equal(((TestCase) test).getName()) .and( result .get("loadBuildSummary") .get("machine") .equal(LoadBuildSystem.getSummary().getMachine())) .and( result .get("loadBuildSummary") .get("loginChoice") .equal(LoadBuildSystem.getSummary().getLoginChoice())) .and(result.get("loadBuildSummary").get("toplinkVersion").equal(currentVersion))); query.addOrdering(result.get("loadBuildSummary").get("timestamp").descending()); query.useCursoredStream(1, 1); stream = (CursoredStream) session.executeQuery(query); // Average last 5 runs. testResult.getCurrentVersionResults().add(new Double(currentCount)); numberOfRuns = 0; while (stream.hasMoreElements() && (numberOfRuns < 4)) { TestResult nextResult = (TestResult) stream.nextElement(); testResult.getCurrentVersionResults().add(new Double(nextResult.getTestTime())); numberOfRuns++; } stream.close(); double currentAverage = PerformanceComparisonTestResult.averageResults(testResult.getCurrentVersionResults()); testResult.percentageDifferenceAverage = PerformanceComparisonTestResult.percentageDifference(currentAverage, baselineAverage); testResult.baselineStandardDeviation = PerformanceComparisonTestResult.standardDeviationResults( testResult.getBaselineVersionResults()); testResult.currentStandardDeviation = PerformanceComparisonTestResult.standardDeviationResults( testResult.getCurrentVersionResults()); if (testResult.percentageDifferenceAverage < test.getAllowableDecrease()) { throw new TestErrorException( "Test is " + ((long) testResult.percentageDifferenceAverage) + "% slower than last successful execution."); } }