private void RunAssertionRenderSimple(EPServiceProvider epService) { var bean = new SupportBean(); bean.TheString = "a\nc>"; bean.IntPrimitive = 1; bean.IntBoxed = 992; bean.CharPrimitive = 'x'; bean.EnumValue = SupportEnum.ENUM_VALUE_1; epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); EPStatement statement = epService.EPAdministrator.CreateEPL("select * from SupportBean"); epService.EPRuntime.SendEvent(bean); string result = epService.EPRuntime.EventRenderer.RenderJSON("supportBean", statement.First()); //Log.Info(result); string valuesOnly = "{ \"BoolBoxed\": null, \"BoolPrimitive\": false, \"ByteBoxed\": null, \"BytePrimitive\": 0, \"CharBoxed\": null, \"CharPrimitive\": \"x\", \"DecimalBoxed\": null, \"DoubleBoxed\": null, \"DoublePrimitive\": 0.0, \"EnumValue\": \"ENUM_VALUE_1\", \"FloatBoxed\": null, \"FloatPrimitive\": 0.0, \"IntBoxed\": 992, \"IntPrimitive\": 1, \"LongBoxed\": null, \"LongPrimitive\": 0, \"ShortBoxed\": null, \"ShortPrimitive\": 0, \"TheString\": \"a\\nc>\", \"This\": { \"BoolBoxed\": null, \"BoolPrimitive\": false, \"ByteBoxed\": null, \"BytePrimitive\": 0, \"CharBoxed\": null, \"CharPrimitive\": \"x\", \"DecimalBoxed\": null, \"DoubleBoxed\": null, \"DoublePrimitive\": 0.0, \"EnumValue\": \"ENUM_VALUE_1\", \"FloatBoxed\": null, \"FloatPrimitive\": 0.0, \"IntBoxed\": 992, \"IntPrimitive\": 1, \"LongBoxed\": null, \"LongPrimitive\": 0, \"ShortBoxed\": null, \"ShortPrimitive\": 0, \"TheString\": \"a\\nc>\" } }"; string expected = "{ \"supportBean\": " + valuesOnly + " }"; Assert.AreEqual(RemoveNewline(expected), RemoveNewline(result)); JSONEventRenderer renderer = epService.EPRuntime.EventRenderer.GetJSONRenderer(statement.EventType); string jsonEvent = renderer.Render("supportBean", statement.First()); Assert.AreEqual(RemoveNewline(expected), RemoveNewline(jsonEvent)); jsonEvent = renderer.Render(statement.First()); Assert.AreEqual(RemoveNewline(valuesOnly), RemoveNewline(jsonEvent)); statement.Dispose(); }
public void Run(RegressionEnvironment env) { string epl = "@public @buseventtype create json schema MyJsonEvent(p0 string, p1 int);\n" + "@Name('s0') select * from MyJsonEvent#keepall;\n"; env.CompileDeploy(epl).AddListener("s0"); var jobject = new JObject( new JProperty("p0", "abc"), new JProperty("p1", 10)); env.SendEventJson(jobject.ToString(), "MyJsonEvent"); string expected = "{\"p0\":\"abc\",\"p1\":10}"; string expectedWithTitle = "{\"thetitle\":{\"p0\":\"abc\",\"p1\":10}}"; EventBean @event = env.Statement("s0").First(); string result = env.Runtime.RenderEventService.RenderJSON("thetitle", @event); Assert.AreEqual(expectedWithTitle, result); result = env.Runtime.RenderEventService.RenderJSON("thetitle", @event); Assert.AreEqual(expectedWithTitle, result); JSONEventRenderer renderer = env.Runtime.RenderEventService.GetJSONRenderer(env.Statement("s0").EventType); result = renderer.Render("thetitle", @event); Assert.AreEqual(expectedWithTitle, result); result = renderer.Render(@event); Assert.AreEqual(expected, result); env.UndeployAll(); }
private void RunAssertion( EPServiceProvider epService, string typename, FunctionSendEvent send, Object @event) { string epl = "select * from " + typename; EPStatement statement = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); statement.Events += listener.Update; send.Invoke(epService, @event); EventBean eventBean = listener.AssertOneGetNewAndReset(); JSONEventRenderer jsonEventRenderer = epService.EPRuntime.EventRenderer.GetJSONRenderer(statement.EventType); string json = jsonEventRenderer.Render(eventBean).RegexReplaceAll("(\\s|\\n|\\t)", ""); Assert.AreEqual("{\"MyInt\":1,\"MyString\":\"abc\",\"Nested\":{\"MyInsideInt\":10}}", json); XMLEventRenderer xmlEventRenderer = epService.EPRuntime.EventRenderer.GetXMLRenderer(statement.EventType); string xml = xmlEventRenderer.Render("root", eventBean).RegexReplaceAll("(\\s|\\n|\\t)", ""); Assert.AreEqual("<?xmlversion=\"1.0\"encoding=\"UTF-8\"?><root><MyInt>1</MyInt><MyString>abc</MyString><Nested><MyInsideInt>10</MyInsideInt></Nested></root>", xml); statement.Dispose(); }
public void Render(EventBean theEvent, StringWriter writer) { string result; if (format == LogSinkOutputFormat.json) { JSONEventRenderer renderer = jsonRendererCache.Get(theEvent.EventType); if (renderer == null) { renderer = GetJsonRenderer(theEvent.EventType); jsonRendererCache.Put(theEvent.EventType, renderer); } result = renderer.Render(theEvent.EventType.Name, theEvent); } else { XMLEventRenderer renderer = xmlRendererCache.Get(theEvent.EventType); if (renderer == null) { renderer = GetXmlRenderer(theEvent.EventType); xmlRendererCache.Put(theEvent.EventType, renderer); } result = renderer.Render(theEvent.EventType.Name, theEvent); } writer.Write(result); }
public void Run(RegressionEnvironment env) { string epl = "@public @buseventtype @JsonSchema(ClassName='" + typeof(SupportUsersEvent).FullName + "') create json schema Users();\n" + "@Name('s0') select * from Users;"; env.CompileDeploy(epl).AddListener("s0"); // try sender parse-only EventSenderJson sender = (EventSenderJson)env.Runtime.EventService.GetEventSender("Users"); SupportUsersEvent users = (SupportUsersEvent)sender.Parse(UsersJson); AssertUsersPremade(users); // try send-event sender.SendEvent(UsersJson); EventBean @event = env.Listener("s0").AssertOneGetNewAndReset(); AssertUsersPremade((SupportUsersEvent)@event.Underlying); // try write JSONEventRenderer render = env.Runtime.RenderEventService.GetJSONRenderer(@event.EventType); Assert.AreEqual(UsersJsonReplaceWhitespace, render.Render(@event)); env.UndeployAll(); }
private void PrintRows(EPServiceProvider epService, EventBean[] rows) { JSONEventRenderer renderer = epService.EPRuntime.EventRenderer.GetJSONRenderer(rows[0].EventType); for (int i = 0; i < rows.Length; i++) { // Log.Info(renderer.Render("event#" + i, rows[i])); renderer.Render("event#" + i, rows[i]); } }