/* * ************************************************************************************* * 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.datetime; 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.time.CurrentTimeEvent; import com.espertech.esper.client.util.DateTime; import com.espertech.esper.support.bean.SupportDateTime; import com.espertech.esper.support.bean.lambda.LambdaAssertionUtil; import com.espertech.esper.support.client.SupportConfigFactory; import junit.framework.TestCase; public class TestDTFormat extends TestCase { private EPServiceProvider epService; private SupportUpdateListener listener; public void setUp() { Configuration config = SupportConfigFactory.getConfiguration(); config.addEventType("SupportDateTime", SupportDateTime.class); epService = EPServiceProviderManager.getDefaultProvider(config); epService.initialize(); listener = new SupportUpdateListener(); } public void tearDown() { listener = null; } public void testFormat() { String startTime = "2002-05-30T9:00:00.000"; epService.getEPRuntime().sendEvent(new CurrentTimeEvent(DateTime.parseDefaultMSec(startTime))); String[] fields = "val0,val1,val2,val3".split(","); String eplFragment = "select " + "current_timestamp.format() as val0," + "utildate.format() as val1," + "msecdate.format() as val2," + "caldate.format() as val3" + " from SupportDateTime"; EPStatement stmtFragment = epService.getEPAdministrator().createEPL(eplFragment); stmtFragment.addListener(listener); LambdaAssertionUtil.assertTypes(stmtFragment.getEventType(), fields, new Class[]{String.class, String.class, String.class, String.class}); epService.getEPRuntime().sendEvent(SupportDateTime.make(startTime)); Object[] expected = SupportDateTime.getArrayCoerced(startTime, "sdf", "sdf", "sdf", "sdf"); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, expected); epService.getEPRuntime().sendEvent(SupportDateTime.make(null)); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[]{SupportDateTime.getValueCoerced(startTime, "sdf"), null, null, null}); } }