Added testcases for indexing.

Change-Id: I63ceff2056141d8ac576cb78e0a3f4a8e0a02e44
diff --git a/src/test/java/de/ids_mannheim/korap/TestIndexer.java b/src/test/java/de/ids_mannheim/korap/TestIndexer.java
new file mode 100644
index 0000000..ea2aea9
--- /dev/null
+++ b/src/test/java/de/ids_mannheim/korap/TestIndexer.java
@@ -0,0 +1,112 @@
+package de.ids_mannheim.korap;

+

+import static org.junit.Assert.assertEquals;

+

+import java.io.ByteArrayOutputStream;

+import java.io.File;

+import java.io.IOException;

+import java.io.PrintStream;

+

+import org.junit.After;

+import org.junit.Before;

+import org.junit.Test;

+import org.slf4j.Logger;

+import org.slf4j.LoggerFactory;

+

+import de.ids_mannheim.korap.index.Indexer;

+

+/**

+ * @author margaretha

+ *

+ */

+public class TestIndexer {

+    private Logger logger = LoggerFactory.getLogger(TestIndexer.class);

+    private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

+    private String info = "usage: Krill indexer";

+    private File outputDirectory = new File("test-index");

+

+    @Test

+    public void testArguments () throws IOException {

+        Indexer.main(new String[] { "-c", "src/test/resources/krill.properties",

+                "-i", "src/test/resources/bzk" });

+        assertEquals("Indexed 1 file.", outputStream.toString());

+    }

+

+    @Test

+    public void testOutputArgument () throws IOException {

+        Indexer.main(new String[] { "-c", "src/test/resources/krill.properties",

+                "-i", "src/test/resources/bzk", "-o", "test-output"});

+        assertEquals("Indexed 1 file.", outputStream.toString());

+    }

+

+    @Test

+    public void testMultipleInputFiles () throws IOException {

+        Indexer.main(new String[] { "-c", "src/test/resources/krill.properties",

+                "-i", "src/test/resources/wiki" });

+        assertEquals("Indexed 14 files.", outputStream.toString());

+    }

+

+    @Test

+    public void testMultipleInputDirectories () throws IOException {

+        Indexer.main(new String[] { "-c", "src/test/resources/krill.properties",

+                "-i",

+                "src/test/resources/bzk;src/test/resources/goe;src/test/resources/sgbr",

+                "-o", "test-index" });

+        assertEquals("Indexed 3 files.", outputStream.toString());

+    }

+

+    @Test

+    public void testEmptyArgument () throws IOException {

+        Indexer.main(new String[] {});

+        logger.info(outputStream.toString());

+        assertEquals(true, outputStream.toString().startsWith(info));

+    }

+

+

+    @Test

+    public void testMissingConfig () throws IOException {

+        Indexer.main(new String[] { "-i", "src/test/resources/bzk",

+                "-o test-index" });

+        logger.info(outputStream.toString());

+        assertEquals(true, outputStream.toString().startsWith(info));

+    }

+

+    @Test

+    public void testMissingInput () throws IOException {

+        Indexer.main(new String[] { "-c", "src/test/resources/krill.properties",

+                "-o", "test-index" });

+        logger.info(outputStream.toString());

+        assertEquals(true, outputStream.toString().startsWith(info));

+    }

+

+    @Before

+    public void setOutputStream () {

+        System.setOut(new PrintStream(outputStream));

+    }

+

+    @After

+    public void cleanOutputStream () {

+        System.setOut(null);

+    }

+

+    @Before

+    public void cleanOutputDirectory () {

+

+        if (outputDirectory.exists()) {

+            logger.debug("Output directory exists");

+            deleteFile(outputDirectory);

+        }

+    }

+

+    private void deleteFile (File path) {

+        if (path.isDirectory()) {

+            File file;

+            for (String filename : path.list()) {

+                file = new File(path + "/" + filename);

+                deleteFile(file);

+                logger.debug(file.getAbsolutePath());

+            }

+        }

+        path.delete();

+    }

+}

diff --git a/src/test/java/de/ids_mannheim/korap/query/TestSpanRelationQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestSpanRelationQueryJSON.java
index 8be9a79..3122b4d 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestSpanRelationQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestSpanRelationQueryJSON.java
@@ -70,7 +70,7 @@
 
 
     @Test
-    public void testMatchBothRelationNodeWithAttribute ()
+    public void testMatchBothRelationNodesWithAttribute ()
             throws QueryException {
         String filepath = getClass()
                 .getResource(
diff --git a/src/test/resources/krill.properties b/src/test/resources/krill.properties
index f9cbc50..e14926b 100644
--- a/src/test/resources/krill.properties
+++ b/src/test/resources/krill.properties
@@ -1,2 +1,3 @@
 krill.version = ${project.version}
 krill.name = ${project.name}
+krill.indexDir = test-output
\ No newline at end of file