Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
* Foundation.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* or from the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* Copyright (c) 2006 - 2015 Pentaho Corporation.. All rights reserved.
*/
package org.pentaho.reporting.engine.classic.core.bugs;
import javax.swing.table.DefaultTableModel;
import org.junit.Before;
import org.junit.Test;
import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
import org.pentaho.reporting.engine.classic.core.MasterReport;
import org.pentaho.reporting.engine.classic.core.TableDataFactory;
import org.pentaho.reporting.engine.classic.core.function.AbstractExpression;
import org.pentaho.reporting.engine.classic.core.function.EventMonitorFunction;
import org.pentaho.reporting.engine.classic.core.function.Expression;
import org.pentaho.reporting.engine.classic.core.function.ItemCountFunction;
import org.pentaho.reporting.engine.classic.core.testsupport.DebugReportRunner;
import org.pentaho.reporting.libraries.base.util.DebugLog;
public class ExpressionOrderTest {
@Before
public void setUp() throws Exception {
ClassicEngineBoot.getInstance().start();
}
@Test
public void testExpressionOrder() throws Exception {
MasterReport r = new MasterReport();
r.setDataFactory( new TableDataFactory( "query", new DefaultTableModel( 4, 1 ) ) );
r.setQuery( "query" );
r.addExpression( new EventMonitorFunction( ) );
r.addExpression( new ItemCountFunction( "rc" ) {
public Object getValue() {
Object value = super.getValue();
DebugLog.log( "ItemCount: " + value );
return value;
}
} );
r.addExpression( createRef( "e2", "e1" ) );
r.addExpression( createRef( "e1", "rc" ) );
DebugReportRunner.createCSV( r );
}
private Expression createRef(final String name, final String field) {
Expression e = new AbstractExpression() {
public Object getValue() {
Object value = getDataRow().get( field );
DebugLog.log( getName() + ": Lookup " + field + "; returning => " + value);
return value;
}
};
e.setName( name );
return e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.