Changeset 3151


Ignore:
Timestamp:
07/17/13 14:12:25 (11 years ago)
Author:
olhsha
Message:

all the methods with notebookId-s as parameters are moved to NotetbookDao?. The affected testing methods are adjusted.

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java

    r3146 r3151  
    3434public interface AnnotationDao extends ResourceDao{
    3535   
    36      // Returns the list of annotation Id-s  for the notebook id.
    37     List<Number> getAnnotationIDs(Number notebookID);
    38    
    39      // Returns the list of annotation info-s  for the notebook id.
     36    // Returns the list of annotation info-s  for the notebook id.
    4037    List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs);   
    4138     
    42      // Returns the list of annotation info-s  for the notebook id.
    43     List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID);   
    44    
     39   
    4540     // Returns the list of annotations Id-s  for the notebook id.
    4641    List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs);   
    4742   
    48      // Returns the list of annotations Id-s  for the notebook id.
    49     List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID);
    50    
    51     // Returns the annotations object for the notebook id.
    52     Annotations getAnnotations(Number notebookID);
    53    
    5443   
    5544}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/NotebookDao.java

    r3146 r3151  
    2121import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    2222import eu.dasish.annotation.backend.identifiers.UserIdentifier;
     23import eu.dasish.annotation.schema.AnnotationInfo;
     24import eu.dasish.annotation.schema.Annotations;
    2325import eu.dasish.annotation.schema.Notebook;
    2426import eu.dasish.annotation.schema.NotebookInfo;
     27import eu.dasish.annotation.schema.ResourceREF;
    2528import java.util.List;
    2629
     
    4750    // Adds an annotation _aid_ to the list of annotations of _nid_.
    4851    public int addAnnotation(NotebookIdentifier notebookId, AnnotationIdentifier annotationId);
     52   
     53     // Returns the list of annotation Id-s  for the notebook id.
     54    List<Number> getAnnotationIDs(Number notebookID);
     55   
     56      /*Returns the list of annotation info-s  for the notebook id.
     57    /List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID); */   
     58   
     59      // Returns the list of annotations Id-s  for the notebook id.
     60    List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID);
     61   
     62    // Returns the Annotations object for the notebook id.
     63    Annotations getAnnotations(Number notebookID);
     64   
     65   
    4966}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3146 r3151  
    4747   
    4848   
    49     ////////////////////////////////////////////////////////////////////////
    50     /**
    51      *
    52      * @param notebookID
    53      * @return the list of annotation-ids belonging to the notebook with notebookId
    54      * returns null if notebookId is null or is not in the DB
    55      * TODO: do we need to return null here? using an additional check.
    56      */
    57      @Override           
    58     public List<Number> getAnnotationIDs(Number notebookID) {
    59         if (notebookID == null) {
    60             return null;
    61         }
    62 
    63         if (isNotebookInTheDataBase(notebookID)) {
    64             String sql = "SELECT notebooks_annotations.annotation_id  FROM notebooks_annotations where notebook_id = ?";
    65             return getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, notebookID.toString());
    66         } else {
    67             return null;
    68         }
    69     }
    70    
    71     private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() {       
    72         @Override
    73         public Integer mapRow(ResultSet rs, int rowNumber) throws SQLException {
    74             Integer annotationId = rs.getInt("annotation_id");
    75             return annotationId;
    76         }
    77     };
    78    
     49   
    7950    ////////////////////////////////////////////////////////////////////////////
    8051
     
    11586   
    11687   
    117     //////////////////////////////////////////////////
    118    
    119     /**
    120      *
    121      * @param notebookID
    122      * @return the list of annotation-infos of the annotations from notebookID;
    123      * if notebook not in the DB or null returns null
    124      * if the notebook contains no annotations returns an empty list
    125      */
    126    
    127     @Override
    128     public List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID) {   
    129         return getAnnotationInfos(getAnnotationIDs(notebookID));
    130     }
    131    
     88   
    13289    /////////////////////////////////////////////////
    13390   
     
    164121    };
    165122   
    166     //////////////////////////////////////////////
    167     /**
    168      *
    169      * @param notebookID
    170      * @return the list of annotation References from the notebookID
    171      * returns null if notebookID == null or it does not exists in the DB
    172      */
     123   
     124     
    173125   
    174     @Override
    175     public List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID) {   
    176         return getAnnotationREFs(getAnnotationIDs(notebookID));
    177     }
    178    
    179    
    180      
    181     ////////////////////////////////////////////////////////////////////////////
    182     /**
    183      *
    184      * @param notebookID
    185      * @return the Annotations (as a list of references) from the notebookID     *
    186      * returns null if notebookID == null, or it does not exists in th DB, or the list of annotations is empty,
    187      * or something wrong happened when extracting annotations from the notebook
    188      * (according to dasish.xsd if an Annotation is created then its list of annotations must contain at least one element!)
    189      *
    190      */
    191 
    192     @Override
    193     public Annotations getAnnotations(Number notebookID) {
    194 
    195         if (notebookID == null) {
    196             return null;
    197         }
    198 
    199         if (isNotebookInTheDataBase(notebookID)) {
    200             Annotations result = new Annotations();
    201             List<ResourceREF> annotREFs = result.getAnnotation();
    202             // TODO: what of annotREFS is null????
    203             boolean test = annotREFs.addAll(getAnnotationREFsOfNotebook(notebookID));
    204             return (test ? result : null);
    205         } else {
    206             return null;
    207         }
    208 
    209     }
    210126   
    211127   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDao.java

    r3146 r3151  
    2323import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    2424import eu.dasish.annotation.backend.identifiers.UserIdentifier;
     25import eu.dasish.annotation.schema.AnnotationInfo;
     26import eu.dasish.annotation.schema.Annotations;
    2527import eu.dasish.annotation.schema.Notebook;
    2628import eu.dasish.annotation.schema.NotebookInfo;
     29import eu.dasish.annotation.schema.ResourceREF;
    2730import java.sql.ResultSet;
    2831import java.sql.SQLException;
     
    110113            }
    111114//            notebook.setURI(rs.getString("URI_ID"));
    112             notebook.setAnnotations(jdbcAnnotationDao.getAnnotations(rs.getInt("notebook_id")));
     115            notebook.setAnnotations(getAnnotations(rs.getInt("notebook_id")));
    113116            return notebook;
    114117        }
     
    138141        }
    139142    }
     143   
     144     ////////////////////////////////////////////////////////////////////////
     145    /**
     146     *
     147     * @param notebookID
     148     * @return the list of annotation-ids belonging to the notebook with notebookId
     149     * returns null if notebookId is null or is not in the DB
     150     * TODO: do we need to return null here? using an additional check.
     151     */
     152     @Override           
     153    public List<Number> getAnnotationIDs(Number notebookID) {
     154        if (notebookID == null) {
     155            return null;
     156        }
     157
     158        if (isNotebookInTheDataBase(notebookID)) {
     159            String sql = "SELECT notebooks_annotations.annotation_id  FROM notebooks_annotations where notebook_id = ?";
     160            return getSimpleJdbcTemplate().query(sql, annotationIDRowMapper, notebookID.toString());
     161        } else {
     162            return null;
     163        }
     164    }
     165   
     166    private final RowMapper<Number> annotationIDRowMapper = new RowMapper<Number>() {       
     167        @Override
     168        public Integer mapRow(ResultSet rs, int rowNumber) throws SQLException {
     169            Integer annotationId = rs.getInt("annotation_id");
     170            return annotationId;
     171        }
     172    };
     173   
     174     //////////////////////////////////////////////////
     175   
     176    /**
     177     *
     178     * @param notebookID
     179     * @return the list of annotation-infos of the annotations from notebookID;
     180     * if notebook not in the DB or null returns null
     181     * if the notebook contains no annotations returns an empty list
     182     *
     183   
     184    @Override
     185    public List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID) {   
     186        return jdbcAnnotationDao.getAnnotationInfos(getAnnotationIDs(notebookID));
     187    }*/
     188   
     189   
     190     //////////////////////////////////////////////
     191    /**
     192     *
     193     * @param notebookID
     194     * @return the list of annotation References from the notebookID
     195     * returns null if notebookID == null or it does not exists in the DB
     196     */
     197   
     198    @Override
     199    public List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID) {   
     200        return jdbcAnnotationDao.getAnnotationREFs(getAnnotationIDs(notebookID));
     201    }
     202   
     203    ////////////////////////////////////////////////////////////////////////////
     204    /**
     205     *
     206     * @param notebookID
     207     * @return the Annotations (as a list of references) from the notebookID     *
     208     * returns null if notebookID == null, or it does not exists in th DB, or the list of annotations is empty,
     209     * or something wrong happened when extracting annotations from the notebook
     210     * (according to dasish.xsd if an Annotation is created then its list of annotations must contain at least one element!)
     211     *
     212     */
     213
     214    @Override
     215    public Annotations getAnnotations(Number notebookID) {
     216
     217        if (notebookID == null) {
     218            return null;
     219        }
     220
     221        if (isNotebookInTheDataBase(notebookID)) {
     222            Annotations result = new Annotations();
     223            List<ResourceREF> annotREFs = result.getAnnotation();
     224            // TODO: what of annotREFS is null????
     225            boolean test = annotREFs.addAll(getAnnotationREFsOfNotebook(notebookID));
     226            return (test ? result : null);
     227        } else {
     228            return null;
     229        }
     230
     231    }
    140232}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3146 r3151  
    2020import eu.dasish.annotation.backend.TestBackendConstants;
    2121import eu.dasish.annotation.schema.AnnotationInfo;
    22 import eu.dasish.annotation.schema.Annotations;
    2322import eu.dasish.annotation.schema.ResourceREF;
    24 import java.io.File;
    25 import java.io.FileNotFoundException;
    26 import java.net.URISyntaxException;
    27 import java.net.URL;
    2823import java.util.ArrayList;
    2924import java.util.List;
    30 import java.util.Scanner;
    31 import org.junit.After;
    3225import static org.junit.Assert.*;
    33 import org.junit.Before;
    34 import org.junit.Ignore;
    3526import org.junit.Test;
    3627import org.junit.runner.RunWith;
    3728import org.springframework.beans.factory.annotation.Autowired;
    38 import org.springframework.dao.DataAccessException;
    39 import org.springframework.jdbc.core.JdbcTemplate;
    4029import org.springframework.test.context.ContextConfiguration;
    4130import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
     
    5847    }
    5948   
    60     /**
    61      * Test of getAnnotationIDs method, of class JdbcAnnotationDao.
    62      * List<Number> getAnnotationIDs(Number notebookID)
    63      */
    64     @Test
    65     public void testGetAnnotationIDs() {
    66         System.out.println("getAnnotationIDs");
    67        
    68         // test one, 2-element notebook
    69         final List<Number> annotationIDs = jdbcAnnotationDao.getAnnotationIDs(TestBackendConstants._TEST_NOTEBOOK_1_INT);
    70         assertEquals(2, annotationIDs.size());
    71         assertEquals(TestBackendConstants._TEST_ANNOT_1_INT, annotationIDs.get(0).intValue());
    72         assertEquals(TestBackendConstants._TEST_ANNOT_2_INT, annotationIDs.get(1).intValue());
    73        
    74         // test two, 1-element notebook
    75         final List<Number> annotationIDsTwo = jdbcAnnotationDao.getAnnotationIDs(TestBackendConstants._TEST_NOTEBOOK_2_INT);
    76         assertEquals(1, annotationIDsTwo.size());
    77         assertEquals(TestBackendConstants._TEST_ANNOT_3_INT, annotationIDsTwo.get(0).intValue());
    78        
    79         // test three, empty notebook
    80         final List<Number> annotationIDsThree = jdbcAnnotationDao.getAnnotationIDs(TestBackendConstants._TEST_NOTEBOOK_3_INT);
    81         assertEquals(0, annotationIDsThree.size());
    82        
    83         // test four, null-notebook
    84         final List<Number> annotationIDsFour = jdbcAnnotationDao.getAnnotationIDs(null);
    85         assertEquals(null, annotationIDsFour);
    86        
    87         //test five, the notebook not in the DB
    88         final List<Number> annotationIDsFive = jdbcAnnotationDao.getAnnotationIDs(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB);
    89         assertEquals(null, annotationIDsFive);
    90        
    91     }
     49 
    9250
    9351    /**
     
    12785    }
    12886
    129     /**
    130      * Test of getAnnotationInfosOfNotebook method, of class JdbcAnnotationDao.
    131      * List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID)
    132      */
    133     @Test
    134     public void testGetAnnotationInfosOfNotebook() {
    135         System.out.println("getAnnotationInfosOfNotebook");
    136        
    137         //test One
    138         final List<AnnotationInfo> annotationInfos = jdbcAnnotationDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_1_INT);
    139         assertEquals(2, annotationInfos.size());
    140        
    141         assertEquals(TestBackendConstants._TEST_ANNOT_1_HEADLINE, annotationInfos.get(0).getHeadline());
    142         assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_OWNER), annotationInfos.get(0).getOwner().getRef());
    143         //assertEquals(TestBackendConstants._TEST_ANNOT_1_TARGETS, annotationInfos.get(0).getTargetSources());
    144        
    145         assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotationInfos.get(1).getHeadline());
    146         assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_OWNER), annotationInfos.get(1).getOwner().getRef());
    147         //assertEquals(TestBackendConstants._TEST_ANNOT_2_TARGETS, annotationInfos.get(1).getTargetSources());
    148        
    149        
    150         //test Two
    151         final List<AnnotationInfo> annotationInfosTwo = jdbcAnnotationDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_2_INT);
    152         assertEquals(1, annotationInfosTwo.size());
    153        
    154         assertEquals(TestBackendConstants._TEST_ANNOT_3_HEADLINE, annotationInfosTwo.get(0).getHeadline());
    155         assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_OWNER), annotationInfosTwo.get(0).getOwner().getRef());
    156         //assertEquals(TestBackendConstants._TEST_ANNOT_3_TARGETS, annotationInfosTwo.get(0).getTargetSources());
    157        
    158         //test notebook with no annotations
    159         final List<AnnotationInfo> annotationInfosThree = jdbcAnnotationDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_3_INT);
    160         assertEquals(0, annotationInfosThree.size());
    161        
    162         //non-existing notebook
    163         final List<AnnotationInfo> annotationInfosFour = jdbcAnnotationDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB);
    164         assertEquals(null, annotationInfosFour);
    165        
    166        
    167         //null notebook
    168         final List<AnnotationInfo> annotationInfosFive = jdbcAnnotationDao.getAnnotationInfosOfNotebook(null);
    169         assertEquals(null, annotationInfosFive);
    170        
    171        
    172     }
    173 
     87   
    17488    /**
    17589     * Test of getAnnotationREFs method, of class JdbcAnnotationDao.
     
    199113    }
    200114
    201     /**
    202      * Test of getAnnotationREFsOfNotebook method, of class JdbcAnnotationDao.
    203      * List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID)
    204      */
    205     @Test
    206     public void testGetAnnotationREFsOfNotebook() {
    207         System.out.println("getAnnotationREFsOfNotebook");
    208        
    209         // test One
    210         List<ResourceREF> testList = jdbcAnnotationDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_NOTEBOOK_1_INT);
    211         assertEquals(2, testList.size());       
    212         assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_INT), testList.get(0).getRef());
    213         assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_INT), testList.get(1).getRef());
    214        
    215         // test One
    216         List<ResourceREF> testListTwo = jdbcAnnotationDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_NOTEBOOK_2_INT);
    217         assertEquals(1, testListTwo.size());       
    218         assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_INT), testListTwo.get(0).getRef());
    219        
    220         // test Three  "empty"
    221         List<ResourceREF> testListThree = jdbcAnnotationDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_NOTEBOOK_3_INT);
    222         assertEquals(0, testListThree.size());
    223        
    224         // test Four, non-existing notebook
    225         List<ResourceREF> testListFour = jdbcAnnotationDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB);
    226         assertEquals(null, testListFour);
    227        
    228         // test Five Null-notebook
    229         List<ResourceREF> testListFive = jdbcAnnotationDao.getAnnotationREFsOfNotebook(null);
    230         assertEquals(null, testListFive);
    231     }
    232 
    233     /**
    234      * Test of getAnnotations method, of class JdbcAnnotationDao.
    235      * Annotations getAnnotations(Number notebookID)
    236      */
    237     @Test     
    238     public void testGetAnnotations() {
    239         System.out.println("getAnnotations");
    240        
    241          // test One
    242         Annotations annotations = jdbcAnnotationDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_1_INT);
    243         assertEquals(2, annotations.getAnnotation().size());       
    244         assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_INT), annotations.getAnnotation().get(0).getRef());
    245         assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_INT), annotations.getAnnotation().get(1).getRef());
    246        
    247         // test One
    248         Annotations annotationsTwo = jdbcAnnotationDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_2_INT);
    249         assertEquals(1, annotationsTwo.getAnnotation().size());       
    250         assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_INT), annotationsTwo.getAnnotation().get(0).getRef());
    251        
    252         // test Three  "empty" list of annotations
    253         // according to dasish.xsd if an Annotation is created then its list of annotations must contain at least one element!
    254         // therefore: no annotations in the notebook ==> Annotations-pbject must be null :(
    255         Annotations annotationsThree = jdbcAnnotationDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_3_INT);
    256         assertEquals(null, annotationsThree);
    257        
    258         // test Five, non-existing notebook
    259         Annotations annotationsFour = jdbcAnnotationDao.getAnnotations(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB);
    260         assertEquals(null, annotationsFour);
    261        
    262         // test Five Null-notebook
    263         Annotations annotationsFive = jdbcAnnotationDao.getAnnotations(null);
    264         assertEquals(null, annotationsFive);
    265     }
     115   
    266116}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java

    r3146 r3151  
    2222import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    2323import eu.dasish.annotation.backend.identifiers.UserIdentifier;
     24import eu.dasish.annotation.schema.AnnotationInfo;
    2425import eu.dasish.annotation.schema.Annotations;
    2526import eu.dasish.annotation.schema.Notebook;
    2627import eu.dasish.annotation.schema.NotebookInfo;
     28import eu.dasish.annotation.schema.ResourceREF;
    2729import java.net.URISyntaxException;
     30import java.util.ArrayList;
     31import java.util.Arrays;
    2832import java.util.Calendar;
    2933import java.util.List;
     
    4549 */
    4650@RunWith(SpringJUnit4ClassRunner.class)
    47 @ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/dataSource.xml", "/spring-config/notebookDao.xml"})
     51@ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml",
     52    "/spring-test-config/dataSource.xml", "/spring-config/notebookDao.xml"})
    4853public class JdbcNotebookDaoTest extends JdbcResourceDaoTest{
    4954
     
    7984        int month = Calendar.getInstance().get(Calendar.MONTH);
    8085        int day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
    81         mockery.checking(new Expectations() {
    82             {
    83                 oneOf(annotationDao).getAnnotations(1);
    84                 will(returnValue(new Annotations()));
    85                 oneOf(annotationDao).getAnnotations(2);
    86                 will(returnValue(new Annotations()));
     86       
     87        ResourceREF testRef = new ResourceREF();
     88        testRef.setRef("1");
     89        final List<ResourceREF> testResult = Arrays.asList(new ResourceREF[] {testRef});
     90       
     91        mockery.checking(new Expectations() {
     92            {
     93                exactly(2).of(annotationDao).getAnnotationREFs(Arrays.asList(new Number[] {1}));// exactly 2 notebooks (their id-s 1 and 2) contains the annotation 1
     94                will(returnValue(testResult));
    8795            }
    8896        });
     97       
    8998        final List<Notebook> notebooks = jdbcNotebookDao.getUsersNotebooks(new UserIdentifier(TestBackendConstants._TEST_UID_2_));
    9099
     
    97106        assertEquals(month + 1, notebooks.get(0).getTimeStamp().getMonth());
    98107        assertEquals(day, notebooks.get(0).getTimeStamp().getDay());
    99         mockery.checking(new Expectations() {
    100             {
    101                 oneOf(annotationDao).getAnnotations(0);
    102                 will(returnValue(new Annotations()));
     108       
     109       
     110        mockery.checking(new Expectations() {
     111            {
     112                oneOf(annotationDao).getAnnotationREFs(new ArrayList<Number>());
     113                will(returnValue(new ArrayList<ResourceREF>()));
    103114            }
    104115        });
     116       
    105117        final List<Notebook> notebooksEmpty = jdbcNotebookDao.getUsersNotebooks(new UserIdentifier(TestBackendConstants._TEST_UID_1_));
    106118        assertEquals(0, notebooksEmpty.size());
     
    126138        assertEquals(1, result);
    127139    }
     140   
     141      /**
     142     * Test of getAnnotationIDs method, of class JdbcAnnotationDao.
     143     * List<Number> getAnnotationIDs(Number notebookID)
     144     */
     145    @Test
     146    public void testGetAnnotationIDs() {
     147        System.out.println("getAnnotationIDs");
     148       
     149        // test one, 2-element notebook
     150        final List<Number> annotationIDs = jdbcNotebookDao.getAnnotationIDs(TestBackendConstants._TEST_NOTEBOOK_1_INT);
     151        assertEquals(2, annotationIDs.size());
     152        assertEquals(TestBackendConstants._TEST_ANNOT_1_INT, annotationIDs.get(0).intValue());
     153        assertEquals(TestBackendConstants._TEST_ANNOT_2_INT, annotationIDs.get(1).intValue());
     154       
     155        // test two, 1-element notebook
     156        final List<Number> annotationIDsTwo = jdbcNotebookDao.getAnnotationIDs(TestBackendConstants._TEST_NOTEBOOK_2_INT);
     157        assertEquals(1, annotationIDsTwo.size());
     158        assertEquals(TestBackendConstants._TEST_ANNOT_3_INT, annotationIDsTwo.get(0).intValue());
     159       
     160        // test three, empty notebook
     161        final List<Number> annotationIDsThree = jdbcNotebookDao.getAnnotationIDs(TestBackendConstants._TEST_NOTEBOOK_3_INT);
     162        assertEquals(0, annotationIDsThree.size());
     163       
     164        // test four, null-notebook
     165        final List<Number> annotationIDsFour = jdbcNotebookDao.getAnnotationIDs(null);
     166        assertEquals(null, annotationIDsFour);
     167       
     168        //test five, the notebook not in the DB
     169        final List<Number> annotationIDsFive = jdbcNotebookDao.getAnnotationIDs(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB);
     170        assertEquals(null, annotationIDsFive);
     171       
     172    }
     173   
     174    /**
     175     * Test of getAnnotationInfosOfNotebook method, of class JdbcAnnotationDao.
     176     * List<AnnotationInfo> getAnnotationInfosOfNotebook(Number notebookID)
     177     
     178    @Test
     179    public void testGetAnnotationInfosOfNotebook() {
     180        System.out.println("getAnnotationInfosOfNotebook");       
     181       
     182        mockery.checking(new Expectations() {
     183            {
     184                exactly(2).of(annotationDao).getAnnotationInfos(Arrays.asList(new Number[] {21, 22}));// exactly 2 notebooks (their id-s 1 and 2) contains the annotation 1
     185                will(returnValue(testResult));
     186            }
     187        });
     188       
     189        //test One
     190        final List<AnnotationInfo> annotationInfos = jdbcNotebookDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_1_INT);
     191        assertEquals(2, annotationInfos.size());
     192       
     193        assertEquals(TestBackendConstants._TEST_ANNOT_1_HEADLINE, annotationInfos.get(0).getHeadline());
     194        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_OWNER), annotationInfos.get(0).getOwner().getRef());
     195        //assertEquals(TestBackendConstants._TEST_ANNOT_1_TARGETS, annotationInfos.get(0).getTargetSources());
     196       
     197        assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotationInfos.get(1).getHeadline());
     198        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_OWNER), annotationInfos.get(1).getOwner().getRef());
     199        //assertEquals(TestBackendConstants._TEST_ANNOT_2_TARGETS, annotationInfos.get(1).getTargetSources());
     200       
     201       
     202        //test Two
     203        final List<AnnotationInfo> annotationInfosTwo = jdbcNotebookDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_2_INT);
     204        assertEquals(1, annotationInfosTwo.size());
     205       
     206        assertEquals(TestBackendConstants._TEST_ANNOT_3_HEADLINE, annotationInfosTwo.get(0).getHeadline());
     207        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_OWNER), annotationInfosTwo.get(0).getOwner().getRef());
     208        //assertEquals(TestBackendConstants._TEST_ANNOT_3_TARGETS, annotationInfosTwo.get(0).getTargetSources());
     209       
     210        //test notebook with no annotations
     211        final List<AnnotationInfo> annotationInfosThree = jdbcNotebookDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_NOTEBOOK_3_INT);
     212        assertEquals(0, annotationInfosThree.size());
     213       
     214        //non-existing notebook
     215        final List<AnnotationInfo> annotationInfosFour = jdbcNotebookDao.getAnnotationInfosOfNotebook(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB);
     216        assertEquals(null, annotationInfosFour);
     217       
     218       
     219        //null notebook
     220        final List<AnnotationInfo> annotationInfosFive = jdbcNotebookDao.getAnnotationInfosOfNotebook(null);
     221        assertEquals(null, annotationInfosFive);       
     222       
     223    }
     224    * */
     225   
     226    /**
     227     * Test of getAnnotationREFsOfNotebook method, of class JdbcAnnotationDao.
     228     * List<ResourceREF> getAnnotationREFsOfNotebook(Number notebookID)
     229     */
     230    @Test
     231    public void testGetAnnotationREFsOfNotebook() {
     232        System.out.println("getAnnotationREFsOfNotebook");
     233       
     234        // test One         
     235        setMockeryNotebookOne();         
     236        List<ResourceREF> testList = jdbcNotebookDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_NOTEBOOK_1_INT);
     237        assertEquals(2, testList.size());       
     238        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_INT), testList.get(0).getRef());
     239        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_INT), testList.get(1).getRef());
     240       
     241        // test Two
     242        setMockeryNotebookTwo();
     243        List<ResourceREF> testListTwo = jdbcNotebookDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_NOTEBOOK_2_INT);
     244        assertEquals(1, testListTwo.size());       
     245        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_INT), testListTwo.get(0).getRef());
     246       
     247        // test Three  "empty"
     248        setMockeryNotebookThreeEmpty();         
     249        List<ResourceREF> testListThree = jdbcNotebookDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_NOTEBOOK_3_INT);
     250        assertEquals(0, testListThree.size());
     251       
     252        // test Four, non-existing notebook
     253        setMockeryNotebookNonExisting();
     254        List<ResourceREF> testListFour = jdbcNotebookDao.getAnnotationREFsOfNotebook(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB);
     255        assertEquals(null, testListFour);
     256       
     257        // test Five Null-notebook
     258        setMockeryNotebookNonExisting();
     259        List<ResourceREF> testListFive = jdbcNotebookDao.getAnnotationREFsOfNotebook(null);
     260        assertEquals(null, testListFive);
     261    }
     262
     263    /**
     264     * Test of getAnnotations method, of class JdbcAnnotationDao.
     265     * Annotations getAnnotations(Number notebookID)
     266     */
     267    @Test     
     268    public void testGetAnnotations() {
     269        System.out.println("getAnnotations");
     270       
     271         // test One
     272        setMockeryNotebookOne();
     273        Annotations annotations = jdbcNotebookDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_1_INT);
     274        assertEquals(2, annotations.getAnnotation().size());       
     275        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_1_INT), annotations.getAnnotation().get(0).getRef());
     276        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_INT), annotations.getAnnotation().get(1).getRef());
     277       
     278        // test Two
     279        setMockeryNotebookTwo();
     280        Annotations annotationsTwo = jdbcNotebookDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_2_INT);
     281        assertEquals(1, annotationsTwo.getAnnotation().size());       
     282        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_INT), annotationsTwo.getAnnotation().get(0).getRef());
     283       
     284        // test Three  "empty" list of annotations
     285        // according to dasish.xsd if an Annotation is created then its list of annotations must contain at least one element!
     286        // therefore: no annotations in the notebook ==> Annotations-pbject must be null :(
     287        setMockeryNotebookThreeEmpty();
     288        Annotations annotationsThree = jdbcNotebookDao.getAnnotations(TestBackendConstants._TEST_NOTEBOOK_3_INT);
     289        assertEquals(null, annotationsThree);
     290       
     291        // test Five, non-existing notebook
     292        setMockeryNotebookNonExisting();
     293        Annotations annotationsFour = jdbcNotebookDao.getAnnotations(TestBackendConstants._TEST_ANNOT_4_INT_NOT_IN_THE_DB);
     294        assertEquals(null, annotationsFour);
     295       
     296        // test Five Null-notebook
     297        setMockeryNotebookNonExisting();
     298        Annotations annotationsFive = jdbcNotebookDao.getAnnotations(null);
     299        assertEquals(null, annotationsFive);
     300    }
     301   
     302   
     303    ////////////////////////////////////////////////////////////////////
     304    //////// Setting Mockeries /////////////////////////////////////////
     305    ///////////////////////////////////////////////////////////////////
     306   
     307    private void setMockeryNotebookOne(){       
     308        ResourceREF testRefOne = new ResourceREF();
     309        testRefOne.setRef(String.valueOf(TestBackendConstants._TEST_ANNOT_1_INT));
     310        ResourceREF testRefTwo = new ResourceREF();
     311        testRefTwo.setRef(String.valueOf(TestBackendConstants._TEST_ANNOT_2_INT));
     312        final List<ResourceREF> testResult = Arrays.asList(new ResourceREF[] {testRefOne, testRefTwo});
     313       
     314        mockery.checking(new Expectations() {
     315            {
     316              oneOf(annotationDao).getAnnotationREFs(Arrays.asList(new Number[] {TestBackendConstants._TEST_ANNOT_1_INT, TestBackendConstants._TEST_ANNOT_2_INT}));
     317              will(returnValue(testResult));
     318            }
     319        });   
     320    }
     321
     322     private void setMockeryNotebookTwo(){
     323      ResourceREF testRef = new ResourceREF();
     324        testRef.setRef(String.valueOf(TestBackendConstants._TEST_ANNOT_3_INT));
     325        final List<ResourceREF> testResultTwo = Arrays.asList(new ResourceREF[] {testRef});
     326       
     327        mockery.checking(new Expectations() {
     328            {
     329              oneOf(annotationDao).getAnnotationREFs(Arrays.asList(new Number[] {TestBackendConstants._TEST_ANNOT_3_INT}));
     330              will(returnValue(testResultTwo));
     331            }
     332        });
     333     }   
     334     
     335     private void setMockeryNotebookThreeEmpty(){
     336         mockery.checking(new Expectations() {
     337            {
     338              oneOf(annotationDao).getAnnotationREFs(new ArrayList<Number>());
     339              will(returnValue(new ArrayList<ResourceREF>()));
     340            }
     341        });       
     342     }
     343     
     344     private void setMockeryNotebookNonExisting() {         
     345         mockery.checking(new Expectations() {
     346            {
     347              oneOf(annotationDao).getAnnotationREFs(null);
     348              will(returnValue(null));
     349            }
     350        });
     351     }
     352       
    128353}
Note: See TracChangeset for help on using the changeset viewer.