package leigh.eo.json;

import leigh.eo.EO;
import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class TestEoJson {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(TestEoJson.class);

    @Test
    public void testThing() throws IOException {
        EO hello = new EO("greeting");
        hello.setValue("msg", "Hello World!");
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        JsonOutput jsonOut = new JsonOutput(out);
        jsonOut.writeEO(hello);
        jsonOut.close();

        logger.info("Encoded: {}", out.toString());

        JsonInput jsonIn = new JsonInput(new ByteArrayInputStream(out.toByteArray()));
        EO readBack = jsonIn.readEo();
        logger.info("Readback : {}", readBack);
        readBack = jsonIn.readEo();
        logger.info("Readback : {}", readBack);
    }
}