use of net.sf.jsqlparser.statement.select.OrderByElement in project JSqlParser by JSQLParser.
the class ExpressionDeParserTest method shouldDeParseAnalyticExpressionWithOrderByElements.
@Test
public void shouldDeParseAnalyticExpressionWithOrderByElements() {
AnalyticExpression analyticExpression = new AnalyticExpression();
List<OrderByElement> orderByElements = new ArrayList<OrderByElement>();
OrderByElement orderByElement1 = mock(OrderByElement.class);
OrderByElement orderByElement2 = mock(OrderByElement.class);
analyticExpression.setName("name");
analyticExpression.setOrderByElements(orderByElements);
orderByElements.add(orderByElement1);
orderByElements.add(orderByElement2);
will(appendToBuffer("order by element 1")).given(orderByDeParser).deParseElement(orderByElement1);
will(appendToBuffer("order by element 2")).given(orderByDeParser).deParseElement(orderByElement2);
expressionDeParser.visit(analyticExpression);
assertEquals("name() OVER (ORDER BY order by element 1, order by element 2)", buffer.toString());
}
use of net.sf.jsqlparser.statement.select.OrderByElement in project JSqlParser by JSQLParser.
the class ExpressionDeParserTest method shouldDeParseAnalyticExpressionWithWindowElement.
@Test
public void shouldDeParseAnalyticExpressionWithWindowElement() {
AnalyticExpression analyticExpression = new AnalyticExpression();
List<OrderByElement> orderByElements = new ArrayList<OrderByElement>();
OrderByElement orderByElement1 = mock(OrderByElement.class);
OrderByElement orderByElement2 = mock(OrderByElement.class);
WindowElement windowElement = mock(WindowElement.class);
analyticExpression.setName("name");
analyticExpression.setOrderByElements(orderByElements);
analyticExpression.setWindowElement(windowElement);
orderByElements.add(orderByElement1);
orderByElements.add(orderByElement2);
will(appendToBuffer("order by element 1")).given(orderByDeParser).deParseElement(orderByElement1);
will(appendToBuffer("order by element 2")).given(orderByDeParser).deParseElement(orderByElement2);
given(windowElement.toString()).willReturn("window element");
expressionDeParser.visit(analyticExpression);
assertEquals("name() OVER (ORDER BY order by element 1, order by element 2 window element)", buffer.toString());
}
use of net.sf.jsqlparser.statement.select.OrderByElement in project JSqlParser by JSQLParser.
the class StatementDeParserTest method shouldUseProvidedDeparsersWhenDeParsingDelete.
@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeparsersWhenDeParsingDelete() {
Delete delete = new Delete();
Table table = new Table();
Expression where = mock(Expression.class);
List<OrderByElement> orderByElements = new ArrayList<OrderByElement>();
OrderByElement orderByElement1 = new OrderByElement();
OrderByElement orderByElement2 = new OrderByElement();
Expression orderByElement1Expression = mock(Expression.class);
Expression orderByElement2Expression = mock(Expression.class);
delete.setTable(table);
delete.setWhere(where);
delete.setOrderByElements(orderByElements);
orderByElements.add(orderByElement1);
orderByElements.add(orderByElement2);
orderByElement1.setExpression(orderByElement1Expression);
orderByElement2.setExpression(orderByElement2Expression);
statementDeParser.visit(delete);
then(where).should().accept(expressionDeParser);
then(orderByElement1Expression).should().accept(expressionDeParser);
then(orderByElement2Expression).should().accept(expressionDeParser);
}
use of net.sf.jsqlparser.statement.select.OrderByElement in project JSqlParser by JSQLParser.
the class SelectASTTest method testSelectASTColumnLF.
@Test
public void testSelectASTColumnLF() throws JSQLParserException {
String sql = "SELECT a, b FROM mytable \n order by b, c";
StringBuilder b = new StringBuilder(sql);
Statement stmt = CCJSqlParserUtil.parse(sql);
Select select = (Select) stmt;
PlainSelect ps = (PlainSelect) select.getSelectBody();
for (SelectItem item : ps.getSelectItems()) {
SelectExpressionItem sei = (SelectExpressionItem) item;
Column c = (Column) sei.getExpression();
SimpleNode astNode = c.getASTNode();
assertNotNull(astNode);
b.setCharAt(astNode.jjtGetFirstToken().absoluteBegin - 1, '*');
}
for (OrderByElement item : ps.getOrderByElements()) {
Column c = (Column) item.getExpression();
SimpleNode astNode = c.getASTNode();
assertNotNull(astNode);
b.setCharAt(astNode.jjtGetFirstToken().absoluteBegin - 1, '#');
}
assertEquals("SELECT *, * FROM mytable \n order by #, #", b.toString());
}
use of net.sf.jsqlparser.statement.select.OrderByElement in project JSqlParser by JSQLParser.
the class SelectASTTest method testSelectASTCommentCRLF.
@Test
public void testSelectASTCommentCRLF() throws JSQLParserException {
String sql = "SELECT /* testcomment */ \r\n a, b FROM -- testcomment2 \r\n mytable \r\n order by b, c";
StringBuilder b = new StringBuilder(sql);
Statement stmt = CCJSqlParserUtil.parse(sql);
Select select = (Select) stmt;
PlainSelect ps = (PlainSelect) select.getSelectBody();
for (SelectItem item : ps.getSelectItems()) {
SelectExpressionItem sei = (SelectExpressionItem) item;
Column c = (Column) sei.getExpression();
SimpleNode astNode = c.getASTNode();
assertNotNull(astNode);
b.setCharAt(astNode.jjtGetFirstToken().absoluteBegin - 1, '*');
}
for (OrderByElement item : ps.getOrderByElements()) {
Column c = (Column) item.getExpression();
SimpleNode astNode = c.getASTNode();
assertNotNull(astNode);
b.setCharAt(astNode.jjtGetFirstToken().absoluteBegin - 1, '#');
}
assertEquals("SELECT /* testcomment */ \r\n *, * FROM -- testcomment2 \r\n mytable \r\n order by #, #", b.toString());
}
Aggregations