Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java	(revision 3412)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java	(revision 3413)
@@ -23,5 +23,4 @@
 import eu.dasish.annotation.schema.Permission;
 import eu.dasish.annotation.schema.ResourceREF;
-import eu.dasish.annotation.schema.UserWithPermission;
 import java.sql.SQLException;
 import java.sql.Timestamp;
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java	(revision 3412)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java	(revision 3413)
@@ -25,5 +25,4 @@
 import eu.dasish.annotation.schema.Permission;
 import eu.dasish.annotation.schema.ResourceREF;
-import eu.dasish.annotation.schema.UserWithPermission;
 import java.lang.String;
 import java.sql.ResultSet;
@@ -282,5 +281,5 @@
     public int updateBody(Number annotationID, String serializedNewBody) {
         StringBuilder sql = new StringBuilder("UPDATE ");
-        sql.append(annotationTableName).append(" SET ").append(body_xml).append("= ").append(serializedNewBody).append(" WHERE ").append(annotation_id).append("= ?");
+        sql.append(annotationTableName).append(" SET ").append(body_xml).append("= '").append(serializedNewBody).append("' WHERE ").append(annotation_id).append("= ?");
         return getSimpleJdbcTemplate().update(sql.toString(), annotationID);
     }
@@ -342,5 +341,5 @@
         paramsPermissions.put("principalId", userID);
         paramsPermissions.put("status", permission.value());
-        String sqlUpdatePermissionTable = "INSERT INTO " + permissionsTableName + " (" + annotation_id + "," + principal_id + "," + permission + ") VALUES (:annotationId, :principalId, :status)";
+        String sqlUpdatePermissionTable = "INSERT INTO " + permissionsTableName + " (" + annotation_id + "," + principal_id + "," + this.permission + ") VALUES (:annotationId, :principalId, :status)";
         final int affectedPermissions = getSimpleJdbcTemplate().update(sqlUpdatePermissionTable, paramsPermissions);
         return affectedPermissions;
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java	(revision 3412)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java	(revision 3413)
@@ -82,5 +82,5 @@
             return 0;
         }
-        String sqlSourcesVersions = "DELETE FROM " + sourceTableName + " WHERE " + source_id + " = ? LIMIT 1";
+        String sqlSourcesVersions = "DELETE FROM " + sourceTableName + " WHERE " + source_id + " = ? ";
         int result = getSimpleJdbcTemplate().update(sqlSourcesVersions, internalID);
         return result;
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java	(revision 3412)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java	(revision 3413)
@@ -235,5 +235,5 @@
         assertFalse(null == addedAnnotation.getURI());
         assertFalse(null == addedAnnotation.getTimeStamp());
-        assertEquals(5, addedAnnotation.getOwner().getRef());
+        assertEquals(Integer.toString(5), addedAnnotation.getOwner().getRef());
         assertEquals(annotationToAdd.getBody().getAny().get(0), addedAnnotation.getBody().getAny().get(0)); // TODO: to be changed after serialization is fixed
         assertEquals(annotationToAdd.getHeadline(), addedAnnotation.getHeadline());
@@ -304,5 +304,5 @@
         
        
-        List<Number> result_3 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, null, 1, null, null);        
+        List<Number> result_3 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, null, 3, null, null);        
         assertEquals(1, result_3.size());
         assertEquals(2, result_3.get(0));
@@ -311,12 +311,12 @@
         Timestamp after = new Timestamp(0); 
         Timestamp before = new Timestamp(System.currentTimeMillis());  
-        List<Number> result_4 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, null, 1, after, before);        
+        List<Number> result_4 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, null, 3, after, before);        
         assertEquals(1, result_4.size());
         assertEquals(2, result_4.get(0));
         
         
-        Timestamp after_1 = new Timestamp(System.currentTimeMillis());        
-        List<Number> result_5 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, null, 1, after_1, null);        
-        assertEquals(1, result_5.size());
+        Timestamp after_1 = new Timestamp(System.currentTimeMillis()); // no annotations added after "now"       
+        List<Number> result_5 = jdbcAnnotationDao.getFilteredAnnotationIDs(annotationIDs, "some html", null, null, 3, after_1, null);        
+        assertEquals(0, result_5.size());
         
         
@@ -344,8 +344,8 @@
         System.out.println("test Permissions");
         List<Map<Number, String>> result = jdbcAnnotationDao.retrievePermissions(2);
-        assertEquals(2, result.size());
+        assertEquals(3, result.size());
         assertEquals("owner", result.get(0).get(3));
-        assertEquals("writer", result.get(0).get(4));
-        assertEquals("reader", result.get(0).get(5));
+        assertEquals("writer", result.get(1).get(4));
+        assertEquals("reader", result.get(2).get(5));
         
         
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java	(revision 3412)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java	(revision 3413)
@@ -81,9 +81,9 @@
         System.out.println("getCachedRepresentationInfo");
         
-        CachedRepresentationInfo result = jdbcCachedRepresentationDao.getCachedRepresentationInfo(1);
+        CachedRepresentationInfo result = jdbcCachedRepresentationDao.getCachedRepresentationInfo(1);        
+        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getRef());
         assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_MIME_TYPE_, result.getMimeType());
-        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_, result.getType());
         assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TOOL_, result.getTool());
-        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TYPE_, result.getRef());
+        assertEquals(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_TYPE_, result.getType());
     }
 
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java	(revision 3412)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java	(revision 3413)
@@ -48,6 +48,10 @@
  * @author Peter Withers <peter.withers@mpi.nl>
  */
+// TODO: Move integrating methods from JdbcNotebookDao to DaoDispatcher, and move corresponding tests to DaoDistatcherTest.class,  
+//remove from here all the  mockery and retest.
 @RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml",
+@ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", 
+    "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockUserDao.xml",
+    "/spring-test-config/mockCachedRepresentationDao.xml", "/spring-test-config/mockVersionDao.xml",
     "/spring-test-config/dataSource.xml", "/spring-config/notebookDao.xml"})
 public class JdbcNotebookDaoTest extends JdbcResourceDaoTest{
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java	(revision 3412)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java	(revision 3413)
@@ -20,5 +20,4 @@
 import eu.dasish.annotation.backend.TestBackendConstants;
 import eu.dasish.annotation.backend.identifiers.SourceIdentifier;
-import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
 import eu.dasish.annotation.schema.Source;
 import eu.dasish.annotation.schema.SourceInfo;
@@ -28,5 +27,4 @@
 import org.junit.Test;
 import static org.junit.Assert.*;
-import org.junit.Ignore;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -88,13 +86,11 @@
     public void testDeleteSource() {
         System.out.println("deleteSource");
-        
+        // test 1
         // remove the rows from the joint table to keep integrity
-        jdbcSourceDao.deleteAllSourceVersion(1);
-
-        // test 1
         int result = jdbcSourceDao.deleteSource(1); //the source is in use, should not be deleted
         assertEquals(0, result); 
 
         // test 2
+        jdbcSourceDao.deleteAllSourceVersion(5);
         int resultTwo = jdbcSourceDao.deleteSource(5);// the source will be deleted because it is not referred by any annotation
         assertEquals(1, resultTwo); 
@@ -129,9 +125,8 @@
 
         String link = "http://www.sagradafamilia.cat/";
-        // test 1: existing version
         Source freshSource = new Source();
         freshSource.setLink(link);
         freshSource.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
-        freshSource.setURI(null);
+        freshSource.setURI((new SourceIdentifier()).toString());
         freshSource.setTimeSatmp(null);
         
@@ -141,11 +136,5 @@
         assertEquals(link, addedSource.getLink());
         assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, addedSource.getVersion());
-        assertFalse(null == addedSource.getURI());
-
-        ////////// test 2 non-existing version
-        freshSource.setVersion(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID);
-        Number resultTwo = jdbcSourceDao.addSource(freshSource);
-        assertEquals(-1, resultTwo); // addversion (preferably with cached representation
-
+        assertEquals(freshSource.getURI(), addedSource.getURI());
     }
 
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java	(revision 3412)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java	(revision 3413)
@@ -25,5 +25,4 @@
 import org.junit.Test;
 import static org.junit.Assert.*;
-import org.junit.Ignore;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
Index: /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql
===================================================================
--- /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql	(revision 3412)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql	(revision 3413)
@@ -51,5 +51,5 @@
 INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (3,3);
 INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (4,4);
-INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (5,5);
+INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (5,4);
 
 
