@Test
public void marketingScenarioDsl() {

    Trigger trigger = new Trigger(TEST_TENANT, "marketing-scenario","Marketing Scenario");
    String expression = "event:groupBy(context.accountId):window(time,10s):having(count > 2)";
    ExternalCondition condition = new ExternalCondition(trigger.getId(), FIRING, DATA_ID, ALERTER_ID, expression);
    Expression exp = new Expression(Arrays.asList(new FullTrigger(trigger, null, Arrays.asList(condition))));
    String drl = exp.getDrl();
    // System.out.println(drl);
    startSession(drl);
    // Init t0
    clock.setStartupTime(1);
    long now = clock.getCurrentTime();
    // User1 buys 5 times in < 10 seconds
    Event e1 = new Event(TEST_TENANT, uuid(), now, DATA_ID, "TraceCompletion", "E1 - Buy Book");
    e1.addContext("duration", "1000");
    e1.addContext("accountId", "user1");
    // User2 buys 3 times > 10 seconds
    Event e6 = new Event(TEST_TENANT, uuid(), now, DATA_ID, "TraceCompletion", "E6 - Buy Book");
    e6.addContext("duration", "1000");
    e6.addContext("accountId", "user2");
    insert(e1, e6);
    // t0 + 1000
    now = clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    Event e2 = new Event(TEST_TENANT, uuid(), now, DATA_ID, "TraceCompletion", "E2 - Buy Music");
    e2.addContext("duration", "2000");
    e2.addContext("accountId", "user1");
    insert(e2);
    // t0 + 2000
    now = clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    Event e3 = new Event(TEST_TENANT, uuid(), now, DATA_ID, "TraceCompletion", "E3 - Buy Groceries");
    e3.addContext("duration", "1500");
    e3.addContext("accountId", "user1");
    insert(e3);
    // t0 + 3000
    now = clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    Event e4 = new Event(TEST_TENANT, uuid(), now, DATA_ID, "TraceCompletion", "E4 - Buy VideoGames");
    e4.addContext("duration", "3000");
    e4.addContext("accountId", "user1");
    insert(e4);
    // t0 + 4000
    now = clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    Event e5 = new Event(TEST_TENANT, uuid(), now, DATA_ID, "TraceCompletion", "E5 - Buy VideoGames");
    e5.addContext("duration", "3000");
    e5.addContext("accountId", "user1");
    insert(e5);
    // t0 + 5000
    now = clock.advanceTime(1000, TimeUnit.MILLISECONDS);
    Event e7 = new Event(TEST_TENANT, uuid(), now, DATA_ID, "TraceCompletion", "E7 - Buy Music");
    e7.addContext("duration", "2000");
    e7.addContext("accountId", "user2");
    insert(e7);
    // t0 + 11000
    now = clock.advanceTime(6000, TimeUnit.MILLISECONDS);
    Event e8 = new Event(TEST_TENANT, uuid(), now, DATA_ID, "TraceCompletion", "E8 - Buy Groceries");
    e8.addContext("duration", "1500");
    e8.addContext("accountId", "user2");
    insert(e8);
    stopSession();
    Assert.assertEquals(4, results.size());
    results.stream().forEach(e -> {
        Assert.assertEquals("user1", e.getContext().get("accountId"));
        /*
            System.out.println("Event: ");
            System.out.println(e);
            System.out.println("Source events:");
            extractEvents(e).stream().forEach(extracted -> {
                System.out.println(extracted);
            });
            System.out.println("\n");
        */
    });
}