use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class SqlAnalyzerTest method test_analyze_IF_keepLine_if_true.
// *detail tests for analyze() are moved to node tests
// ===================================================================================
// IF Comment
// ==========
public void test_analyze_IF_keepLine_if_true() {
// ## Arrange ##
SimpleMapPmb<Object> pmb = preparePmb();
StringBuilder sb = new StringBuilder();
sb.append("select *");
sb.append(ln());
sb.append(ln()).append("/*IF pmb.sea*/");
sb.append(ln()).append("mystic");
sb.append(ln()).append("/*END*/");
sb.append(ln()).append("/*IF pmb.land*/oneman/*END*/");
sb.append(ln()).append("/*$pmb.iks*/");
String twoway = sb.toString();
SqlAnalyzer analyzer = new SqlAnalyzer(twoway, false);
// ## Act ##
Node node = analyzer.analyze();
// ## Assert ##
CommandContext ctx = prepareCtx(pmb, node);
String sql = ctx.getSql();
log(ln() + sql);
assertEquals("select *\n\n\nmystic\n\n\namba", sql);
assertEquals(0, ctx.getBindVariables().length);
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_that_has_nested_IFIF_all_false.
public void test_parse_BEGIN_that_has_nested_IFIF_all_false() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " ";
sql = sql + "/*IF pmb.memberId != null*/";
sql = sql + "AAA /*IF false*/and BBB /*IF false*/and CCC/*END*//*END*/ /*IF false*/and DDD/*END*/";
sql = sql + "/*END*/";
sql = sql + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
// ## Act ##
Node rootNode = analyzer.analyze();
// ## Assert ##
MockMemberPmb pmb = new MockMemberPmb();
CommandContext ctx = createCtx(pmb);
rootNode.accept(ctx);
log("ctx:" + ctx);
assertEquals("", ctx.getSql());
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_that_has_nested_BEGIN_false.
public void test_parse_BEGIN_that_has_nested_BEGIN_false() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " ";
sql = sql + "/*IF pmb.memberName != null*/";
sql = sql + "FIXED";
sql = sql + "/*END*/";
sql = sql + " ";
sql = sql + "/*BEGIN*/";
sql = sql + "FIXED2 /*IF false*/and BBB/*END*/ /*IF false*/and CCC/*END*/";
sql = sql + "/*END*/";
sql = sql + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
// ## Act ##
Node rootNode = analyzer.analyze();
// ## Assert ##
MockMemberPmb pmb = new MockMemberPmb();
pmb.setMemberName("foo");
CommandContext ctx = createCtx(pmb);
rootNode.accept(ctx);
log("ctx:" + ctx);
// Basically Unsupported!
assertEquals("where FIXED ", ctx.getSql());
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_for_where_either_true.
public void test_parse_BEGIN_for_where_either_true() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " /*IF pmb.memberId != null*/member.MEMBER_ID = 3/*END*/";
sql = sql + " /*IF pmb.memberName != null*/and member.MEMBER_NAME = 'TEST'/*END*/";
sql = sql + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
// ## Act ##
Node rootNode = analyzer.analyze();
// ## Assert ##
MockMemberPmb pmb = new MockMemberPmb();
pmb.setMemberName("pmb");
CommandContext ctx = createCtx(pmb);
rootNode.accept(ctx);
log("ctx:" + ctx);
String expected = "where member.MEMBER_NAME = 'TEST'";
assertEquals(expected, ctx.getSql());
}
use of org.dbflute.twowaysql.context.CommandContext in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_that_has_nested_BEGIN_toponly_false_either_true.
public void test_parse_BEGIN_that_has_nested_BEGIN_toponly_false_either_true() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " ";
sql = sql + "/*IF pmb.memberName != null*/";
sql = sql + "FIXED";
sql = sql + "/*END*/";
sql = sql + " ";
sql = sql + "/*BEGIN*/";
sql = sql + "FIXED2 /*IF false*/and BBB/*END*/ /*IF true*/and CCC/*END*/";
sql = sql + "/*END*/";
sql = sql + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
// ## Act ##
Node rootNode = analyzer.analyze();
// ## Assert ##
MockMemberPmb pmb = new MockMemberPmb();
CommandContext ctx = createCtx(pmb);
rootNode.accept(ctx);
log("ctx:" + ctx);
assertEquals("where FIXED2 CCC", ctx.getSql());
}
Aggregations