use of org.dbflute.logic.outsidesqltest.DfOutsideSqlChecker in project dbflute-core by dbflute.
the class OutsideSqlCheckerTest method test_check_parameterBean.
public void test_check_parameterBean() {
// ## Arrange ##
DfOutsideSqlChecker ker = new DfOutsideSqlChecker();
String fn = "test.sql";
// ## Act ##
try {
ker.check(fn, "-- #df:entity#\n-- !df;pmb!\nfoo /*IF pmb.memberId != null*/bar/*END*/");
// ## Assert ##
fail();
} catch (DfParameterBeanMarkInvalidException e) {
// OK
log(e.getMessage());
}
// ## Act ##
try {
ker.check(fn, "-- #df:entity#\n-- !df:entity!\nfoo /*IF pmb.memberId != null*/bar/*END*/");
// ## Assert ##
fail();
} catch (DfParameterBeanMarkInvalidException e) {
// OK
log(e.getMessage());
}
// ## Act ##
try {
ker.check(fn, "-- #df:entity#\n-- !df:pnb!\nfoo /*IF pmb.memberId != null*/bar/*END*/");
// ## Assert ##
fail();
} catch (DfParameterBeanMarkInvalidException e) {
// OK
log(e.getMessage());
}
}
use of org.dbflute.logic.outsidesqltest.DfOutsideSqlChecker in project dbflute-core by dbflute.
the class OutsideSqlCheckerTest method test_check_customizeEntity.
public void test_check_customizeEntity() {
// ## Arrange ##
DfOutsideSqlChecker ker = new DfOutsideSqlChecker();
String fn = "test.sql";
// ## Act ##
try {
ker.check(fn, "-- #df;entity#\n-- !df:pmb!\nfoo /*IF pmb.memberId != null*/bar/*END*/");
// ## Assert ##
fail();
} catch (DfCustomizeEntityMarkInvalidException e) {
// OK
log(e.getMessage());
}
// ## Act ##
try {
ker.check(fn, "-- #df:pmb#\n-- !df:pmb!\nfoo /*IF pmb.memberId != null*/bar/*END*/");
// ## Assert ##
fail();
} catch (DfCustomizeEntityMarkInvalidException e) {
// OK
log(e.getMessage());
}
// ## Act ##
try {
ker.check(fn, "-- #df:emtity#\n-- !df:pmb!\nfoo /*IF pmb.memberId != null*/bar/*END*/");
// ## Assert ##
fail();
} catch (DfCustomizeEntityMarkInvalidException e) {
// OK
log(e.getMessage());
}
}
use of org.dbflute.logic.outsidesqltest.DfOutsideSqlChecker in project dbflute-core by dbflute.
the class OutsideSqlCheckerTest method test_check_basic.
public void test_check_basic() {
// ## Arrange ##
DfOutsideSqlChecker ker = new DfOutsideSqlChecker();
String fn = "test.sql";
// ## Act & Assert ##
ker.check(fn, "-- #df:entity#\n-- !df:pmb!\nfoo /*IF pmb.memberId != null*/bar/*END*/");
ker.check(fn, "-- #df:entity#\n-- !df:pmb!\nfoo /*IF pmb.memberId != null && pmb.existsPurchase*/bar/*END*/");
ker.check(fn, "-- #df:entity#\nfoo /*IF pmb.getMemberId() != null || pmb.isExistsPurchase()*/bar/*END*/");
ker.check(fn, "-- !df:pmb!\nfoo /*IF pmb.memberName == 'abc'*/bar/*END*/");
}
use of org.dbflute.logic.outsidesqltest.DfOutsideSqlChecker in project dbflute-core by dbflute.
the class DfOutsideSqlTestTask method getSqlFileRunner.
protected DfSqlFileRunnerExecute getSqlFileRunner(final DfRunnerInformation runInfo) {
final String nonTargetMark = "df:x";
final DBDef currentDBDef = getDatabaseTypeFacadeProp().getCurrentDBDef();
return new DfSqlFileRunnerExecute(runInfo, getDataSource()) {
protected DfOutsideSqlChecker _outsideSqlChecker;
@Override
protected String filterSql(String sql) {
// /- - - - - - - - - - - - - - - - - - - - - - - - - -
// check parameter comments in the SQL before filtering
// - - - - - - - - - -/
checkParameterComment(_sqlFile, sql);
// filter comments if it needs.
if (!currentDBDef.dbway().isBlockCommentSupported()) {
sql = removeBlockComment(sql);
}
if (!currentDBDef.dbway().isLineCommentSupported()) {
sql = removeLineComment(sql);
}
return super.filterSql(sql);
}
protected String removeBlockComment(final String sql) {
return Srl.removeBlockComment(sql);
}
protected String removeLineComment(final String sql) {
return Srl.removeLineComment(sql);
}
@Override
protected boolean isTargetSql(String sql) {
final String entityName = getEntityName(sql);
if (entityName != null && nonTargetMark.equalsIgnoreCase(entityName)) {
// non-target SQL
_nonTargetSqlFileSet.add(_sqlFile);
_log.info("...Skipping the SQL by non-target mark '" + nonTargetMark + "'");
return false;
}
return super.isTargetSql(sql);
}
@Override
protected void traceSql(String sql) {
_log.info("SQL:" + ln() + sql);
}
@Override
protected void traceResult(int goodSqlCount, int totalSqlCount) {
_log.info(" -> success=" + goodSqlCount + " failure=" + (totalSqlCount - goodSqlCount) + ln());
}
protected String getEntityName(final String sql) {
return getTargetString(sql, "#");
}
protected String getTargetString(final String sql, final String mark) {
final List<String> targetList = getTargetList(sql, mark);
return !targetList.isEmpty() ? targetList.get(0) : null;
}
protected List<String> getTargetList(final String sql, final String mark) {
if (sql == null || sql.trim().length() == 0) {
String msg = "The sql is invalid: " + sql;
throw new IllegalArgumentException(msg);
}
final List<String> betweenBeginEndMarkList = getListBetweenBeginEndMark(sql, "--" + mark, mark);
if (!betweenBeginEndMarkList.isEmpty()) {
return betweenBeginEndMarkList;
} else {
// basically for MySQL
return getListBetweenBeginEndMark(sql, "-- " + mark, mark);
}
}
protected List<String> getListBetweenBeginEndMark(String targetStr, String beginMark, String endMark) {
final List<ScopeInfo> scopeList = Srl.extractScopeList(targetStr, beginMark, endMark);
final List<String> resultList = DfCollectionUtil.newArrayList();
for (ScopeInfo scope : scopeList) {
resultList.add(scope.getContent());
}
return resultList;
}
protected void checkParameterComment(File sqlFile, String sql) {
final DfOutsideSqlProperties outsideSqlProp = getOutsideSqlProperties();
if (outsideSqlProp.isSuppressParameterCommentCheck()) {
return;
}
if (_outsideSqlChecker == null) {
_outsideSqlChecker = createOutsideSqlChecker(outsideSqlProp);
}
_outsideSqlChecker.check(sqlFile.getName(), sql);
}
};
}
use of org.dbflute.logic.outsidesqltest.DfOutsideSqlChecker in project dbflute-core by dbflute.
the class OutsideSqlCheckerTest method test_check_parameterComment.
public void test_check_parameterComment() {
// ## Arrange ##
DfOutsideSqlChecker ker = new DfOutsideSqlChecker();
String fn = "test.sql";
// ## Act ##
try {
ker.check(fn, "-- #df:entity#\n-- !df:pmb!\nfoo /*IF pmb.memberId != null*/bar");
// ## Assert ##
fail();
} catch (EndCommentNotFoundException e) {
// OK
log(e.getMessage());
}
// ## Act ##
try {
ker.check(fn, "-- #df:entity#\n-- !df:pmb!\nfoo /*IF */bar/*END*/");
// ## Assert ##
fail();
} catch (IfCommentConditionEmptyException e) {
// OK
log(e.getMessage());
}
}
Aggregations