package co.cask.hydrator.plugin;

import co.cask.cdap.api.data.format.StructuredRecord;
import co.cask.cdap.api.data.schema.Schema;
import co.cask.cdap.etl.api.Transform;
import org.junit.Assert;
import org.junit.Test;

/**
 * Tests {@link JSONParser}
 */
public class JSONFormatterTest {
  private static final Schema OUTPUT1 = Schema.recordOf("output1",
                                                       Schema.Field.of("body", Schema.of(Schema.Type.STRING)));

  private static final Schema INPUT1 = Schema.recordOf("input1",
                                                        Schema.Field.of("a", Schema.of(Schema.Type.STRING)),
                                                        Schema.Field.of("b", Schema.of(Schema.Type.STRING)),
                                                        Schema.Field.of("c", Schema.of(Schema.Type.STRING)),
                                                        Schema.Field.of("d", Schema.of(Schema.Type.STRING)),
                                                        Schema.Field.of("e", Schema.of(Schema.Type.STRING)));
  private static final Schema INPUT2 = Schema.recordOf("input2",
                                                        Schema.Field.of("a", Schema.of(Schema.Type.STRING)),
                                                        Schema.Field.of("b", Schema.of(Schema.Type.STRING)),
                                                        Schema.Field.of("e", Schema.of(Schema.Type.STRING)));
  @Test
  public void testJSONFormatter() throws Exception {
    JSONFormatter.Config config = new JSONFormatter.Config(OUTPUT1.toString());
    Transform<StructuredRecord, StructuredRecord> transform = new JSONFormatter(config);
    transform.initialize(null);
    MockEmitter<StructuredRecord> emitter = new MockEmitter<>();
    transform.transform(StructuredRecord.builder(INPUT1)
                          .set("a", "1")
                          .set("b", "2")
                          .set("c", "3")
                          .set("d", "4")
                          .set("e", "5").build(), emitter);
    Assert.assertEquals("body", emitter.getEmitted().get(0).get("{\"a\":\"1\",\"b\":\"2\",\"c\":\"3\",\"d\":\"4\"," +
                                                                  "\"e\":\"5\"}"));
  }
}
@@ -2074,16 +2074,17 @@
 itter);%0A
+%0A
     Asse
@@ -2104,48 +2104,8 @@
 ls(%22
-body%22, emitter.getEmitted().get(0).get(%22
 %7B%5C%22a
@@ -2153,28 +2153,23 @@
 4%5C%22,
-%22 +%0A                
+%5C%22e%5C%22:%5C%225%5C%22%7D%22,%0A
     
@@ -2192,47 +2192,45 @@
     
-                          %22%5C%22e%5C%22:%5C%225%5C%22%7D
+emitter.getEmitted().get(0).get(%22body
 %22));

Fix unit tests