UUIDInterceptor implements Interceptor { @Override public Event intercept(Event event) { Map<String, String> headers = event.getHeaders(); if (preserveExisting && headers.containsKey(headerName)) { } else if (isMatch(event)) { headers.put(headerName, generateUUID()); } return event; } protected  UUIDInterceptor(Context context); @Override void initialize(); @Override Event intercept(Event event); @Override List<Event> intercept(List<Event> events); @Override void close(); static final String HEADER_NAME; static final String PRESERVE_EXISTING_NAME; static final String PREFIX_NAME; }
@Test public void testBasic() throws Exception { Context context = new Context(); context.put(UUIDInterceptor.HEADER_NAME, ID); context.put(UUIDInterceptor.PRESERVE_EXISTING_NAME, "true"); Event event = new SimpleEvent(); assertTrue(build(context).intercept(event).getHeaders().get(ID).length() > 0); }
@Test public void testPreserveExisting() throws Exception { Context context = new Context(); context.put(UUIDInterceptor.HEADER_NAME, ID); context.put(UUIDInterceptor.PRESERVE_EXISTING_NAME, "true"); Event event = new SimpleEvent(); event.getHeaders().put(ID, "foo"); assertEquals("foo", build(context).intercept(event).getHeaders().get(ID)); }
@Test public void testPrefix() throws Exception { Context context = new Context(); context.put(UUIDInterceptor.HEADER_NAME, ID); context.put(UUIDInterceptor.PREFIX_NAME, "bar#"); Event event = new SimpleEvent(); assertTrue(build(context).intercept(event).getHeaders().get(ID).startsWith("bar#")); }