/*
***************************************************************************************
* Copyright (C) 2006 EsperTech, Inc. All rights reserved. *
* http://www.espertech.com/esper *
* http://www.espertech.com *
* ---------------------------------------------------------------------------------- *
* The software in this package is published under the terms of the GPL license *
* a copy of which has been included with this distribution in the license.txt file. *
***************************************************************************************
*/
package com.espertech.esper.regression.resultset;
import com.espertech.esper.client.*;
import com.espertech.esper.client.scopetest.EPAssertionUtil;
import com.espertech.esper.client.scopetest.SupportUpdateListener;
import com.espertech.esper.client.soda.EPStatementObjectModel;
import com.espertech.esper.metrics.instrumentation.InstrumentationHelper;
import com.espertech.esper.supportregression.bean.SupportBean;
import com.espertech.esper.supportregression.client.SupportConfigFactory;
import com.espertech.esper.supportregression.util.SupportMessageAssertUtil;
import junit.framework.TestCase;
public class TestAggregateExtLeaving extends TestCase {
private EPServiceProvider epService;
private SupportUpdateListener listener;
public void setUp()
{
listener = new SupportUpdateListener();
Configuration config = SupportConfigFactory.getConfiguration();
config.addEventType("SupportBean", SupportBean.class);
epService = EPServiceProviderManager.getDefaultProvider(config);
epService.initialize();
if (InstrumentationHelper.ENABLED) { InstrumentationHelper.startTest(epService, this.getClass(), getName());}
}
protected void tearDown() throws Exception {
if (InstrumentationHelper.ENABLED) { InstrumentationHelper.endTest();}
listener = null;
}
public void testLeaving()
{
String epl = "select leaving() as val from SupportBean#length(3)";
EPStatement stmt = epService.getEPAdministrator().createEPL(epl);
stmt.addListener(listener);
runAssertion();
stmt.destroy();
EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(epl);
stmt = epService.getEPAdministrator().create(model);
stmt.addListener(listener);
assertEquals(epl, model.toEPL());
runAssertion();
tryInvalid("select leaving(1) from SupportBean",
"Error starting statement: Failed to validate select-clause expression 'leaving(1)': The 'leaving' function expects no parameters");
}
private void runAssertion() {
String[] fields = "val".split(",");
epService.getEPRuntime().sendEvent(new SupportBean("E1", 1));
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{false});
epService.getEPRuntime().sendEvent(new SupportBean("E2", 2));
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{false});
epService.getEPRuntime().sendEvent(new SupportBean("E3", 3));
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{false});
epService.getEPRuntime().sendEvent(new SupportBean("E4", 4));
EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{true});
}
private void tryInvalid(String epl, String message) {
try
{
epService.getEPAdministrator().createEPL(epl);
fail();
}
catch (EPStatementException ex) {
SupportMessageAssertUtil.assertMessage(ex, ex.getMessage());
}
}
}