Search in sources :

Example 1 with TestUtils.createBatchItem

use of org.zalando.nakadi.utils.TestUtils.createBatchItem in project nakadi by zalando.

the class MetadataEnrichmentStrategyTest method setReceivedAtWithSystemTimeInUTC.

@Test
public void setReceivedAtWithSystemTimeInUTC() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONObject event = buildBusinessEvent();
    final BatchItem batch = TestUtils.createBatchItem(event);
    assertThat(event.getJSONObject("metadata").optString("received_at"), isEmptyString());
    try {
        DateTimeUtils.setCurrentMillisFixed(0);
        strategy.enrich(batch, eventType);
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
    assertThat(batch.getEvent().getJSONObject("metadata").getString("received_at"), equalTo("1970-01-01T00:00:00.000Z"));
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) TestUtils.createBatchItem(org.zalando.nakadi.utils.TestUtils.createBatchItem) BatchItem(org.zalando.nakadi.domain.BatchItem) Test(org.junit.Test)

Example 2 with TestUtils.createBatchItem

use of org.zalando.nakadi.utils.TestUtils.createBatchItem in project nakadi by zalando.

the class MetadataEnrichmentStrategyTest method setEventTypeName.

@Test
public void setEventTypeName() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONObject event = buildBusinessEvent();
    final BatchItem batch = TestUtils.createBatchItem(event);
    assertThat(event.getJSONObject("metadata").optString("event_type"), isEmptyString());
    strategy.enrich(batch, eventType);
    assertThat(batch.getEvent().getJSONObject("metadata").getString("event_type"), equalTo(eventType.getName()));
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) TestUtils.createBatchItem(org.zalando.nakadi.utils.TestUtils.createBatchItem) BatchItem(org.zalando.nakadi.domain.BatchItem) Test(org.junit.Test)

Aggregations

JSONObject (org.json.JSONObject)2 Test (org.junit.Test)2 BatchItem (org.zalando.nakadi.domain.BatchItem)2 EventType (org.zalando.nakadi.domain.EventType)2 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)2 TestUtils.createBatchItem (org.zalando.nakadi.utils.TestUtils.createBatchItem)2