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.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();
        System.out.println(result);
        assertTrue(result.startsWith("iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAYAAACAvzbMAAAGoUlEQVR42u3VsQkAIAxFQXfN"));

        // 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();
        System.out.println(result);
        assertTrue(result.startsWith("data:image/jpeg;base64,/9j/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aH"));
    }

    @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);
        System.out.println(result);
        assertTrue(result.startsWith("iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAYAAACAvzbMAAAGoUlEQVR42u3VsQkAIAxFQXfN"));

        // JPEG with prefix, geometry from input stream
        result = runApp(new String[]{
                "drawbase64",
                "-y", "jpeg",
                "-p",
                "-w", "300",
                "-h", "250",
                "-b", "0,0,0",
                "-s", "255,255,255",
                "-t", "0.75",
                "-l", "255,255,0",
                "-o", "0.55",
                "-m", "square",
                "-z", "12",
                "-e", "0,0,10,10"
        }, "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))");
        System.out.println(result);
        assertTrue(result.startsWith("data:image/jpeg;base64,/9j/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aH"));
    }
}

@@ -892,43 +892,14 @@
 ng()
-;%0A        System.out.println(result
+.trim(
 );%0A 
@@ -1417,43 +1417,14 @@
 ng()
-;%0A        System.out.println(result
+.trim(
 );%0A 
@@ -1807,43 +1807,14 @@
 ull)
-;%0A        System.out.println(result
+.trim(
 );%0A 
@@ -2476,43 +2476,14 @@
 ))%22)
-;%0A        System.out.println(result
+.trim(
 );%0A 

trim the base64 strings