// Path: asciidoctorj-springboot-integration-test/src/test/java/org/asciidoctor/it/springboot/ProcessHelper.java
// static ProcessOutput run(Map<String, String> env, String... command) throws IOException, InterruptedException {
//     ProcessBuilder processBuilder = new ProcessBuilder(command)
//             .directory(new File("springboot-app"));
// 
//     processBuilder.environment().clear();
//     String javaHome = System.getProperty("java.home");
//     processBuilder.environment().put("JAVA_HOME", javaHome);
//     processBuilder.environment().put("PATH", javaHome + "/bin");
//     processBuilder.environment().putAll(env);
// 
//     Process process = processBuilder.start();
// 
//     final InputStream is = process.getInputStream();
//     final InputStream es = process.getErrorStream();
//     boolean status = process.waitFor(10l, TimeUnit.SECONDS);
//     if (!status) {
//         byte[] buffer = new byte[1800];
//         IOUtils.read(is, buffer);
//         return new ProcessOutput(process, new String(buffer), new String());
//     }
// 
//     return new ProcessOutput(IOUtils.toString(es), IOUtils.toString(is));
// }


import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import kotlin.collections.ArrayDeque;
import okhttp3.*;
import org.awaitility.Awaitility;
import org.junit.After;
import org.junit.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.asciidoctor.it.springboot.ProcessHelper.run;
import static org.assertj.core.api.Assertions.assertThat;
    @After
    public void cleanup() {
        testProcesses.forEach(Process::destroy);
    }

    private Map<String, String> convertDocument(String asciidocDocument, int serverPort) throws IOException {
        String body = "{\"data\":\"" + base64Encode(asciidocDocument) + "\"}";

        Request request = new Request.Builder()
                .url("http://localhost:" + serverPort + "/asciidoc")
                .post(RequestBody.create(body, MediaType.parse("application/json")))
                .build();
        Response response = new OkHttpClient()
                .newCall(request)
                .execute();

        return new Gson()
                .fromJson(response.body().string(), new TypeToken<Map<String, String>>() {}.getType());
    }

    private String base64Encode(String asciidocDocument) {
        return new String(Base64.getEncoder().encode(asciidocDocument.getBytes(StandardCharsets.UTF_8)));
    }

    private String base64Decode(String value) {
        return new String(Base64.getDecoder().decode(value));
    }

    private void startSpringBootApp(int serverPort) throws IOException, InterruptedException {

// Path: asciidoctorj-springboot-integration-test/src/test/java/org/asciidoctor/it/springboot/ProcessHelper.java
// static ProcessOutput run(Map<String, String> env, String... command) throws IOException, InterruptedException {
//     ProcessBuilder processBuilder = new ProcessBuilder(command)
//             .directory(new File("springboot-app"));
// 
//     processBuilder.environment().clear();
//     String javaHome = System.getProperty("java.home");
//     processBuilder.environment().put("JAVA_HOME", javaHome);
//     processBuilder.environment().put("PATH", javaHome + "/bin");
//     processBuilder.environment().putAll(env);
// 
//     Process process = processBuilder.start();
// 
//     final InputStream is = process.getInputStream();
//     final InputStream es = process.getErrorStream();
//     boolean status = process.waitFor(10l, TimeUnit.SECONDS);
//     if (!status) {
//         byte[] buffer = new byte[1800];
//         IOUtils.read(is, buffer);
//         return new ProcessOutput(process, new String(buffer), new String());
//     }
// 
//     return new ProcessOutput(IOUtils.toString(es), IOUtils.toString(is));
// }


// Path: asciidoctorj-springboot-integration-test/src/test/java/org/asciidoctor/it/springboot/SpringBootTest.java
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import kotlin.collections.ArrayDeque;
import okhttp3.*;
import org.awaitility.Awaitility;
import org.junit.After;
import org.junit.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.asciidoctor.it.springboot.ProcessHelper.run;
import static org.assertj.core.api.Assertions.assertThat;

    @After
    public void cleanup() {
        testProcesses.forEach(Process::destroy);
    }

    private Map<String, String> convertDocument(String asciidocDocument, int serverPort) throws IOException {
        String body = "{\"data\":\"" + base64Encode(asciidocDocument) + "\"}";

        Request request = new Request.Builder()
                .url("http://localhost:" + serverPort + "/asciidoc")
                .post(RequestBody.create(body, MediaType.parse("application/json")))
                .build();
        Response response = new OkHttpClient()
                .newCall(request)
                .execute();

        return new Gson()
                .fromJson(response.body().string(), new TypeToken<Map<String, String>>() {}.getType());
    }

    private String base64Encode(String asciidocDocument) {
        return new String(Base64.getEncoder().encode(asciidocDocument.getBytes(StandardCharsets.UTF_8)));
    }

    private String base64Decode(String value) {
        return new String(Base64.getDecoder().decode(value));
    }

    private void startSpringBootApp(int serverPort) throws IOException, InterruptedException {

        ProcessHelper.ProcessOutput run = run(singletonMap("SERVER_PORT", String.valueOf(serverPort)),