package org.geometrycommands;

import org.geometrycommands.DrawBase64Command.DrawOptions;
import org.junit.Test;

import java.io.File;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
 * The DrawBase64Command UnitTest
 *
 * @author Jared Erickson
 */
public class DrawBase64CommandTest extends BaseTest {

    @Test
    public void execute() throws Exception {
        // PNG no prefix
        String inputGeometry = "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))";
        DrawOptions options = new DrawOptions();
        options.setGeometry(inputGeometry);

        Reader reader = new StringReader(inputGeometry);
        StringWriter writer = new StringWriter();

        DrawBase64Command command = new DrawBase64Command();
        command.execute(options, reader, writer);
        String result = writer.toString();
        assertTrue(result.length() > 0);
        assertFalse(result.startsWith("data:image/jpeg;base64"));

        // JPEG with prefix
        options = new DrawOptions();
        options.setGeometry(inputGeometry);
        options.setType("jpeg");
        options.setIncludingPrefix(true);

        reader = new StringReader(inputGeometry);
        writer = new StringWriter();

        command = new DrawBase64Command();
        command.execute(options, reader, writer);
        result = writer.toString();
        assertTrue(result.length() > 0);
        assertTrue(result.startsWith("data:image/jpeg;base64"));
    }

    @Test
    public void run() throws Exception {
        // PNG, no prefix, geometry from options
        String result = runApp(new String[]{
                "drawbase64",
                "-g", "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))"
        }, null);
        assertTrue(result.length() > 0);
        assertFalse(result.startsWith("data:image/jpeg;base64"));
    }
}

@@ -1057,11 +1057,10 @@
  // 
-JPE
+PN
 G wi
@@ -1175,19 +1175,18 @@
 etType(%22
-jpe
+pn
 g%22);%0A   
@@ -1524,35 +1524,34 @@
 ith(%22data:image/
-jpe
+pn
 g;base64%22));%0A   
@@ -1894,35 +1894,684 @@
 ith(%22data:image/
-jpe
+png;base64%22));%0A%0A        // PNG with prefix, geometry from input stream%0A        result = runApp(new String%5B%5D%7B%0A                %22drawbase64%22,%0A                %22-y%22, %22png%22,%0A                %22-p%22,%0A                %22-w%22, %22300%22,%0A                %22-h%22, %22250%22,%0A                %22-b%22, %220,0,0%22,%0A                %22-s%22, %22255,255,255%22,%0A                %22-t%22, %220.75%22,%0A                %22-l%22, %22255,255,0%22,%0A                %22-o%22, %220.55%22,%0A                %22-m%22, %22square%22,%0A                %22-z%22, %2212%22,%0A                %22-e%22, %220,0,10,10%22%0A        %7D, %22POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))%22);%0A        assertTrue(result.length() %3E 0);%0A        assertTrue(result.startsWith(%22data:image/pn
 g;base64%22));%0A   

Change jpeg to png image types