package de.tudresden.slr.latexexport.data;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;

import de.tudresden.slr.metainformation.util.DataProvider;
import de.tudresden.slr.model.taxonomy.Term;
import de.tudresden.slr.model.taxonomy.impl.TermImpl;

public class LatexExportChartGeneratorTest {

	@Rule
	public TemporaryFolder tempFolder = new TemporaryFolder();
	
	private DataProvider dataProvider;

	@Before
	public void setUp() throws Exception {		
		EList<Term> mainDimensions = new BasicEList<>();
		EList<Term> subDimensions = new BasicEList<>();
		
		Term termA = Mockito.mock(Term.class);
		Mockito.when(termA.getName()).thenReturn("termA");
		//Mockito.when(termA.getSubclasses()).thenReturn(subDimensions);
		mainDimensions.add(termA);
		
		Term termB = Mockito.mock(Term.class);
		Mockito.when(termB.getName()).thenReturn("termB");
		subDimensions.add(termB);
		
		dataProvider = Mockito.mock(DataProvider.class);
		Mockito.when(dataProvider.getMainDimensions()).thenReturn(mainDimensions);
	}

	@Test
	public void testTexAndImagesAreCreated() throws IOException {
		// renderer dv.JPG not available in jenkins build
		File targetFile = tempFolder.newFile("output.texFileEnding");
		LatexExportChartGenerator.generatePDFOutput(targetFile.toString(), dataProvider);
		
		File texFile = null;
		File imagesFolder = null;

		for(File f : tempFolder.getRoot().listFiles()) {
			if(f.getName().contains("texFileEnding")) {
				texFile = f;
			}
			
			if(f.getName().contains("images")) {
				imagesFolder = f;
			}
		}
		
		// assert that there are the tex file, the images folder and exactly one image
		assertNotNull(texFile);
//		assertNotNull(imagesFolder);
//		assertEquals(1, imagesFolder.listFiles().length);
	}

}

@@ -1151,18 +1151,16 @@
 A%22);%0D%0A%09%09
-//
 Mockito.
@@ -1215,16 +1215,16 @@
 ions);%0D%0A
+
 %09%09mainDi
@@ -1347,16 +1347,18 @@
 B%22);%0D%0A%09%09
+//
 subDimen
@@ -1552,17 +1552,22 @@
 AndImage
-s
+Folder
 AreCreat
@@ -2168,26 +2168,24 @@
 (texFile);%0D%0A
-//
 %09%09assertNotN
@@ -2208,63 +2208,8 @@
 );%0D%0A
-//%09%09assertEquals(1, imagesFolder.listFiles().length);%0D%0A
 %09%7D%0D%0A

Edit chart generator test