// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java
// public class Result {
// 
//     private final String title;
//     private final String excerpt;
//     private final List<String> categories;
//     private final List<String> speakers;
//     private final Date date;
// 
//     public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) {
//         this.title = title;
//         this.excerpt = excerpt;
//         this.categories = categories;
//         this.speakers = speakers;
//         this.date = date;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public String getExcerpt() {
//         return excerpt;
//     }
// 
//     public List<String> getCategories() {
//         return categories;
//     }
// 
//     public List<String> getSpeakers() {
//         return speakers;
//     }
// 
//     public Date getDate() {
//         return date;
//     }
// }
// 
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java
// public class Talk {
// 
//     public final String path;
//     public final String title;
//     public final List<String> speakers;
//     public final Date date;
//     public final String content;
//     public final List<String> categories;
//     public final String organizer;
// 
//     public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) {
//         this.path = path;
//         this.title = title;
//         this.speakers = speakers;
//         this.date = date;
//         this.content = content;
//         this.categories = categories;
//         this.organizer = organizer;
//     }
// }


import com.google.common.io.Files;
import com.google.common.io.Resources;
import de.fhopf.lucenesolrtalk.Result;
import de.fhopf.lucenesolrtalk.Talk;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.sax.BodyContentHandler;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.xml.sax.SAXException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import static junit.framework.Assert.*;
import org.apache.lucene.queryparser.classic.ParseException;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
package de.fhopf.lucenesolrtalk.lucene;




public class TikaIndexerTest {

    private static String dataDir;

    @BeforeClass
    public static void copySlides() throws IOException {
        File directory = Files.createTempDir();
        File pdf = new File(directory, "enter-the-gradle.pdf");
        FileOutputStream out = new FileOutputStream(pdf);
        Resources.copy(Resources.getResource(TikaIndexerTest.class, "enter-the-gradle.pdf"), out);
        out.close();
        dataDir = directory.getAbsolutePath();
    }


    @Test
    public void pdfIsTransformed() throws IOException {

        Indexer indexer = mock(Indexer.class);
        TikaIndexer tikaIndexer = new TikaIndexer(indexer);

        tikaIndexer.indexDir(dataDir);

        ArgumentCaptor<Talk> argument = ArgumentCaptor.forClass(Talk.class);
        verify(indexer).index(argument.capture());

        assertEquals("enter-the-gradle.pdf", argument.getValue().title);
        assertFalse(argument.getValue().content.isEmpty());
    }


    @Test
    public void gradleIsGroovy() throws ParseException {
        Directory dir = new RAMDirectory();
        Indexer indexer = new Indexer(dir);
        TikaIndexer tikaIndexer = new TikaIndexer(indexer);

        tikaIndexer.indexDir(dataDir);

        Searcher searcher = new Searcher(dir);

// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java
// public class Result {
// 
//     private final String title;
//     private final String excerpt;
//     private final List<String> categories;
//     private final List<String> speakers;
//     private final Date date;
// 
//     public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) {
//         this.title = title;
//         this.excerpt = excerpt;
//         this.categories = categories;
//         this.speakers = speakers;
//         this.date = date;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public String getExcerpt() {
//         return excerpt;
//     }
// 
//     public List<String> getCategories() {
//         return categories;
//     }
// 
//     public List<String> getSpeakers() {
//         return speakers;
//     }
// 
//     public Date getDate() {
//         return date;
//     }
// }
// 
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Talk.java
// public class Talk {
// 
//     public final String path;
//     public final String title;
//     public final List<String> speakers;
//     public final Date date;
//     public final String content;
//     public final List<String> categories;
//     public final String organizer;
// 
//     public Talk(String path, String title, List<String> speakers, Date date, String content, List<String> categories, String organizer) {
//         this.path = path;
//         this.title = title;
//         this.speakers = speakers;
//         this.date = date;
//         this.content = content;
//         this.categories = categories;
//         this.organizer = organizer;
//     }
// }


// Path: lucene/src/test/java/de/fhopf/lucenesolrtalk/lucene/TikaIndexerTest.java
import com.google.common.io.Files;
import com.google.common.io.Resources;
import de.fhopf.lucenesolrtalk.Result;
import de.fhopf.lucenesolrtalk.Talk;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.sax.BodyContentHandler;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.xml.sax.SAXException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import static junit.framework.Assert.*;
import org.apache.lucene.queryparser.classic.ParseException;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

package de.fhopf.lucenesolrtalk.lucene;




public class TikaIndexerTest {

    private static String dataDir;

    @BeforeClass
    public static void copySlides() throws IOException {
        File directory = Files.createTempDir();
        File pdf = new File(directory, "enter-the-gradle.pdf");
        FileOutputStream out = new FileOutputStream(pdf);
        Resources.copy(Resources.getResource(TikaIndexerTest.class, "enter-the-gradle.pdf"), out);
        out.close();
        dataDir = directory.getAbsolutePath();
    }


    @Test
    public void pdfIsTransformed() throws IOException {

        Indexer indexer = mock(Indexer.class);
        TikaIndexer tikaIndexer = new TikaIndexer(indexer);

        tikaIndexer.indexDir(dataDir);

        ArgumentCaptor<Talk> argument = ArgumentCaptor.forClass(Talk.class);
        verify(indexer).index(argument.capture());

        assertEquals("enter-the-gradle.pdf", argument.getValue().title);
        assertFalse(argument.getValue().content.isEmpty());
    }


    @Test
    public void gradleIsGroovy() throws ParseException {
        Directory dir = new RAMDirectory();
        Indexer indexer = new Indexer(dir);
        TikaIndexer tikaIndexer = new TikaIndexer(indexer);

        tikaIndexer.indexDir(dataDir);

        Searcher searcher = new Searcher(dir);

        List<Result> results = searcher.search("Groovy");