TimestampedEvent extends SimpleEvent { long getTimestamp() { return timestamp; } TimestampedEvent(Event base);   }
@Test public void shouldEnsureTimestampHeaderPresentInTimestampedEvent() { SimpleEvent base = new SimpleEvent(); TimestampedEvent timestampedEvent = new TimestampedEvent(base); assertEquals(FIXED_TIME_MILLIS, timestampedEvent.getTimestamp()); assertEquals(String.valueOf(FIXED_TIME_MILLIS), timestampedEvent.getHeaders().get("timestamp")); }
@Test public void shouldUseExistingTimestampHeaderInTimestampedEvent() { SimpleEvent base = new SimpleEvent(); Map<String, String> headersWithTimestamp = Maps.newHashMap(); headersWithTimestamp.put("timestamp", "-321"); base.setHeaders(headersWithTimestamp ); TimestampedEvent timestampedEvent = new TimestampedEvent(base); assertEquals(-321L, timestampedEvent.getTimestamp()); assertEquals("-321", timestampedEvent.getHeaders().get("timestamp")); }
@Test public void shouldUseExistingAtTimestampHeaderInTimestampedEvent() { SimpleEvent base = new SimpleEvent(); Map<String, String> headersWithTimestamp = Maps.newHashMap(); headersWithTimestamp.put("@timestamp", "-999"); base.setHeaders(headersWithTimestamp ); TimestampedEvent timestampedEvent = new TimestampedEvent(base); assertEquals(-999L, timestampedEvent.getTimestamp()); assertEquals("-999", timestampedEvent.getHeaders().get("@timestamp")); assertNull(timestampedEvent.getHeaders().get("timestamp")); }