use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class BeginNodeTest method test_parse_BEGIN_IF_notFoundProperty_basic.
// ===================================================================================
// NotFound Property
// =================
public void test_parse_BEGIN_IF_notFoundProperty_basic() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " /*IF pmb.wrongMemberId != null*/member.MEMBER_ID = 3/*END*/";
sql = sql + " /*IF pmb.memberName != null*/and member.MEMBER_NAME = 'foo'/*END*/";
sql = sql + "/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
// ## Act ##
try {
MockMemberPmb pmb = new MockMemberPmb();
pmb.setMemberName("foo");
Node rootNode = analyzer.analyze();
CommandContext ctx = createCtx(pmb);
rootNode.accept(ctx);
// ## Assert ##
fail();
} catch (IfCommentNotFoundPropertyException e) {
// OK
log(e.getMessage());
}
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class IfNodeTest method test_parse_IF_false.
public void test_parse_IF_false() {
// ## Arrange ##
String sql = "/*IF pmb.memberName != null*/and member.MEMBER_NAME = 'TEST'/*END*/";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
// ## Act ##
Node rootNode = analyzer.analyze();
// ## Assert ##
MockMemberPmb pmb = new MockMemberPmb();
pmb.setMemberName(null);
CommandContext ctx = createCtx(pmb);
rootNode.accept(ctx);
log("ctx:" + ctx);
assertEquals("", ctx.getSql().trim());
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class IfNodeTest method test_parse_IF_Else_elseValid_in_BEGIN.
public void test_parse_IF_Else_elseValid_in_BEGIN() {
// ## Arrange ##
String sql = "/*BEGIN*/where";
sql = sql + " /*IF pmb.memberId != null*/";
sql = sql + " select foo";
sql = sql + " -- ELSE select count(*)";
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);
String expected = "where select count(*) ";
assertEquals(expected, ctx.getSql());
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class IfNodeTest method test_parse_IF_endNotFound.
public void test_parse_IF_endNotFound() {
// ## Arrange ##
String sql = "where";
sql = sql + " /*IF pmb.memberId != null*/";
sql = sql + " select foo";
SqlAnalyzer analyzer = new SqlAnalyzer(sql, false);
// ## Act ##
try {
analyzer.analyze();
// ## Assert ##
fail();
} catch (EndCommentNotFoundException e) {
// OK
log(e.getMessage());
}
}
use of org.dbflute.twowaysql.SqlAnalyzer in project dbflute-core by dbflute.
the class IfNodeTest method test_parse_IF_for_where_one_true.
public void test_parse_IF_for_where_one_true() {
// ## Arrange ##
String sql = "where";
sql = sql + " /*IF pmb.memberId != null*/member.MEMBER_ID = 3/*END*/";
sql = sql + " /*IF pmb.memberName != null*/and member.MEMBER_NAME = 'TEST'/*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);
String expected = "where and member.MEMBER_NAME = 'TEST'";
assertEquals(expected, ctx.getSql());
}
Aggregations