Changeset 3396


Ignore:
Timestamp:
08/15/13 17:01:59 (11 years ago)
Author:
olhsha
Message:

refactored DAO-s and creating an annotation in rest. Still 2 failures and 3 errors.

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3380 r3396  
    215215                will(returnValue(sourceInfoList));
    216216
    217                 oneOf(sourceDao).contructNewOrExistingSourceInfo(sourceInfoList);
    218                 will(returnValue(noeSourceInfos));
    219217            }
    220218        });
     
    349347        sources.add(1);
    350348        sources.add(2);
    351         List<Number> result = jdbcAnnotationDao.getAnnotationIDsForSources(sources);
     349        List<Number> result = jdbcAnnotationDao.retrieveAnnotationList(sources);
    352350        assertEquals (2, result.size());
    353351        assertEquals(2, result.get(0));
     
    466464    }
    467465   
    468     //////////// helpers //////////////////////
     466     /**
     467     * Test of contructNewOrExistingSourceInfo method, of class JdbcSourceDao.
     468     */
     469    @Test
     470    public void testContructNewOrExistingSourceInfo() {
     471        System.out.println("contructNewOrExistingSourceInfo");
     472
     473        List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>();
     474
     475        SourceInfo sourceInfoOne = new SourceInfo();
     476        sourceInfoOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
     477        sourceInfoOne.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
     478        sourceInfoOne.setRef(TestBackendConstants._TEST_VERSION_1_EXT_ID);
     479
     480        SourceInfo sourceInfoTwo = new SourceInfo();
     481        sourceInfoTwo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK);
     482        sourceInfoTwo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID);
     483        sourceInfoTwo.setRef(TestBackendConstants._TEST_VERSION_3_EXT_ID);
     484
     485        sourceInfoList.add(sourceInfoOne);
     486        sourceInfoList.add(sourceInfoTwo);
     487
     488//        NewOrExistingSourceInfos result = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList);
     489//        assertEquals(2, result.getTarget().size());
     490//        assertEquals(sourceInfoOne, result.getTarget().get(0).getSource());
     491//        assertEquals(sourceInfoTwo, result.getTarget().get(1).getSource());
     492
     493    }
     494
     495//    /**
     496//     * Test of addTargetSources method, of class JdbcSourceDao. public
     497//     * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>
     498//     * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>
     499//     * sources)
     500//     */
     501//    @Test
     502//    public void testAddTargetSourcesOnExistingSource() {
     503//        System.out.println("addTargetSources : adding the old source");
     504//
     505//        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
     506//        SourceInfo si = new SourceInfo();
     507//        si.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
     508//        si.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
     509//        si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
     510//        noesi.setSource(si);
     511//
     512//        List<NewOrExistingSourceInfo> listnoesi = new ArrayList<NewOrExistingSourceInfo>();
     513//        listnoesi.add(noesi);
     514//
     515//        try {
     516//            Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesi);
     517//            assertEquals(0, result.size()); // no new peristsent source IDs are produced
     518//        } catch (SQLException e) {
     519//            System.out.println(e);
     520//        }
     521//    }
     522//
     523//    /**
     524//     * Test of addTargetSources method, of class JdbcSourceDao. public
     525//     * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>
     526//     * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>
     527//     * sources)
     528//     */
     529//    @Test
     530//    public void testAddTargetSourcesOnNewSource() {
     531//        System.out.println("addTargetSources : adding the new source");
     532//
     533//        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
     534//        NewSourceInfo nsi = new NewSourceInfo();
     535//        nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
     536//        nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);
     537//        nsi.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
     538//        noesi.setNewSource(nsi);
     539//
     540//        List<NewOrExistingSourceInfo> listnoesiTwo = new ArrayList<NewOrExistingSourceInfo>();
     541//        listnoesiTwo.add(noesi);
     542//       
     543//        mockery.checking(new Expectations() {
     544//            {
     545//                oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID));
     546//                will(returnValue(1));
     547//            }
     548//        });
     549//
     550//        try {
     551//            Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo);
     552//            assertEquals(1, result.size());// a new identifier must be produced
     553//            SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(TestBackendConstants._TEST_TEMP_SOURCE_ID));
     554//            assertFalse(null == sourceIdentifier.getUUID()); // check if a proper uuid has been assigned
     555//        } catch (SQLException e) {
     556//            System.out.print(e);
     557//        }
     558//
     559//    }
     560//   
    469561}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java

    r3380 r3396  
    2121import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier;
    2222import eu.dasish.annotation.schema.CachedRepresentationInfo;
    23 import java.util.ArrayList;
    24 import java.util.List;
    2523import org.junit.Test;
    2624import static org.junit.Assert.*;
     
    3836@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml",
    3937    "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml",
    40     "/spring-test-config/mockSourceDao.xml", "/spring-config/cachedRepresentationDao.xml"})
     38    "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockVersionDao.xml", "/spring-config/cachedRepresentationDao.xml"})
    4139public class JdbcCachedRepresentationDaoTest extends JdbcResourceDaoTest{
    4240   
     
    5755    @Test 
    5856    public void testGetExternalId() {
    59         // 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
    6057        System.out.println("getExternalId");
    6158        Number internalID = 1;
     
    6461        assertEquals(expResult, result);
    6562    }
     63   
    6664
    6765    /**
     
    7371        System.out.println("getInternalId");
    7472        CachedRepresentationIdentifier externalID = new CachedRepresentationIdentifier(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_);
    75         Number expResult = 1;
    7673        Number result = jdbcCachedRepresentationDao.getInternalID(externalID);
    77         assertEquals(expResult, result);
     74        assertEquals(1, result.intValue());
    7875    }
    7976
     
    8481    @Test 
    8582    public void testGetCachedRepresentationInfo() {
    86         // 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
    8783        System.out.println("getCachedRepresentationInfo");
    8884        Number internalID = 1;
     
    10197    }
    10298
    103     /**
    104      * Test of retrieveCachedRepresentationList method, of class JdbcCachedRepresentationDao.
    105      *  public List<Number> retrieveCachedRepresentationList(Number versionID);
    106      */
    107     @Test
    108     public void testRetrieveCachedRepresentationList() {
    109        
    110         System.out.println("retrieveCachedRepresentationList");
    111         Number versionID = 1;
    112        
    113         List expResult = new ArrayList<Number>();
    114         expResult.add(1);
    115         expResult.add(5);
    116        
    117         List result = jdbcCachedRepresentationDao.retrieveCachedRepresentationList(versionID);
    118         assertEquals(expResult, result);
    119     }
    120 
     99   
    121100    /**
    122101     * Test of deleteCachedRepresentationInfo method, of class JdbcCachedRepresentationDao.
     
    161140   
    162141 
    163    
    164  
    165    
     142     /**
     143     * Test of addVersion method, of class JdbcVersionDao.
     144     */
     145    @Test
     146    public void testAddCachedForVersion() {
     147        System.out.println("test addCachedForVersion");
     148
     149        final CachedRepresentationInfo cached = new CachedRepresentationInfo();
     150        cached.setMimeType("text/plain");
     151        cached.setTool("vi");
     152        cached.setType("text");
     153        cached.setRef(null);
     154       
     155        Number[] result = jdbcCachedRepresentationDao.addCachedForVersion(6, cached);
     156        assertEquals(8, result[0].intValue());
     157        assertEquals(1, result[1].intValue());
     158    }
     159
     160     /**
     161     *
     162     */
     163    @Test
     164    public void tesDeleteCachedForVersion() {
     165        System.out.println("test delete CachedRepresentationForVersion");
     166        System.out.println("deleteVersion");
     167       
     168        int[] result = jdbcCachedRepresentationDao.deleteCachedForVersion(6, 5);
     169        assertEquals(1, result[0]); //versions-cached
     170        assertEquals(0, result[1]);//cached 5 is in use
     171       
     172        int[] resultTwo = jdbcCachedRepresentationDao.deleteCachedForVersion(6, 4); // no such pair
     173        assertEquals(0, resultTwo[0]);
     174        assertEquals(0, resultTwo[1]);
     175
     176
     177    }
    166178}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java

    r3380 r3396  
    2222import eu.dasish.annotation.backend.identifiers.SourceIdentifier;
    2323import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
    24 import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
    25 import eu.dasish.annotation.schema.NewOrExistingSourceInfos;
    26 import eu.dasish.annotation.schema.NewSourceInfo;
    2724import eu.dasish.annotation.schema.Source;
    2825import eu.dasish.annotation.schema.SourceInfo;
     
    3027import java.util.ArrayList;
    3128import java.util.List;
    32 import java.util.Map;
    3329import org.jmock.Expectations;
    3430import org.jmock.Mockery;
    3531import org.junit.Test;
    3632import static org.junit.Assert.*;
     33import org.junit.Ignore;
    3734import org.junit.runner.RunWith;
    3835import org.springframework.beans.factory.annotation.Autowired;
     
    8178    }
    8279
    83  
    84 
    8580    /**
    8681     * Test of getSource method, of class JdbcSourceDao.
     
    10499        assertEquals(TestBackendConstants._TEST_SOURCE_1_LINK, result.getLink());
    105100        assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, result.getVersion());
    106         //TODO: time stamp is not check: do not know with what to compare :\
    107     }
    108 
    109     /**
    110      * Test of deleteSourceVersionRows method, of class JdbcSourceDao.
    111      */
    112     @Test
    113     public void testDeleteSourceVersionRows() {
    114         System.out.println("DeleteSourceVersionRows");
    115         Number internalID = 4;
    116         int result = jdbcSourceDao.deleteSourceVersionRows(internalID);
    117         assertEquals(1, result);
    118 
    119         Number internalIDNoExist = 6;
    120         int resultTwo = jdbcSourceDao.deleteSourceVersionRows(internalIDNoExist);
    121         assertEquals(0, resultTwo);
     101        //TODO: time stamp is not checked: do not know with what to compare
    122102    }
    123103
     
    128108    public void testDeleteSource() {
    129109        System.out.println("deleteSource");
    130        
     110
    131111        // test 1
    132         Number internalID = 1;
    133         int result = jdbcSourceDao.deleteSource(internalID);
    134         assertEquals(0, result); // the source is in use, should not be deleted
     112        int[] result = jdbcSourceDao.deleteSource(1); //the source is in use, should not be deleted
     113        assertEquals(0, result[0]); //
     114        assertEquals(0, result[1]);
    135115
    136116        // test 2
    137         final List<Number> versions = new ArrayList<Number>();
    138         versions.add(5);
    139         mockery.checking(new Expectations() {
    140             {
    141                 oneOf(versionDao).retrieveVersionList(5);
    142                 will(returnValue(versions));
    143 
    144                 oneOf(versionDao).deleteVersion(5);
    145                 will(returnValue(1)); // no other sources refer to this version # 5
    146             }
    147         });
    148 
    149         int resultTwo = jdbcSourceDao.deleteSource(5);
    150         assertEquals(1, resultTwo); // the source will be deleted because it is not referred by any annotation
     117        final int[] versionDeleted = new int[3];
     118        versionDeleted[0] = 0; // versions_cahced_representations
     119        versionDeleted[1] = 1; // version deleted
     120        versionDeleted[2] = 0; // deleted cached representations; version 7 does not have them
     121        mockery.checking(new Expectations() {
     122            {
     123                oneOf(versionDao).deleteVersion(7);
     124                will(returnValue(versionDeleted)); // no other sources refer to this version # 5
     125            }
     126        });
     127
     128        int[] resultTwo = jdbcSourceDao.deleteSource(5);// the source will be deleted because it is not referred by any annotation
     129        assertEquals(1, resultTwo[0]); // row (5,7) in "sorces_versions" is deleted
     130        assertEquals(1, resultTwo[1]); //source 5 is deleted from "source" table
    151131    }
    152132
     
    155135     */
    156136    @Test
    157     public void testAddSource() {
     137    public void testAddSource() throws SQLException {
    158138        System.out.println("addSource");
    159139
    160         String link = "http://www.sagradafamilia.cat/";     
    161  
    162         // existing version
     140        String link = "http://www.sagradafamilia.cat/";
     141
     142        // test 1: existing version
    163143        Source freshSource = new Source();
    164144        freshSource.setLink(link);
     
    166146        freshSource.setURI(null);
    167147        freshSource.setTimeSatmp(null);
    168        
     148
    169149        mockery.checking(new Expectations() {
    170150            {
     
    173153            }
    174154        });
    175  
    176         try {
    177             Number result = jdbcSourceDao.addSource(freshSource);           
    178             assertEquals(6, result);
    179             Map<String, Object> addedSource = jdbcSourceDao.getRawSource(result);
    180             assertEquals(link, addedSource.get("link_uri"));
    181             assertEquals(1, addedSource.get("version_id"));
    182             assertFalse(null==addedSource.get("external_id"));
    183         } catch (SQLException e) {
    184             System.out.println(e);
    185         }
     155
     156        Number result = jdbcSourceDao.addSource(freshSource);
     157        assertEquals(6, result);
    186158       
    187         ////////// test 2 non-existing source
     159        mockery.checking(new Expectations() {
     160            {
     161                oneOf(versionDao).getExternalID(1); // used in getSource
     162                will(returnValue(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID)));
     163               
     164               
     165            }
     166        });
     167        Source addedSource = jdbcSourceDao.getSource(result);
     168        assertEquals(link, addedSource.getLink());
     169        assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, addedSource.getVersion());
     170        assertFalse(null == addedSource.getURI());
     171
     172        ////////// test 2 non-existing version
    188173        freshSource.setVersion(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID);
    189          mockery.checking(new Expectations() {
     174        mockery.checking(new Expectations() {
    190175            {
    191176                oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID));
     
    193178            }
    194179        });
    195  
    196         try {
    197             Number result = jdbcSourceDao.addSource(freshSource);           
    198             assertEquals(-1, result);
    199         } catch (SQLException e) {
    200             System.out.println(e);
    201         }
    202        
     180
     181
     182        Number resultTwo = jdbcSourceDao.addSource(freshSource);
     183        assertEquals(-1, resultTwo); // addversion (preferably with cached representation
     184
    203185    }
    204186
     
    235217
    236218    /**
    237      * Test of contructNewOrExistingSourceInfo method, of class JdbcSourceDao.
    238      */
    239     @Test
    240     public void testContructNewOrExistingSourceInfo() {
    241         System.out.println("contructNewOrExistingSourceInfo");
    242 
    243         List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>();
    244 
    245         SourceInfo sourceInfoOne = new SourceInfo();
    246         sourceInfoOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
    247         sourceInfoOne.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
    248         sourceInfoOne.setRef(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    249 
    250         SourceInfo sourceInfoTwo = new SourceInfo();
    251         sourceInfoTwo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK);
    252         sourceInfoTwo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID);
    253         sourceInfoTwo.setRef(TestBackendConstants._TEST_VERSION_3_EXT_ID);
    254 
    255         sourceInfoList.add(sourceInfoOne);
    256         sourceInfoList.add(sourceInfoTwo);
    257 
    258         NewOrExistingSourceInfos result = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList);
    259         assertEquals(2, result.getTarget().size());
    260         assertEquals(sourceInfoOne, result.getTarget().get(0).getSource());
    261         assertEquals(sourceInfoTwo, result.getTarget().get(1).getSource());
    262 
    263     }
    264 
    265     /**
    266      * Test of addTargetSources method, of class JdbcSourceDao. public
    267      * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>
    268      * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>
    269      * sources)
    270      */
    271     @Test
    272     public void testAddTargetSourcesOnExistingSource() {
    273         System.out.println("addTargetSources : adding the old source");
    274 
    275         NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
    276         SourceInfo si = new SourceInfo();
    277         si.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
    278         si.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
    279         si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    280         noesi.setSource(si);
    281 
    282         List<NewOrExistingSourceInfo> listnoesi = new ArrayList<NewOrExistingSourceInfo>();
    283         listnoesi.add(noesi);
    284 
    285         try {
    286             Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesi);
    287             assertEquals(0, result.size()); // no new peristsent source IDs are produced
    288         } catch (SQLException e) {
    289             System.out.println(e);
    290         }
    291     }
    292 
    293     /**
    294      * Test of addTargetSources method, of class JdbcSourceDao. public
    295      * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>
    296      * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>
    297      * sources)
    298      */
    299     @Test
    300     public void testAddTargetSourcesOnNewSource() {
    301         System.out.println("addTargetSources : adding the new source");
    302 
    303         NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
    304         NewSourceInfo nsi = new NewSourceInfo();
    305         nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
    306         nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);
    307         nsi.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    308         noesi.setNewSource(nsi);
    309 
    310         List<NewOrExistingSourceInfo> listnoesiTwo = new ArrayList<NewOrExistingSourceInfo>();
    311         listnoesiTwo.add(noesi);
    312        
    313         mockery.checking(new Expectations() {
    314             {
    315                 oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID));
    316                 will(returnValue(1));
    317             }
    318         });
    319 
    320         try {
    321             Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo);
    322             assertEquals(1, result.size());// a new identifier must be produced
    323             SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(TestBackendConstants._TEST_TEMP_SOURCE_ID));
    324             assertFalse(null == sourceIdentifier.getUUID()); // check if a proper uuid has been assigned
    325         } catch (SQLException e) {
    326             System.out.print(e);
    327         }
    328 
    329     }
    330    
    331     /**
    332219     * test public List<Number> getSourcesForLink(String link)
    333      *
    334      **/
    335     @Test
    336     public void tesGetSourcesForLink(){
     220     *
     221     *
     222     */
     223    @Test
     224    public void tesGetSourcesForLink() {
    337225        System.out.println(" test getSourcesForLink");
    338        
     226
    339227        String substring = "http://nl.wikipedia.org";
    340         List<Number> result  = jdbcSourceDao.getSourcesForLink(substring);
     228        List<Number> result = jdbcSourceDao.getSourcesForLink(substring);
    341229        assertEquals(2, result.size());
    342230        assertEquals(1, result.get(0));
    343         assertEquals(2, result.get(1));               
    344     }
    345    
     231        assertEquals(2, result.get(1));
     232    }
     233
     234    /* Test of retrieveVersionList method, of class JdbcSourceDao.
     235     */
     236    @Test
     237    public void testRetrieveVersionList() {
     238        System.out.println("retrieveVersionList");
     239        Number sourceID = 1;
     240        List<Number> result = jdbcSourceDao.retrieveVersionList(sourceID);
     241        assertEquals(1, result.get(0));
     242        assertEquals(2, result.get(1));
     243    }
    346244}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java

    r3380 r3396  
    2020import eu.dasish.annotation.backend.TestBackendConstants;
    2121import eu.dasish.annotation.backend.dao.CachedRepresentationDao;
     22import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier;
    2223import eu.dasish.annotation.backend.identifiers.VersionIdentifier;
     24import eu.dasish.annotation.schema.CachedRepresentationInfo;
    2325import eu.dasish.annotation.schema.Version;
    2426import java.util.ArrayList;
     
    2830import org.junit.Test;
    2931import static org.junit.Assert.*;
     32import org.junit.Ignore;
    3033import org.junit.runner.RunWith;
    3134import org.springframework.beans.factory.annotation.Autowired;
     
    4144    "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml",
    4245    "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockCachedRepresentationDao.xml", "/spring-config/versionDao.xml"})
     46public class JdbcVersionDaoTest extends JdbcResourceDaoTest {
    4347
    44 public class JdbcVersionDaoTest extends JdbcResourceDaoTest{
    45    
    4648    @Autowired
    4749    JdbcVersionDao jdbcVersionDao;
    48    
    4950    @Autowired
    50     private CachedRepresentationDao cachedRepresentationDao;   
    51    
     51    private CachedRepresentationDao cachedRepresentationDao;
    5252    @Autowired
    5353    private Mockery mockery;
    54    
    55    
     54
    5655    /**
    5756     * Test of getExternalId method, of class JdbcVersionDao.
     
    9190
    9291    /**
    93      * Test of retrieveVersionList method, of class JdbcVersionDao.
    94      */
    95     @Test
    96     public void testRetrieveVersionList() {
    97         System.out.println("retrieveVersionList");
    98         Number sourceID = 1;
    99         // INSERT INTO sources_versions (source_id, version_id) VALUES (1, 1);
    100         // INSERT INTO sources_versions (source_id, version_id) VALUES (1, 2);
    101         List<Number> result = jdbcVersionDao.retrieveVersionList(sourceID);
    102         assertEquals(1, result.get(0));
    103         assertEquals(2, result.get(1));
    104     }
    105 
    106      /**
    107      * Test of deleteVersionCachedRepresentationRows method, of class JdbcVersionDao.
    108      */
    109     @Test
    110     public void testDeleteVersionCachedRepresentationRows() {
    111         System.out.println("deleteVersion");
    112         Number internalID = 6; // there is no sources (in target_source and sources_versions - sibling table) connected to this version in the test table
    113         int result = jdbcVersionDao.deleteVersionCachedRepresentationRow(internalID);
    114         assertEquals(1, result);
    115     }
    116    
    117     /**
     92     *
     93     *
     94     * /**
    11895     * Test of deleteVersion method, of class JdbcVersionDao.
    11996     */
     
    12198    public void testDeleteVersion() {
    12299        System.out.println("deleteVersion");
    123         final Number internalID = 6; // there is no sources (in target_source and sources_versions - sibling table) connected to this version in the test table
    124         final Number cachedID =5;
    125         final List<Number> versions = new ArrayList<Number>();
    126         versions.add(cachedID);
    127        
    128         //jdbcCachedRepresentationDao.retrieveCachedRepresentationList(internalID);
    129         //jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(cachedID);
    130        
    131100        mockery.checking(new Expectations() {
    132             {
    133                 oneOf(cachedRepresentationDao).retrieveCachedRepresentationList(internalID);
    134                 will(returnValue(versions));
    135                
    136                 oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(cachedID);
     101            {
     102                oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5);
    137103                will(returnValue(0));
    138                
     104
    139105            }
    140106        });
    141        
    142         int result = jdbcVersionDao.deleteVersion(internalID);
    143         assertEquals(1, result);
    144        
    145         // try to delete one more time
    146          mockery.checking(new Expectations() {
    147             {
    148                 oneOf(cachedRepresentationDao).retrieveCachedRepresentationList(internalID);
    149                 will(returnValue(new ArrayList<Number>()));
    150                
    151             }
    152         });
    153         int resultTwo = jdbcVersionDao.deleteVersion(internalID);
    154         assertEquals(0, resultTwo);
    155        
    156         // the version in use, shoul not be deleted
    157         final Number internalIDNotToDelete = 4;         
    158         int resultThree = jdbcVersionDao.deleteVersion(internalIDNotToDelete);
    159         assertEquals(0, resultThree);
     107        int[] result = jdbcVersionDao.deleteVersion(6);
     108        assertEquals(1, result[0]); //versions-cached
     109        assertEquals(1, result[1]); // version
     110        assertEquals(0, result[2]);//cached 5 is in use
     111
     112
     113        int[] resultTwo = jdbcVersionDao.deleteVersion(5); // version is in use by the source 4
     114        assertEquals(0, resultTwo[0]);
     115        assertEquals(0, resultTwo[1]);
     116        assertEquals(0, resultTwo[2]);
     117
    160118    }
    161119
     
    166124    public void testAddVersion() {
    167125        System.out.println("addVersion");
    168        
    169         Version freshVersion = new Version();   
    170        
     126
     127        Version freshVersion = new Version();
     128
    171129        Number result = jdbcVersionDao.addVersion(freshVersion);
    172130        assertEquals(8, result);
    173131        Version addedVersion = jdbcVersionDao.getVersion(result);
    174         assertFalse(null==addedVersion.getVersion());
    175        
     132        assertFalse(null == addedVersion.getVersion());
    176133    }
     134   
     135   
     136   
     137   
    177138
    178  
    179139    /**
    180      * test
    181      * public int deleteCachedRepresentationForSource(Number sourceID, Number cachedRepresentationID)
    182      *
    183      **/
    184  
    185    
     140     * Test of retrieveCachedRepresentationList method, of class JdbcVersionDao.
     141     * public List<Number> retrieveCachedRepresentationList(Number versionID);
     142     */
    186143    @Test
    187     public void tesDeleteCachedRepresentationForSource() {
    188          System.out.println("test delete CachedRepresentationForSource");
    189          
    190          /// TEST 1 /////
    191           mockery.checking(new Expectations() {
    192             {
    193                 oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5);
    194                 will(returnValue(0));
    195                
    196             }
    197          });         
    198          int[] result = jdbcVersionDao.deleteCachedRepresentationForSource(1, 5); // source 1 has versions {1,2}, versions 1 and 2 have cached representations {1, 5} and {3} respectively
    199          assertEquals(1, result[0]);
    200          assertEquals(0, result[1]); //cahced representation 5 is also connected version 6, therefore cannot be removed
    201          
    202          
    203          // TEST 2 ////////
    204           mockery.checking(new Expectations() {
    205             {
    206                 oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(4);
    207                 will(returnValue(1));
    208                
    209             }
    210          });     
    211          int[] result_2 = jdbcVersionDao.deleteCachedRepresentationForSource(3, 4); //source 1 --> version 4 --> cached 4
    212          assertEquals(1, result_2[0]);
    213          assertEquals(1, result_2[1]);
     144    public void testRetrieveCachedRepresentationList() {
     145
     146        System.out.println("retrieveCachedRepresentationList");
     147        Number versionID = 1;
     148
     149        List expResult = new ArrayList<Number>();
     150        expResult.add(1);
     151        expResult.add(5);
     152
     153        List result = jdbcVersionDao.retrieveCachedRepresentationList(versionID);
     154        assertEquals(expResult, result);
    214155    }
    215156}
Note: See TracChangeset for help on using the changeset viewer.