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 3395)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java	(revision 3396)
@@ -215,6 +215,4 @@
                 will(returnValue(sourceInfoList));
 
-                oneOf(sourceDao).contructNewOrExistingSourceInfo(sourceInfoList);
-                will(returnValue(noeSourceInfos));
             }
         });
@@ -349,5 +347,5 @@
         sources.add(1);
         sources.add(2);
-        List<Number> result = jdbcAnnotationDao.getAnnotationIDsForSources(sources);
+        List<Number> result = jdbcAnnotationDao.retrieveAnnotationList(sources);
         assertEquals (2, result.size());
         assertEquals(2, result.get(0));
@@ -466,4 +464,98 @@
     }
     
-    //////////// helpers //////////////////////
+     /**
+     * Test of contructNewOrExistingSourceInfo method, of class JdbcSourceDao.
+     */
+    @Test
+    public void testContructNewOrExistingSourceInfo() {
+        System.out.println("contructNewOrExistingSourceInfo");
+
+        List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>();
+
+        SourceInfo sourceInfoOne = new SourceInfo();
+        sourceInfoOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
+        sourceInfoOne.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
+        sourceInfoOne.setRef(TestBackendConstants._TEST_VERSION_1_EXT_ID);
+
+        SourceInfo sourceInfoTwo = new SourceInfo();
+        sourceInfoTwo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK);
+        sourceInfoTwo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID);
+        sourceInfoTwo.setRef(TestBackendConstants._TEST_VERSION_3_EXT_ID);
+
+        sourceInfoList.add(sourceInfoOne);
+        sourceInfoList.add(sourceInfoTwo);
+
+//        NewOrExistingSourceInfos result = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList);
+//        assertEquals(2, result.getTarget().size());
+//        assertEquals(sourceInfoOne, result.getTarget().get(0).getSource());
+//        assertEquals(sourceInfoTwo, result.getTarget().get(1).getSource());
+
+    }
+
+//    /**
+//     * Test of addTargetSources method, of class JdbcSourceDao. public
+//     * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>
+//     * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>
+//     * sources)
+//     */
+//    @Test
+//    public void testAddTargetSourcesOnExistingSource() {
+//        System.out.println("addTargetSources : adding the old source");
+//
+//        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
+//        SourceInfo si = new SourceInfo();
+//        si.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
+//        si.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
+//        si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
+//        noesi.setSource(si);
+//
+//        List<NewOrExistingSourceInfo> listnoesi = new ArrayList<NewOrExistingSourceInfo>();
+//        listnoesi.add(noesi);
+//
+//        try {
+//            Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesi);
+//            assertEquals(0, result.size()); // no new peristsent source IDs are produced
+//        } catch (SQLException e) {
+//            System.out.println(e);
+//        }
+//    }
+//
+//    /**
+//     * Test of addTargetSources method, of class JdbcSourceDao. public
+//     * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>
+//     * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>
+//     * sources)
+//     */
+//    @Test
+//    public void testAddTargetSourcesOnNewSource() {
+//        System.out.println("addTargetSources : adding the new source");
+//
+//        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
+//        NewSourceInfo nsi = new NewSourceInfo();
+//        nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
+//        nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);
+//        nsi.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
+//        noesi.setNewSource(nsi);
+//
+//        List<NewOrExistingSourceInfo> listnoesiTwo = new ArrayList<NewOrExistingSourceInfo>();
+//        listnoesiTwo.add(noesi);
+//        
+//        mockery.checking(new Expectations() {
+//            {
+//                oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID));
+//                will(returnValue(1));
+//            }
+//        });
+//
+//        try {
+//            Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo);
+//            assertEquals(1, result.size());// a new identifier must be produced
+//            SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(TestBackendConstants._TEST_TEMP_SOURCE_ID));
+//            assertFalse(null == sourceIdentifier.getUUID()); // check if a proper uuid has been assigned 
+//        } catch (SQLException e) {
+//            System.out.print(e);
+//        }
+//
+//    }
+//    
 }
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 3395)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java	(revision 3396)
@@ -21,6 +21,4 @@
 import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier;
 import eu.dasish.annotation.schema.CachedRepresentationInfo;
-import java.util.ArrayList;
-import java.util.List;
 import org.junit.Test;
 import static org.junit.Assert.*;
@@ -38,5 +36,5 @@
 @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml",
     "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml",
-    "/spring-test-config/mockSourceDao.xml", "/spring-config/cachedRepresentationDao.xml"})
+    "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockVersionDao.xml", "/spring-config/cachedRepresentationDao.xml"})
 public class JdbcCachedRepresentationDaoTest extends JdbcResourceDaoTest{
     
@@ -57,5 +55,4 @@
     @Test  
     public void testGetExternalId() {
-        // INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000051', 'text/html', 'latex', 'text', 'corpus1'); --1
         System.out.println("getExternalId");
         Number internalID = 1;
@@ -64,4 +61,5 @@
         assertEquals(expResult, result);
     }
+    
 
     /**
@@ -73,7 +71,6 @@
         System.out.println("getInternalId");
         CachedRepresentationIdentifier externalID = new CachedRepresentationIdentifier(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_);
-        Number expResult = 1;
         Number result = jdbcCachedRepresentationDao.getInternalID(externalID);
-        assertEquals(expResult, result);
+        assertEquals(1, result.intValue());
     }
 
@@ -84,5 +81,4 @@
     @Test  
     public void testGetCachedRepresentationInfo() {
-        // INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000051', 'text/html', 'latex', 'text', 'corpus1'); --1
         System.out.println("getCachedRepresentationInfo");
         Number internalID = 1;
@@ -101,22 +97,5 @@
     }
 
-    /**
-     * Test of retrieveCachedRepresentationList method, of class JdbcCachedRepresentationDao.
-     *  public List<Number> retrieveCachedRepresentationList(Number versionID);
-     */
-    @Test 
-    public void testRetrieveCachedRepresentationList() {
-        
-        System.out.println("retrieveCachedRepresentationList");
-        Number versionID = 1;
-        
-        List expResult = new ArrayList<Number>();
-        expResult.add(1);
-        expResult.add(5);
-        
-        List result = jdbcCachedRepresentationDao.retrieveCachedRepresentationList(versionID);
-        assertEquals(expResult, result);
-    }
-
+    
     /**
      * Test of deleteCachedRepresentationInfo method, of class JdbcCachedRepresentationDao.
@@ -161,6 +140,39 @@
     
   
-    
-  
-    
+     /**
+     * Test of addVersion method, of class JdbcVersionDao.
+     */
+    @Test
+    public void testAddCachedForVersion() {
+        System.out.println("test addCachedForVersion");
+
+        final CachedRepresentationInfo cached = new CachedRepresentationInfo();
+        cached.setMimeType("text/plain");
+        cached.setTool("vi");
+        cached.setType("text");
+        cached.setRef(null);
+       
+        Number[] result = jdbcCachedRepresentationDao.addCachedForVersion(6, cached);
+        assertEquals(8, result[0].intValue());
+        assertEquals(1, result[1].intValue());
+    }
+
+     /**
+     *
+     */
+    @Test
+    public void tesDeleteCachedForVersion() {
+        System.out.println("test delete CachedRepresentationForVersion");
+        System.out.println("deleteVersion");
+        
+        int[] result = jdbcCachedRepresentationDao.deleteCachedForVersion(6, 5);
+        assertEquals(1, result[0]); //versions-cached
+        assertEquals(0, result[1]);//cached 5 is in use
+        
+        int[] resultTwo = jdbcCachedRepresentationDao.deleteCachedForVersion(6, 4); // no such pair
+        assertEquals(0, resultTwo[0]); 
+        assertEquals(0, resultTwo[1]); 
+
+
+    }
 }
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 3395)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java	(revision 3396)
@@ -22,7 +22,4 @@
 import eu.dasish.annotation.backend.identifiers.SourceIdentifier;
 import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
-import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
-import eu.dasish.annotation.schema.NewOrExistingSourceInfos;
-import eu.dasish.annotation.schema.NewSourceInfo;
 import eu.dasish.annotation.schema.Source;
 import eu.dasish.annotation.schema.SourceInfo;
@@ -30,9 +27,9 @@
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 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;
@@ -81,6 +78,4 @@
     }
 
-  
-
     /**
      * Test of getSource method, of class JdbcSourceDao.
@@ -104,20 +99,5 @@
         assertEquals(TestBackendConstants._TEST_SOURCE_1_LINK, result.getLink());
         assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, result.getVersion());
-        //TODO: time stamp is not check: do not know with what to compare :\
-    }
-
-    /**
-     * Test of deleteSourceVersionRows method, of class JdbcSourceDao.
-     */
-    @Test
-    public void testDeleteSourceVersionRows() {
-        System.out.println("DeleteSourceVersionRows");
-        Number internalID = 4;
-        int result = jdbcSourceDao.deleteSourceVersionRows(internalID);
-        assertEquals(1, result);
-
-        Number internalIDNoExist = 6;
-        int resultTwo = jdbcSourceDao.deleteSourceVersionRows(internalIDNoExist);
-        assertEquals(0, resultTwo);
+        //TODO: time stamp is not checked: do not know with what to compare 
     }
 
@@ -128,25 +108,25 @@
     public void testDeleteSource() {
         System.out.println("deleteSource");
-        
+
         // test 1
-        Number internalID = 1;
-        int result = jdbcSourceDao.deleteSource(internalID);
-        assertEquals(0, result); // the source is in use, should not be deleted
+        int[] result = jdbcSourceDao.deleteSource(1); //the source is in use, should not be deleted
+        assertEquals(0, result[0]); // 
+        assertEquals(0, result[1]);
 
         // test 2
-        final List<Number> versions = new ArrayList<Number>();
-        versions.add(5);
-        mockery.checking(new Expectations() {
-            {
-                oneOf(versionDao).retrieveVersionList(5);
-                will(returnValue(versions));
-
-                oneOf(versionDao).deleteVersion(5);
-                will(returnValue(1)); // no other sources refer to this version # 5
-            }
-        });
-
-        int resultTwo = jdbcSourceDao.deleteSource(5);
-        assertEquals(1, resultTwo); // the source will be deleted because it is not referred by any annotation
+        final int[] versionDeleted = new int[3];
+        versionDeleted[0] = 0; // versions_cahced_representations
+        versionDeleted[1] = 1; // version deleted
+        versionDeleted[2] = 0; // deleted cached representations; version 7 does not have them
+        mockery.checking(new Expectations() {
+            {
+                oneOf(versionDao).deleteVersion(7);
+                will(returnValue(versionDeleted)); // no other sources refer to this version # 5
+            }
+        });
+
+        int[] resultTwo = jdbcSourceDao.deleteSource(5);// the source will be deleted because it is not referred by any annotation
+        assertEquals(1, resultTwo[0]); // row (5,7) in "sorces_versions" is deleted
+        assertEquals(1, resultTwo[1]); //source 5 is deleted from "source" table
     }
 
@@ -155,10 +135,10 @@
      */
     @Test
-    public void testAddSource() {
+    public void testAddSource() throws SQLException {
         System.out.println("addSource");
 
-        String link = "http://www.sagradafamilia.cat/";     
-  
-        // existing version
+        String link = "http://www.sagradafamilia.cat/";
+
+        // test 1: existing version
         Source freshSource = new Source();
         freshSource.setLink(link);
@@ -166,5 +146,5 @@
         freshSource.setURI(null);
         freshSource.setTimeSatmp(null);
-        
+
         mockery.checking(new Expectations() {
             {
@@ -173,19 +153,24 @@
             }
         });
- 
-        try {
-            Number result = jdbcSourceDao.addSource(freshSource);            
-            assertEquals(6, result);
-            Map<String, Object> addedSource = jdbcSourceDao.getRawSource(result);
-            assertEquals(link, addedSource.get("link_uri"));
-            assertEquals(1, addedSource.get("version_id"));
-            assertFalse(null==addedSource.get("external_id"));
-        } catch (SQLException e) {
-            System.out.println(e);
-        }
+
+        Number result = jdbcSourceDao.addSource(freshSource);
+        assertEquals(6, result);
         
-        ////////// test 2 non-existing source
+        mockery.checking(new Expectations() {
+            {
+                oneOf(versionDao).getExternalID(1); // used in getSource
+                will(returnValue(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID)));
+                
+                
+            }
+        });
+        Source addedSource = jdbcSourceDao.getSource(result);
+        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);
-         mockery.checking(new Expectations() {
+        mockery.checking(new Expectations() {
             {
                 oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID));
@@ -193,12 +178,9 @@
             }
         });
- 
-        try {
-            Number result = jdbcSourceDao.addSource(freshSource);            
-            assertEquals(-1, result);
-        } catch (SQLException e) {
-            System.out.println(e);
-        }
-        
+
+
+        Number resultTwo = jdbcSourceDao.addSource(freshSource);
+        assertEquals(-1, resultTwo); // addversion (preferably with cached representation
+
     }
 
@@ -235,112 +217,28 @@
 
     /**
-     * Test of contructNewOrExistingSourceInfo method, of class JdbcSourceDao.
-     */
-    @Test
-    public void testContructNewOrExistingSourceInfo() {
-        System.out.println("contructNewOrExistingSourceInfo");
-
-        List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>();
-
-        SourceInfo sourceInfoOne = new SourceInfo();
-        sourceInfoOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
-        sourceInfoOne.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
-        sourceInfoOne.setRef(TestBackendConstants._TEST_VERSION_1_EXT_ID);
-
-        SourceInfo sourceInfoTwo = new SourceInfo();
-        sourceInfoTwo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK);
-        sourceInfoTwo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID);
-        sourceInfoTwo.setRef(TestBackendConstants._TEST_VERSION_3_EXT_ID);
-
-        sourceInfoList.add(sourceInfoOne);
-        sourceInfoList.add(sourceInfoTwo);
-
-        NewOrExistingSourceInfos result = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList);
-        assertEquals(2, result.getTarget().size());
-        assertEquals(sourceInfoOne, result.getTarget().get(0).getSource());
-        assertEquals(sourceInfoTwo, result.getTarget().get(1).getSource());
-
-    }
-
-    /**
-     * Test of addTargetSources method, of class JdbcSourceDao. public
-     * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>
-     * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>
-     * sources)
-     */
-    @Test
-    public void testAddTargetSourcesOnExistingSource() {
-        System.out.println("addTargetSources : adding the old source");
-
-        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
-        SourceInfo si = new SourceInfo();
-        si.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
-        si.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
-        si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
-        noesi.setSource(si);
-
-        List<NewOrExistingSourceInfo> listnoesi = new ArrayList<NewOrExistingSourceInfo>();
-        listnoesi.add(noesi);
-
-        try {
-            Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesi);
-            assertEquals(0, result.size()); // no new peristsent source IDs are produced
-        } catch (SQLException e) {
-            System.out.println(e);
-        }
-    }
-
-    /**
-     * Test of addTargetSources method, of class JdbcSourceDao. public
-     * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>
-     * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>
-     * sources)
-     */
-    @Test
-    public void testAddTargetSourcesOnNewSource() {
-        System.out.println("addTargetSources : adding the new source");
-
-        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
-        NewSourceInfo nsi = new NewSourceInfo();
-        nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
-        nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);
-        nsi.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
-        noesi.setNewSource(nsi);
-
-        List<NewOrExistingSourceInfo> listnoesiTwo = new ArrayList<NewOrExistingSourceInfo>();
-        listnoesiTwo.add(noesi);
-        
-        mockery.checking(new Expectations() {
-            {
-                oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID));
-                will(returnValue(1));
-            }
-        });
-
-        try {
-            Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo);
-            assertEquals(1, result.size());// a new identifier must be produced
-            SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(TestBackendConstants._TEST_TEMP_SOURCE_ID));
-            assertFalse(null == sourceIdentifier.getUUID()); // check if a proper uuid has been assigned 
-        } catch (SQLException e) {
-            System.out.print(e);
-        }
-
-    }
-    
-    /** 
      * test public List<Number> getSourcesForLink(String link)
-     * 
-     **/
-    @Test
-    public void tesGetSourcesForLink(){
+     *
+     *
+     */
+    @Test
+    public void tesGetSourcesForLink() {
         System.out.println(" test getSourcesForLink");
-        
+
         String substring = "http://nl.wikipedia.org";
-        List<Number> result  = jdbcSourceDao.getSourcesForLink(substring);
+        List<Number> result = jdbcSourceDao.getSourcesForLink(substring);
         assertEquals(2, result.size());
         assertEquals(1, result.get(0));
-        assertEquals(2, result.get(1));                
-    }
-    
+        assertEquals(2, result.get(1));
+    }
+
+    /* Test of retrieveVersionList method, of class JdbcSourceDao.
+     */
+    @Test
+    public void testRetrieveVersionList() {
+        System.out.println("retrieveVersionList");
+        Number sourceID = 1;
+        List<Number> result = jdbcSourceDao.retrieveVersionList(sourceID);
+        assertEquals(1, result.get(0));
+        assertEquals(2, result.get(1));
+    }
 }
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 3395)
+++ /DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java	(revision 3396)
@@ -20,5 +20,7 @@
 import eu.dasish.annotation.backend.TestBackendConstants;
 import eu.dasish.annotation.backend.dao.CachedRepresentationDao;
+import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier;
 import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
+import eu.dasish.annotation.schema.CachedRepresentationInfo;
 import eu.dasish.annotation.schema.Version;
 import java.util.ArrayList;
@@ -28,4 +30,5 @@
 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;
@@ -41,17 +44,13 @@
     "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml",
     "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockCachedRepresentationDao.xml", "/spring-config/versionDao.xml"})
+public class JdbcVersionDaoTest extends JdbcResourceDaoTest {
 
-public class JdbcVersionDaoTest extends JdbcResourceDaoTest{
-    
     @Autowired
     JdbcVersionDao jdbcVersionDao;
-    
     @Autowired
-    private CachedRepresentationDao cachedRepresentationDao;    
-    
+    private CachedRepresentationDao cachedRepresentationDao;
     @Autowired
     private Mockery mockery;
-    
-    
+
     /**
      * Test of getExternalId method, of class JdbcVersionDao.
@@ -91,29 +90,7 @@
 
     /**
-     * Test of retrieveVersionList method, of class JdbcVersionDao.
-     */
-    @Test
-    public void testRetrieveVersionList() {
-        System.out.println("retrieveVersionList");
-        Number sourceID = 1;
-        // INSERT INTO sources_versions (source_id, version_id) VALUES (1, 1);
-        // INSERT INTO sources_versions (source_id, version_id) VALUES (1, 2);
-        List<Number> result = jdbcVersionDao.retrieveVersionList(sourceID);
-        assertEquals(1, result.get(0));
-        assertEquals(2, result.get(1));
-    }
-
-     /**
-     * Test of deleteVersionCachedRepresentationRows method, of class JdbcVersionDao.
-     */
-    @Test
-    public void testDeleteVersionCachedRepresentationRows() {
-        System.out.println("deleteVersion");
-        Number internalID = 6; // there is no sources (in target_source and sources_versions - sibling table) connected to this version in the test table
-        int result = jdbcVersionDao.deleteVersionCachedRepresentationRow(internalID);
-        assertEquals(1, result);
-    }
-    
-    /**
+     *
+     *
+     * /**
      * Test of deleteVersion method, of class JdbcVersionDao.
      */
@@ -121,41 +98,22 @@
     public void testDeleteVersion() {
         System.out.println("deleteVersion");
-        final Number internalID = 6; // there is no sources (in target_source and sources_versions - sibling table) connected to this version in the test table
-        final Number cachedID =5;
-        final List<Number> versions = new ArrayList<Number>();
-        versions.add(cachedID);
-        
-        //jdbcCachedRepresentationDao.retrieveCachedRepresentationList(internalID);
-        //jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(cachedID);
-        
         mockery.checking(new Expectations() {
-            { 
-                oneOf(cachedRepresentationDao).retrieveCachedRepresentationList(internalID);
-                will(returnValue(versions));
-                
-                oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(cachedID);
+            {
+                oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5);
                 will(returnValue(0));
-                
+
             }
         });
-        
-        int result = jdbcVersionDao.deleteVersion(internalID); 
-        assertEquals(1, result);
-        
-        // try to delete one more time
-         mockery.checking(new Expectations() {
-            { 
-                oneOf(cachedRepresentationDao).retrieveCachedRepresentationList(internalID);
-                will(returnValue(new ArrayList<Number>()));
-                
-            }
-        });
-        int resultTwo = jdbcVersionDao.deleteVersion(internalID);
-        assertEquals(0, resultTwo);
-        
-        // the version in use, shoul not be deleted
-        final Number internalIDNotToDelete = 4;          
-        int resultThree = jdbcVersionDao.deleteVersion(internalIDNotToDelete);
-        assertEquals(0, resultThree);
+        int[] result = jdbcVersionDao.deleteVersion(6);
+        assertEquals(1, result[0]); //versions-cached
+        assertEquals(1, result[1]); // version
+        assertEquals(0, result[2]);//cached 5 is in use
+
+
+        int[] resultTwo = jdbcVersionDao.deleteVersion(5); // version is in use by the source 4
+        assertEquals(0, resultTwo[0]);
+        assertEquals(0, resultTwo[1]);
+        assertEquals(0, resultTwo[2]);
+
     }
 
@@ -166,50 +124,33 @@
     public void testAddVersion() {
         System.out.println("addVersion");
-        
-        Version freshVersion = new Version();   
-        
+
+        Version freshVersion = new Version();
+
         Number result = jdbcVersionDao.addVersion(freshVersion);
         assertEquals(8, result);
         Version addedVersion = jdbcVersionDao.getVersion(result);
-        assertFalse(null==addedVersion.getVersion());
-        
+        assertFalse(null == addedVersion.getVersion());
     }
+    
+    
+   
+   
 
-  
     /**
-     * test 
-     * public int deleteCachedRepresentationForSource(Number sourceID, Number cachedRepresentationID)
-     * 
-     **/
-  
-   
+     * Test of retrieveCachedRepresentationList method, of class JdbcVersionDao.
+     * public List<Number> retrieveCachedRepresentationList(Number versionID);
+     */
     @Test
-    public void tesDeleteCachedRepresentationForSource() {
-         System.out.println("test delete CachedRepresentationForSource");
-         
-         /// TEST 1 /////
-          mockery.checking(new Expectations() {
-            { 
-                oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5);
-                will(returnValue(0));
-                
-            }
-         });         
-         int[] result = jdbcVersionDao.deleteCachedRepresentationForSource(1, 5); // source 1 has versions {1,2}, versions 1 and 2 have cached representations {1, 5} and {3} respectively
-         assertEquals(1, result[0]); 
-         assertEquals(0, result[1]); //cahced representation 5 is also connected version 6, therefore cannot be removed
-         
-         
-         // TEST 2 ////////
-          mockery.checking(new Expectations() {
-            { 
-                oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(4);
-                will(returnValue(1));
-                
-            }
-         });      
-         int[] result_2 = jdbcVersionDao.deleteCachedRepresentationForSource(3, 4); //source 1 --> version 4 --> cached 4
-         assertEquals(1, result_2[0]); 
-         assertEquals(1, result_2[1]); 
+    public void testRetrieveCachedRepresentationList() {
+
+        System.out.println("retrieveCachedRepresentationList");
+        Number versionID = 1;
+
+        List expResult = new ArrayList<Number>();
+        expResult.add(1);
+        expResult.add(5);
+
+        List result = jdbcVersionDao.retrieveCachedRepresentationList(versionID);
+        assertEquals(expResult, result);
     }
 }
