Added vc loading from classpath for testing.

Change-Id: I71bf7f98497e04c133e0fe970b9ef9a84fd43399
diff --git a/src/main/java/de/ids_mannheim/korap/KrillCollection.java b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
index 14153e7..8f8dbde 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
@@ -3,6 +3,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.nio.ByteBuffer;
 import java.util.Properties;
 import java.util.Set;
@@ -175,6 +176,9 @@
 			return null;
         }
 
+        String p = prop.getProperty("krill.test", "false");
+        boolean isTest = Boolean.parseBoolean(p);
+                
         String namedVCPath = prop.getProperty("krill.namedVC");
 
 		if (!namedVCPath.endsWith("/")) {
@@ -184,6 +188,7 @@
 		String fileName = namedVCPath + ref + ".jsonld";
 		File file; 
         String json = null;
+        InputStream is = null;
         if ((file= new File(fileName)).exists()) {
             try (FileInputStream fis = new FileInputStream(file)) {
                 json = IOUtils.toString(fis,"utf-8");
@@ -209,6 +214,18 @@
 				return this;
             }
         }
+        // for testing
+        else if (isTest
+                && (is = retrieveInputStreamFromClasspath(fileName)) != null) {
+            try {
+                json = IOUtils.toString(is, "utf-8");
+            }
+            catch (IOException e) {
+                this.addError(StatusCodes.READING_COLLECTION_FAILED,
+                        e.getMessage());
+                return this;
+            }
+        }
         else{
             this.addError(StatusCodes.MISSING_COLLECTION,
                     "Collection is not found " + fileName);
@@ -219,6 +236,14 @@
 	};
 
 
+    private InputStream retrieveInputStreamFromClasspath (String fileName) {
+        if (!fileName.startsWith("/")) {
+            fileName = "/"+fileName;
+        }
+        return KrillCollection.class.getResourceAsStream(fileName);
+    }
+
+
     /**
      * Import the "collection" part of a KoralQuery.
      * 
diff --git a/src/test/java/de/ids_mannheim/korap/cache/TestVirtualCorpusCache.java b/src/test/java/de/ids_mannheim/korap/cache/TestVirtualCorpusCache.java
index b456930..95bf1c6 100644
--- a/src/test/java/de/ids_mannheim/korap/cache/TestVirtualCorpusCache.java
+++ b/src/test/java/de/ids_mannheim/korap/cache/TestVirtualCorpusCache.java
@@ -68,7 +68,6 @@
         assertFalse(VirtualCorpusCache.contains(vcId));
     }
 
-
     @Test
     public void testReferToUncachedVC () throws IOException, QueryException {
         String vcId = "named-vc1";
diff --git a/src/test/resources/krill.properties b/src/test/resources/krill.properties
index eb7f374..0c26284 100644
--- a/src/test/resources/krill.properties
+++ b/src/test/resources/krill.properties
@@ -1,7 +1,7 @@
 krill.version = ${project.version}
 krill.name = ${project.name}
 krill.indexDir = test-output
-krill.namedVC = vc
 krill.index.commit.count = 15
 
-krill.namedVC=src/test/resources/queries/collections/named-vcs/
\ No newline at end of file
+krill.namedVC = queries/collections/named-vcs/
+krill.test = true
\ No newline at end of file