package com.workfusion.odf.impl.converter;

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

import org.apache.poi.util.IOUtils;
import org.junit.jupiter.api.Test;

import com.workfusion.odf.impl.converter.excel2html.ToHtml;

import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
 * @author Maksim Turchyn
 */
public class ToHtmlTest {
    @Test
    public void differentExcelFormats() throws Exception {
        byte[] excelAsBytes = IOUtils.toByteArray(ClassLoader.class.getResourceAsStream("/excel/excel-different-sheets.xlsx"));
        byte[] htmlAsBytes = convertToHTML(excelAsBytes);
        assertNotNull(htmlAsBytes);
    }

    protected byte[] convertToHTML(byte[] content) {
        InputStream input = new ByteArrayInputStream(content);
        ByteArrayOutputStream output = new ByteArrayOutputStream();

        try {
            ToHtml toHtml = ToHtml.create(input, new PrintWriter(output));
            toHtml.setCompleteHTML(true);
            toHtml.printPage();
            output.close();
            return output.toByteArray();//StandardCharsets.UTF_8.name()
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
    }
}
