assertEquals("Should not be accepting null objects as events.", 0, lc.getClientEvents().size());
Aura.getContextService().endContext();
// Adding multiple contexts
lc = Aura.getContextService().startContext(Mode.UTEST, Format.JSON, Authentication.AUTHENTICATED);
Event evt1 = Aura.getInstanceService().getInstance("markup://aura:applicationEvent", EventDef.class, null);
lc.addClientApplicationEvent(evt1);
Event evt2 = Aura.getInstanceService().getInstance("markup://aura:connectionLost", EventDef.class, null);
lc.addClientApplicationEvent(evt2);
List<Event> evnts = lc.getClientEvents();
assertEquals("Found unexpected number of events on context", 2, evnts.size());
assertEquals("markup://aura:applicationEvent", evnts.get(0).getDescriptor().getQualifiedName());
assertEquals("markup://aura:connectionLost", evnts.get(1).getDescriptor().getQualifiedName());
Aura.getContextService().endContext();
// Adding same event again should not cause an error, same event can be
// fired with different parameters.
lc = Aura.getContextService().startContext(Mode.UTEST, Format.JSON, Authentication.AUTHENTICATED);
Event evt3 = Aura.getInstanceService().getInstance("markup://handleEventTest:applicationEvent", EventDef.class,
null);
lc.addClientApplicationEvent(evt3);
Event evt3_dup = Aura.getInstanceService().getInstance("markup://handleEventTest:applicationEvent",
EventDef.class, null);
lc.addClientApplicationEvent(evt3_dup);
assertEquals("Failed to add same event twice.", 2, evnts.size());
Aura.getContextService().endContext();
// Verify component events are not acceptable
lc = Aura.getContextService().startContext(Mode.UTEST, Format.JSON, Authentication.AUTHENTICATED);
Event evt4 = Aura.getInstanceService().getInstance("markup://handleEventTest:event", EventDef.class, null);
try {
lc.addClientApplicationEvent(evt4);
fail("Component events should not be allowed to be fired from server.");
} catch (Exception e) {
assertEquals("markup://handleEventTest:event is not an Application event. "