use of org.dbflute.hook.SqlLogInfo.SqlLogDisplaySqlBuilder in project dbflute-core by dbflute.
the class BehaviorCommandInvokerTest method test_callbackSqlResultHanler_basic.
public void test_callbackSqlResultHanler_basic() {
// ## Arrange ##
BehaviorCommandInvoker invoker = new BehaviorCommandInvoker();
final long before = 123;
final long after = 456;
final Object ret = new Object();
MockBehaviorCommand mockCmd = new MockBehaviorCommand() {
@Override
public String getTableDbName() {
return "FOO";
}
@Override
public String getCommandName() {
return "BAR";
}
};
final HashSet<String> markSet = new HashSet<String>();
try {
SqlLogInfo sqlLogInfo = new SqlLogInfo(mockCmd, "select ...", new Object[] {}, new Class<?>[] {}, new SqlLogDisplaySqlBuilder() {
public String build(String executedSql, Object[] bindArgs, Class<?>[] bindArgTypes) {
return "select ...";
}
});
InternalMapContext.setResultSqlLogInfo(sqlLogInfo);
// ## Act & Assert ##
invoker.callbackSqlResultHanler(mockCmd, new SqlResultHandler() {
public void handle(SqlResultInfo info) {
long actualBefore = info.getExecutionTimeInfo().getCommandBeforeTimeMillis();
long actualAfter = info.getExecutionTimeInfo().getCommandAfterTimeMillis();
assertEquals(ret, info.getResult());
assertEquals("FOO", info.getMeta().getTableDbName());
assertEquals("BAR", info.getMeta().getCommandName());
String displaySql = info.getSqlLogInfo().getDisplaySql();
assertEquals("select ...", displaySql);
assertEquals(before, actualBefore);
assertEquals(after, actualAfter);
assertNull(info.getCause());
markSet.add("handle()");
log(info.getResult() + ":" + displaySql + ":" + actualBefore + ":" + actualAfter);
}
}, ret, before, after, null);
assertTrue(markSet.size() == 1);
assertTrue(markSet.contains("handle()"));
} finally {
InternalMapContext.clearInternalMapContextOnThread();
}
}
use of org.dbflute.hook.SqlLogInfo.SqlLogDisplaySqlBuilder in project dbflute-core by dbflute.
the class BehaviorCommandInvokerTest method test_callbackSqlResultHanler_notExistsDisplaySql.
public void test_callbackSqlResultHanler_notExistsDisplaySql() {
// ## Arrange ##
BehaviorCommandInvoker invoker = new BehaviorCommandInvoker();
final long before = 123;
final long after = 456;
final Object ret = new Object();
MockBehaviorCommand mockCmd = new MockBehaviorCommand() {
@Override
public String getTableDbName() {
return "FOO";
}
@Override
public String getCommandName() {
return "BAR";
}
};
final HashSet<String> markSet = new HashSet<String>();
SqlLogInfo sqlLogInfo = new SqlLogInfo(mockCmd, "select ...", new Object[] {}, new Class<?>[] {}, new SqlLogDisplaySqlBuilder() {
public String build(String executedSql, Object[] bindArgs, Class<?>[] bindArgTypes) {
return "select ...";
}
});
InternalMapContext.setResultSqlLogInfo(sqlLogInfo);
try {
// ## Act & Assert ##
invoker.callbackSqlResultHanler(mockCmd, new SqlResultHandler() {
public void handle(SqlResultInfo info) {
long actualBefore = info.getExecutionTimeInfo().getCommandBeforeTimeMillis();
long actualAfter = info.getExecutionTimeInfo().getCommandAfterTimeMillis();
assertEquals(ret, info.getResult());
assertEquals("FOO", info.getMeta().getTableDbName());
assertEquals("BAR", info.getMeta().getCommandName());
String displaySql = info.getSqlLogInfo().getDisplaySql();
assertEquals("select ...", displaySql);
assertEquals(before, actualBefore);
assertEquals(after, actualAfter);
assertNotNull(info.getCause());
markSet.add("handle()");
log(info.getResult() + ":" + displaySql + ":" + actualBefore + ":" + actualAfter);
}
}, ret, before, after, new IllegalStateException());
assertTrue(markSet.size() == 1);
assertTrue(markSet.contains("handle()"));
} finally {
InternalMapContext.clearInternalMapContextOnThread();
}
}
Aggregations