CallableQuery extends CallableJob implements Callable<Void> { @VisibleForTesting public static String createMessageContent(PersistentResultSet results, JobSpec spec, String replacedReportQuery) { StringBuilder sb = new StringBuilder(); sb.append("<br>"); sb.append(createInlineResults(results, spec)); sb.append("<br>"); sb.append("<pre> Query: " + replacedReportQuery + "</pre>"); sb.append("<br>"); sb.append("Note: For brevity the first " + MAX_RESULTS_IN_BODY + " rows are included in the email body."); return sb.toString(); } CallableQuery();  CallableQuery(PlannedJob plannedJob, JobDao dao,
                       Reporting reporting, String hostname,
                       MailInfo mailInfo, Session session,
                       SupportedDriver driver, String reportRootPath,
                       int attemptNumber); static String[] cleanupQuery(String[] parts); static String getJobReportDir(String rootPath, PlannedJob plannedJob); static String getJobReportPath(String reportJobPath, PlannedJob plannedJob); @VisibleForTesting static void writeReportToLocal(PersistentResultSet result, String rootPath, PlannedJob plannedJob); @VisibleForTesting static String createMessageContent(PersistentResultSet results, JobSpec spec,
                                             String replacedReportQuery); static StringBuilder createInlineResults(PersistentResultSet results, JobSpec spec); static String makeAttachmentText(PersistentResultSet results); String getReplacedQuery(); String getReplacedReportQuery(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static Logger LOG; static final String TSV; static final String TAB; static final String ENTER; static final String NULL; static final String QUERY_SPLITTER; }
@Test public void testCreateMessageContent() { JobSpec aJob = TestAgent.getTestJob("Broken Social Scene", dao); aJob.setResultQuery("select * from blah where dt=${YYYMMDDHH}"); dao.createJob(aJob); PlannedJob pj = new PlannedJob(aJob, Utils.getCurrentTime()); CallableQuery cq = new CallableQuery(pj, dao, null, "example.com", null, null, null, null, 1); PersistentResultSet results = getPRS(); String expected = String.format("<br><table border='1' cellspacing='0' cellpadding='2' align='center' style='width:100%%'>\n" + "<tr>\n" + "<th style='padding: 5px'>%s</th>\n" + "<th style='padding: 5px'>%s</th>\n" + "</tr>\n" + "<tr>\n" + "<td style='padding: 5px'>%s</td>\n" + "<td style='padding: 5px'>%s</td>\n" + "</tr>\n" + "<tr>\n" + "<td style='padding: 5px'>%s</td>\n" + "<td style='padding: 5px'>%s</td>\n" + "</tr>\n" + "</table>\n" + "<br><pre> Query: %s</pre><br>Note: For brevity the first 500 rows are included in the email body.", results.getColumnNames().get(0), results.getColumnNames().get(1), results.getData().get(0).get(0), results.getData().get(0).get(1), results.getData().get(1).get(0), results.getData().get(1).get(1), cq.getReplacedReportQuery()); String actual = CallableQuery.createMessageContent(results, aJob, cq.getReplacedReportQuery()); Assert.assertEquals(expected, actual); }