package plugtests;

import static org.junit.Assert.assertNotNull;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import eu.europa.esig.dss.FileDocument;
import eu.europa.esig.dss.client.http.IgnoreDataLoader;
import eu.europa.esig.dss.utils.Utils;
import eu.europa.esig.dss.validation.CommonCertificateVerifier;
import eu.europa.esig.dss.validation.SignedDocumentValidator;
import eu.europa.esig.dss.validation.reports.DetailedReport;
import eu.europa.esig.dss.validation.reports.Reports;
import eu.europa.esig.dss.validation.reports.SimpleReport;
import eu.europa.esig.dss.validation.reports.wrapper.DiagnosticData;

/**
 * This test is only to ensure that we don't have exception with valid? files
 */
@RunWith(Parameterized.class)
public class ETSISamplesValidation {

	@Parameters(name = "Validation {index} : {0}")
	public static Collection<Object[]> data() {
		File folder = new File("src/test/resources/plugtest");
		Collection<File> listFiles = Utils.listFiles(folder, new String[] { "pdf" }, true);
		Collection<Object[]> dataToRun = new ArrayList<Object[]>();
		for (File file : listFiles) {
			dataToRun.add(new Object[] { file });
		}
		return dataToRun;
	}

	private File fileToTest;

	public ETSISamplesValidation(File fileToTest) {
		this.fileToTest = fileToTest;
	}

	@Test
	public void testValidate() {
		SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(new FileDocument(fileToTest));

		CommonCertificateVerifier certificateVerifier = new CommonCertificateVerifier();
		certificateVerifier.setDataLoader(new IgnoreDataLoader());
		validator.setCertificateVerifier(certificateVerifier);

		Reports validateDocument = validator.validateDocument();
		assertNotNull(validateDocument);

		DiagnosticData diagnosticData = validateDocument.getDiagnosticData();
		assertNotNull(diagnosticData);

		SimpleReport simpleReport = validateDocument.getSimpleReport();
		assertNotNull(simpleReport);

		DetailedReport detailedReport = validateDocument.getDetailedReport();
		assertNotNull(detailedReport);

		// validateDocument.print();
	}

}

@@ -75,20 +75,92 @@
 java.io.
-File
+BufferedReader;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader
 ;%0Aimport
@@ -385,20 +385,63 @@
 sig.dss.
-File
+DSSDocument;%0Aimport eu.europa.esig.dss.InMemory
 Document
@@ -502,47 +502,8 @@
 er;%0A
-import eu.europa.esig.dss.utils.Utils;%0A
 impo
@@ -1022,16 +1022,17 @@
 tion %7B%0A%0A
+%0A
 %09@Parame
@@ -1118,247 +1118,424 @@
 a() 
-%7B%0A%09%09File folder = new File(%22src/test/resources/plugtest%22);%0A%09%09Collection%3CFile%3E listFiles = Utils.listFiles(folder, new String%5B%5D %7B %22pdf%22 %7D, true);%0A%09%09Collection%3CObject%5B%5D%3E dataToRun = new ArrayList%3CObject%5B%5D%3E();%0A%09%09for (File file : listFiles
+throws IOException %7B%0A%0A%09%09// We use this file because File.listFiles() doesn't work from another jar%0A%09%09String listFiles = %22/plugtest/plugtest_files.txt%22;%0A%0A%09%09Collection%3CObject%5B%5D%3E dataToRun = new ArrayList%3CObject%5B%5D%3E();%0A%09%09try (BufferedReader br = new BufferedReader(new InputStreamReader(ETSISamplesValidation.class.getResourceAsStream(listFiles)))) %7B%0A%09%09%09String filepath;%0A%09%09%09while ((filepath = br.readLine()) != null
 ) %7B%0A
+%09
 %09%09%09d
@@ -1566,16 +1566,97 @@
 %5D %7B 
-file %7D);
+new InMemoryDocument(ETSISamplesValidation.class.getResourceAsStream(filepath)) %7D);%0A%09%09%09%7D%0A
 %0A%09%09%7D
@@ -1689,31 +1689,31 @@
 private 
-File fileToTest
+DSSDocument doc
 ;%0A%0A%09publ
@@ -1741,57 +1741,43 @@
 ion(
-File fileToTest) %7B%0A%09%09this.fileToTest = fileToTest
+DSSDocument doc) %7B%0A%09%09this.doc = doc
 ;%0A%09%7D
@@ -1894,36 +1894,11 @@
 ent(
-new FileDocument(fileToTest)
+doc
 );%0A%0A

Improve unit tests to cover both implementations