package com.capgemini.reports.printing;

import com.capgemini.framework.common.ResourceHelper;
import com.capgemini.reports.exceptions.FileLoadingException;
import com.capgemini.reports.printing.Printer.PrintFormat;
import net.sf.jasperreports.engine.JRException;
import org.testng.annotations.Test;

import java.io.IOException;
import java.io.InputStream;

import static org.assertj.core.api.Assertions.assertThat;


public class PrintParametersTest {

    private static final String PARAM_KEY = "Parameter Key";
    private static final String PARAM_VALUE = "Parameter Value";
    private static final String TEMPLATE = "/Jasper/template/dynamic_table/reference.jrxml";
    private static final String FOLDER = "Folder";
    private static final String FILENAME = "Filename";


    @Test
    public void printParametersTest() throws FileLoadingException, JRException, IOException {
        try (InputStream templateIS = ResourceHelper.getResourceAsStream(TEMPLATE)) {
            PrintParameters mainReport = new PrintParameters(PrintFormat.PDF, FILENAME, FOLDER, templateIS);
          assertThat(mainReport.getTemplate()).isNotNull();
          assertThat(mainReport.getParameters()).isEmpty();
          assertThat(mainReport.hasSubReports()).isFalse();

            mainReport.addReportParameter(PARAM_KEY, PARAM_VALUE);
          assertThat(mainReport.getParameters().get(PARAM_KEY)).isEqualTo(PARAM_VALUE);
        }
    }
}
