Fixed resource DAO & added tests.

Change-Id: I9222d20efa62f7bc37b8e38a2d1ec6b0ea70117e
diff --git a/full/src/main/java/de/ids_mannheim/korap/dao/ResourceDao.java b/full/src/main/java/de/ids_mannheim/korap/dao/ResourceDao.java
index ff3ffd0..d12ff3f 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dao/ResourceDao.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dao/ResourceDao.java
@@ -4,8 +4,10 @@
 import java.util.Set;
 
 import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
 import javax.persistence.PersistenceContext;
 import javax.persistence.Query;
+import javax.persistence.TypedQuery;
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Root;
@@ -37,15 +39,14 @@
      * 
      * @return a list of resources
      */
-    @SuppressWarnings("unchecked")
     public List<Resource> getAllResources () {
         CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
         CriteriaQuery<Resource> query =
                 criteriaBuilder.createQuery(Resource.class);
         Root<Resource> resource = query.from(Resource.class);
         query.select(resource);
-        
-        Query q = entityManager.createQuery(query);
+
+        TypedQuery<Resource> q = entityManager.createQuery(query);
         return q.getResultList();
     }
 
@@ -58,12 +59,17 @@
         query.where(criteriaBuilder.equal(resource.get(Resource_.id), id));
 
         Query q = entityManager.createQuery(query);
-        return (Resource) q.getSingleResult();
+        try {
+            return (Resource) q.getSingleResult();
+        }
+        catch (NoResultException e) {
+            return null;
+        }
     }
 
     public void createResource (String id, String germanTitle,
-            String englishTitle, String englishDescription, Set<AnnotationLayer> layers)
-            throws KustvaktException {
+            String englishTitle, String englishDescription,
+            Set<AnnotationLayer> layers) throws KustvaktException {
         ParameterChecker.checkStringValue(id, "id");
         ParameterChecker.checkStringValue(englishTitle, "en_title");
         ParameterChecker.checkStringValue(germanTitle, "de_title");
diff --git a/full/src/main/java/de/ids_mannheim/korap/entity/Resource.java b/full/src/main/java/de/ids_mannheim/korap/entity/Resource.java
index fbe3f92..813adc5 100644
--- a/full/src/main/java/de/ids_mannheim/korap/entity/Resource.java
+++ b/full/src/main/java/de/ids_mannheim/korap/entity/Resource.java
@@ -6,8 +6,8 @@
 import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.Id;
-import javax.persistence.JoinTable;
 import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
 import javax.persistence.ManyToMany;
 import javax.persistence.Table;
 
diff --git a/full/src/main/resources/free-resources.json b/full/src/main/resources/free-resources.json
index ea71020..ba6f63e 100644
--- a/full/src/main/resources/free-resources.json
+++ b/full/src/main/resources/free-resources.json
@@ -5,6 +5,9 @@
     "en_description" : "A collection of German Wikipedia articles from May 2015.",
     "layers": [
         "opennlp/p",
-        "corenlp/p"
+        "corenlp/p",
+        "corenlp/c",
+        "marmot/m",
+        "marmot/p"
     ]
 }]
\ No newline at end of file
diff --git a/full/src/test/java/de/ids_mannheim/korap/web/controller/FreeResourceControllerTest.java b/full/src/test/java/de/ids_mannheim/korap/web/controller/FreeResourceControllerTest.java
new file mode 100644
index 0000000..7fc5807
--- /dev/null
+++ b/full/src/test/java/de/ids_mannheim/korap/web/controller/FreeResourceControllerTest.java
@@ -0,0 +1,31 @@
+package de.ids_mannheim.korap.web.controller;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.sun.jersey.api.client.ClientResponse;
+
+import de.ids_mannheim.korap.config.SpringJerseyTest;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.utils.JsonUtils;
+
+public class FreeResourceControllerTest extends SpringJerseyTest {
+    
+    @Test
+    public void testResource () throws KustvaktException {
+        ClientResponse response = resource().path(API_VERSION)
+                .path("resource").path("info").get(ClientResponse.class);
+
+        String entity = response.getEntity(String.class);
+        JsonNode n = JsonUtils.readTree(entity).get(0);
+        
+        assertEquals("WPD15",n.at("/resourceId").asText());
+        assertEquals("Deutsche Wikipedia Artikel 2015", n.at("/titles/de").asText());
+        assertEquals("German Wikipedia Articles 2015", n.at("/titles/en").asText());
+        assertEquals(1, n.at("/languages").size());
+        assertEquals(5, n.at("/layers").size());
+    }
+
+}