@Override public Long withHandle(final Handle handle) throws Exception { return (Long) handle.select("select count(distinct record_id) count from bus_events").get(0).get("count") + (Long) handle.select("select count(distinct record_id) count from notifications where effective_date < ?", clock.getUTCNow().toDate()).get(0).get("count") + (Long) handle.select("select count(distinct record_id) count from notifications where processing_state = 'IN_PROCESSING'").get(0).get("count"); } }
@Override public Void withHandle(final Handle handle) throws Exception { final List<Map<String, Object>> values = handle.select("select account_record_id from tags where object_id = ?", accountId.toString()); Assert.assertEquals(values.size(), 1); Assert.assertEquals(values.get(0).keySet().size(), 1); Assert.assertEquals(Long.valueOf(values.get(0).get("account_record_id").toString()), accountRecordId); return null; } });
@Override public Void withHandle(final Handle handle) throws Exception { final List<Map<String, Object>> values = handle.select("select account_record_id from custom_fields where object_id = ?", accountId.toString()); Assert.assertEquals(values.size(), 1); Assert.assertEquals(values.get(0).keySet().size(), 1); Assert.assertEquals(Long.valueOf(values.get(0).get("account_record_id").toString()), accountRecordId); return null; } });
@Test(groups = "slow") public void testRetrieveAuditsDirectly() throws Exception { addTag(); // Verify we get an audit entry for the tag_history table final Handle handle = dbi.open(); final String tagHistoryString = (String) handle.select("select id from tag_history limit 1").get(0).get("id"); handle.close(); for (final AuditLevel level : AuditLevel.values()) { final List<AuditLog> auditLogs = auditDao.getAuditLogsForId(TableName.TAG_HISTORY, UUID.fromString(tagHistoryString), level, internalCallContext); verifyAuditLogsForTag(auditLogs, level); } }
@Override public Long withHandle(final Handle handle) throws Exception { return (Long) handle.select("select count(distinct record_id) count from bus_events").get(0).get("count") + (Long) handle.select("select count(distinct record_id) count from notifications where effective_date < ?", clock.getUTCNow().toDate()).get(0).get("count") + (Long) handle.select("select count(distinct record_id) count from notifications where processing_state = 'IN_PROCESSING'").get(0).get("count"); } }
@Override public Integer withHandle(final Handle handle) throws Exception { List<Map<String, Object>> res = handle.select("select target_record_id from audit_log where id = '" + auditLogId.toString() + "';"); return Integer.valueOf(res.get(0).get("target_record_id").toString()); } });
@Override public Void inTransaction(final Handle conn, final TransactionStatus status) throws Exception { Assert.assertEquals(conn.select("select now();").size(), 1); final BusEvent event = new LoadBusEvent(); eventBus.postFromTransaction(event, conn.getConnection()); return null; } });
@Test public void testInsertWithDefaultParams(){ somethingDao.insertWithDefaultParams("Greg",21); List<Map<String, Object>> rows = handle.select("select * from something where something_id=?", 19); assertEquals(rows.size(), 1); Map<String, Object> row = rows.get(0); assertEquals(row.get("something_id"), 19); assertEquals(row.get("name"), "Greg"); assertEquals(row.get("code"), 21); }
@Test public void testInsertWithDefaultParams(){ somethingDao.insertWithDefaultParams("Greg",21); List<Map<String, Object>> rows = handle.select("select * from something where something_id=?", 19); assertEquals(rows.size(), 1); Map<String, Object> row = rows.get(0); assertEquals(row.get("something_id"), 19); assertEquals(row.get("name"), "Greg"); assertEquals(row.get("code"), 21); }
@Test(groups = "slow") public void testRetrieveAuditsDirectly() throws Exception { addTag(); // Verify we get an audit entry for the tag_history table final Handle handle = dbi.open(); final String tagHistoryString = (String) handle.select("select id from tag_history limit 1").get(0).get("id"); handle.close(); for (final AuditLevel level : AuditLevel.values()) { final List<AuditLog> auditLogs = auditDao.getAuditLogsForId(TableName.TAG_HISTORY, UUID.fromString(tagHistoryString), level, internalCallContext); verifyAuditLogsForTag(auditLogs, level); } }
@Test public void testNamedPositionalNamedParamsInPrepared() throws Exception { Handle h = openHandle(); h.insert("insert-id-name", 3, "Tip"); assertEquals(1, h.select("select name from something").size()); }
@Test public void testLocateNamedWithSuffix() throws Exception { Handle h = openHandle(); h.insert("insert-keith.sql"); assertEquals(1, h.select("select name from something").size()); }
@Test public void testNamedPositionalNamedParamsInPrepared() throws Exception { Handle h = openHandle(); h.insert("insert-id-name", 3, "Tip"); assertEquals(1, h.select("select name from something").size()); }
@Test public void testCommentsInExternalSql() throws Exception { Handle h = openHandle(); h.insert("insert-eric-with-comments"); assertEquals(1, h.select("select name from something").size()); }
@Test public void testLocateNamedWithSuffix() throws Exception { Handle h = openHandle(); h.insert("insert-keith.sql"); assertEquals(1, h.select("select name from something").size()); }
@Test public void testScriptStuff() throws Exception { Handle h = openHandle(); Script s = h.createScript("default-data"); s.execute(); assertEquals(2, h.select("select * from something").size()); }
@Test public void testScriptStuff() throws Exception { Handle h = openHandle(); Script s = h.createScript("default-data"); s.execute(); assertEquals(2, h.select("select * from something").size()); }
@Test public void testLocateNamedWithoutSuffix() throws Exception { Handle h = openHandle(); h.createStatement("insert-keith").execute(); assertEquals(1, h.select("select name from something").size()); }
@Test public void testLocateNamedWithoutSuffix() throws Exception { Handle h = openHandle(); h.createStatement("insert-keith").execute(); assertEquals(1, h.select("select name from something").size()); }
@Test public void testNamedParamsInExternal() throws Exception { Handle h = openHandle(); h.createStatement("insert-id-name").bind("id", 1).bind("name", "Tip").execute(); assertEquals(1, h.select("select name from something").size()); }