package model.transform;

import org.junit.Test;
import util.FilestackService;

import static org.junit.Assert.assertTrue;
import static util.MockConstants.*;

public class TestTransform {
    private static final TransformTask TASK = new TransformTask("task");
    static {
        TASK.addOption("option1", 1);
        TASK.addOption("option2", 1.0);
        TASK.addOption("option3", "value");
        TASK.addOption("option4", new Integer[]{1,1,1,1});
    }
    private static final String TASK_STRING = "task=option1:1,option2:1.0,option3:value,option4:[1,1,1,1]";
    private static final String SOURCE = "https://example.com/image.jpg";

    @Test
    public void testUrl() {
        String correct = FilestackService.Process.URL + TASK_STRING + "/" + HANDLE;
        Transform transform = new Transform(FILE_LINK);
        transform.tasks.add(TASK);
        String output = transform.url();

        String message = String.format("URL malformed\nCorrect: %s\nOutput:  %s", correct, output);
        assertTrue(message, output.equals(correct));
    }
    
    @Test
    public void testUrlExternal() {
        String correct = FilestackService.Process.URL + API_KEY + "/" + TASK_STRING + "/" + SOURCE;
        Transform transform = new Transform(CLIENT, SOURCE);
        transform.tasks.add(TASK);
        String output = transform.url();

        String message = String.format("URL malformed\nCorrect: %s\nOutput:  %s", correct, output);
        assertTrue(message, output.equals(correct));
    }

    @Test
    public void testUrlMultipleTasks() {
        String correct = FilestackService.Process.URL + TASK_STRING + "/" + TASK_STRING + "/" + HANDLE;

        Transform transform = new Transform(FILE_LINK);
        transform.tasks.add(TASK);
        transform.tasks.add(TASK);
        String output = transform.url();

        String message = String.format("URL malformed\nCorrect: %s\nOutput:  %s", correct, output);
        assertTrue(message, output.equals(correct));
    }

    @Test
    public void testUrlTaskWithoutOptions() {
        String correct = FilestackService.Process.URL + "task/" + HANDLE;

        Transform transform = new Transform(FILE_LINK);
        transform.tasks.add(new TransformTask("task"));
        String output = transform.url();

        String message = String.format("URL malformed\nCorrect: %s\nOutput:  %s", correct, output);
        assertTrue(message, output.equals(correct));
    }
}

@@ -885,32 +885,610 @@
 ansform.url();%0A%0A
+        String message = String.format(%22URL malformed%5CnCorrect: %25s%5CnOutput:  %25s%22, correct, output);%0A        assertTrue(message, output.equals(correct));%0A    %7D%0A%0A    @Test%0A    public void testUrlSecurity() %7B%0A        String correct = FilestackService.Process.URL%0A                + %22security=policy:%22 + SECURITY.getPolicy() + %22,%22%0A                + %22signature:%22 + SECURITY.getSignature() + %22/%22%0A                + TASK_STRING + %22/%22 + HANDLE;%0A%0A        Transform transform = new Transform(FILE_LINK_SECURITY);%0A        transform.tasks.add(TASK);%0A        String output = transform.url();%0A%0A
         String m

Add test for transform security formatting