package org.apache.flume.interceptor;

import org.apache.flume.serialization.JSONStringSerializer;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class EnrichedEventBodyTest {

    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(EnrichmentInterceptor.class);

    @Test
    public void testCreateFromByteArray() {
        // Build a enriched event payload
        byte[] bytes = "hello".getBytes();
        Map<String, String> data = new HashMap<String, String>();
        data.put("k1", "v1");

        EnrichedEventBody enrichedEventBody = new EnrichedEventBody(data, bytes);

        String json;
        try {
            json = JSONStringSerializer.toJSONString(enrichedEventBody);
            EnrichedEventBody newMessage = EnrichedEventBody.createFromEventBody(json.getBytes(), true);

            Assert.assertEquals(JSONStringSerializer.toJSONString(newMessage), json);
        } catch (IOException e) {
            e.printStackTrace();
            Assert.fail();
        }

    }
}

@@ -452,63 +452,21 @@
 From
-ByteArray() %7B%0A        // Build a enriched event payload
+EventBody() %7B
 %0A   
@@ -1089,16 +1089,894 @@
       %7D%0A
+    %7D%0A%0A    @Test%0A    public void testNullExtraData() %7B%0A        byte%5B%5D message = %22hello%22.getBytes();%0A        String messageAsJsonString = %22%7B%5C%22message%5C%22:%5C%22aGVsbG8=%5C%22%7D%22;%0A%0A        try %7B%0A            // build an event from bytes with no extra_data and get its JSON string%0A            EnrichedEventBody fromBytes = new EnrichedEventBody(message);%0A%0A            // build an event from JSON string with no extra_data%0A            EnrichedEventBody fromJson = JSONStringSerializer.fromJSONString(messageAsJsonString, EnrichedEventBody.class);%0A%0A            logger.info(%22fromBytes.extraData is: %22 + fromBytes.getExtraData());%0A            logger.info(%22fromJSON.extraData is: %22 + fromJson.getExtraData());%0A            Assert.assertEquals(fromBytes.getExtraData(), fromJson.getExtraData());%0A%0A        %7D catch (IOException e) %7B%0A            e.printStackTrace();%0A            Assert.fail();%0A        %7D
 %0A    %7D%0A%7D

Add tests