/* * ************************************************************************************* * Copyright (C) 2008 EsperTech, Inc. All rights reserved. * * http://esper.codehaus.org * * 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.view; import com.espertech.esper.client.Configuration; import com.espertech.esper.client.EPServiceProvider; import com.espertech.esper.client.EPServiceProviderManager; import com.espertech.esper.client.EPStatement; 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.support.bean.SupportBean; import com.espertech.esper.support.bean.SupportBean_A; import com.espertech.esper.support.client.SupportConfigFactory; import junit.framework.TestCase; public class TestFirstEverLastEverAgg extends TestCase { private EPServiceProvider epService; private SupportUpdateListener listener; public void setUp() { listener = new SupportUpdateListener(); Configuration config = SupportConfigFactory.getConfiguration(); config.addEventType("SupportBean", SupportBean.class); config.addEventType("SupportBean_A", SupportBean_A.class); epService = EPServiceProviderManager.getDefaultProvider(config); epService.initialize(); } protected void tearDown() throws Exception { listener = null; } public void testFirstEverLastEver() { String epl = "select firstever(theString) as firsteverstring, lastever(theString) as lasteverstring, " + "firstever(intPrimitive) as firsteverint, lastever(intPrimitive) as lasteverint from SupportBean.win:length(2)"; 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(); } public void testOnDelete() { epService.getEPAdministrator().createEPL("create window MyWindow.win:keepall() as select * from SupportBean"); epService.getEPAdministrator().createEPL("insert into MyWindow select * from SupportBean"); epService.getEPAdministrator().createEPL("on SupportBean_A delete from MyWindow where theString = id"); String[] fields = "firsteverstring,lasteverstring".split(","); String epl = "select firstever(theString) as firsteverstring, lastever(theString) as lasteverstring from MyWindow"; EPStatement stmt = epService.getEPAdministrator().createEPL(epl); stmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean("E1", 10)); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{"E1", "E1"}); epService.getEPRuntime().sendEvent(new SupportBean("E2", 20)); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{"E1", "E2"}); epService.getEPRuntime().sendEvent(new SupportBean("E3", 30)); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{"E1", "E3"}); epService.getEPRuntime().sendEvent(new SupportBean_A("E2")); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{"E1", "E3"}); epService.getEPRuntime().sendEvent(new SupportBean_A("E3")); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{"E1", "E3"}); epService.getEPRuntime().sendEvent(new SupportBean_A("E1")); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{"E1", "E3"}); } private void runAssertion() { String[] fields = "firsteverstring,firsteverint,lasteverstring,lasteverint".split(","); epService.getEPRuntime().sendEvent(new SupportBean("E1", 10)); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{"E1", 10, "E1", 10}); epService.getEPRuntime().sendEvent(new SupportBean("E2", 11)); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{"E1", 10, "E2", 11}); epService.getEPRuntime().sendEvent(new SupportBean("E3", 12)); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{"E1", 10, "E3", 12}); } }