Fixed ResourceDao and its test.
Change-Id: Ic54953e517bd06835ed91f8b0b1c8378d737dce8
diff --git a/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java b/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
index cf5701b..e0ba3c3 100644
--- a/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
+++ b/src/main/java/de/ids_mannheim/korap/handlers/ResourceDao.java
@@ -1,15 +1,9 @@
package de.ids_mannheim.korap.handlers;
-import de.ids_mannheim.korap.exceptions.KustvaktException;
-import de.ids_mannheim.korap.exceptions.StatusCodes;
-import de.ids_mannheim.korap.exceptions.dbException;
-import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
-import de.ids_mannheim.korap.interfaces.db.ResourceOperationIface;
-import de.ids_mannheim.korap.resources.KustvaktResource;
-import de.ids_mannheim.korap.resources.ResourceFactory;
-import de.ids_mannheim.korap.config.Attributes;
-import de.ids_mannheim.korap.user.User;
-import de.ids_mannheim.korap.utils.SqlBuilder;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
@@ -19,9 +13,16 @@
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
+import de.ids_mannheim.korap.config.Attributes;
+import de.ids_mannheim.korap.exceptions.KustvaktException;
+import de.ids_mannheim.korap.exceptions.StatusCodes;
+import de.ids_mannheim.korap.exceptions.dbException;
+import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
+import de.ids_mannheim.korap.interfaces.db.ResourceOperationIface;
+import de.ids_mannheim.korap.resources.KustvaktResource;
+import de.ids_mannheim.korap.resources.ResourceFactory;
+import de.ids_mannheim.korap.user.User;
+import de.ids_mannheim.korap.utils.SqlBuilder;
/**
* Created by hanl on 7/21/14.
@@ -189,7 +190,7 @@
source.addValue("type",
ResourceFactory.getResourceMapping(resource.getClass()));
source.addValue("created", System.currentTimeMillis());
- source.addValue("data", resource.getData());
+ source.addValue("data", resource.getStringData());
try {
this.jdbcTemplate
diff --git a/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java b/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
index 15bdd4f..25d110b 100644
--- a/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
+++ b/src/test/java/de/ids_mannheim/korap/handlers/ResourceDaoTest.java
@@ -1,5 +1,18 @@
package de.ids_mannheim.korap.handlers;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
import de.ids_mannheim.korap.config.Attributes;
import de.ids_mannheim.korap.config.BeanConfigTest;
import de.ids_mannheim.korap.config.KustvaktClassLoader;
@@ -8,15 +21,6 @@
import de.ids_mannheim.korap.resources.KustvaktResource;
import de.ids_mannheim.korap.resources.VirtualCollection;
import de.ids_mannheim.korap.user.User;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import static org.junit.Assert.*;
-import static org.junit.Assert.assertNotEquals;
/**
* @author hanl
@@ -26,20 +30,28 @@
private static List<Integer> ids = new ArrayList<>();
+// @Autowired
+// private TransactionTemplate txTemplate;
+//
+// @Autowired
+// private ResourceDao<KustvaktResource> resourceDao;
@Override
public void initMethod () {
helper().setupAccount();
- List classes = new ArrayList<>(
+ List<Class<? extends KustvaktResource>> classes = new ArrayList<>(
KustvaktClassLoader.loadSubTypes(KustvaktResource.class));
int size = classes.size();
for (int i = 0; i < size; i++) {
- Class s = (Class) classes.get(i < classes.size() ? i : 0);
+ Class<? extends KustvaktResource> s = classes.get(i < classes.size() ? i : 0);
try {
KustvaktResource r = (KustvaktResource) s.newInstance();
r.setName("resource_" + i);
r.setPersistentID(r.getName());
+ Map<String, Object> map = new HashMap<>();
+ map.put("testVar", "testVal_" + i);
+ r.setFields(map);
int id = helper().setupResource(r);
ids.add(id);
assertNotEquals(0, new ResourceDao<>(helper().getContext()
@@ -55,7 +67,6 @@
}
}
-
@Test
public void testBatchGetResources () throws KustvaktException {
ResourceDao dao = new ResourceDao(helper().getContext()
@@ -68,7 +79,7 @@
@Test
public void testGetResource () throws KustvaktException {
- ResourceDao dao = new ResourceDao(helper().getContext()
+ ResourceDao<?> dao = new ResourceDao<>(helper().getContext()
.getPersistenceClient());
assertEquals("sqlite", helper().getContext().getPersistenceClient()
.getDatabase());
@@ -77,6 +88,7 @@
KustvaktResource res = dao.findbyId(ids.get(0),
User.UserFactory.getDemoUser());
assertNotNull(res);
+ Assert.assertEquals("testVal_0", res.getField("testVar"));
}