Changeset 3361


Ignore:
Timestamp:
08/12/13 11:26:15 (11 years ago)
Author:
olhsha
Message:

adding times_tamp and external_Id when geeting annotations. Debugged and tested

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

Legend:

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

    r3334 r3361  
    1818package eu.dasish.annotation.backend;
    1919
     20import java.sql.Timestamp;
     21import java.text.ParseException;
     22import java.text.SimpleDateFormat;
    2023import java.util.Date;
    2124import java.util.GregorianCalendar;
     25import java.util.Locale;
    2226import javax.xml.datatype.DatatypeConfigurationException;
    2327import javax.xml.datatype.DatatypeFactory;
     
    3034public class Helpers {
    3135
    32     public static XMLGregorianCalendar setXMLGregorianCalendar(Date timeStamp) throws DatatypeConfigurationException {
    33         GregorianCalendar c = new GregorianCalendar();
    34         c.setTime(timeStamp);
    35         return DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    36 
     36    public static XMLGregorianCalendar setXMLGregorianCalendar(Timestamp timeStamp) throws DatatypeConfigurationException {
     37            GregorianCalendar gc = new GregorianCalendar();
     38            gc.setTime(timeStamp);
     39            return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
    3740    }
    3841}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3348 r3361  
    4141import javax.sql.DataSource;
    4242import javax.xml.datatype.DatatypeConfigurationException;
    43 import javax.xml.datatype.XMLGregorianCalendar;
    4443import org.springframework.beans.factory.annotation.Autowired;
    4544import org.springframework.dao.DataAccessException;
     
    154153        public Annotation mapRow(ResultSet rs, int rowNumber) throws SQLException {
    155154            Annotation result = new Annotation();
    156             result.setHeadline(rs.getString(headline));
    157155
    158156            ResourceREF ownerREF = new ResourceREF();
     
    160158            result.setOwner(ownerREF);
    161159
     160            result.setHeadline(rs.getString(headline));
     161
     162            result.setBody(convertToAnnotationBody(rs.getString(body_xml)));
     163
    162164            List<SourceInfo> sourceInfoList = jdbcSourceDao.getSourceInfos(rs.getInt(annotation_id));
    163165            NewOrExistingSourceInfos noeSourceInfos = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList);
    164166            result.setTargetSources(noeSourceInfos);
    165167
    166             result.setBody(convertToAnnotationBody(rs.getString(body_xml)));
    167             return result;
     168            // TODO: fix: rpelace URI in the schema with external id, or make here the conversion:
     169            // from external ID in the DB to the URI for the class
     170            result.setURI(rs.getString(external_id));
     171
     172            try {
     173                result.setTimeStamp(Helpers.setXMLGregorianCalendar(rs.getTimestamp(time_stamp)));
     174                return result;
     175            } catch (DatatypeConfigurationException e) {
     176                System.out.println(e);
     177                return result; // no date-time is set
     178            }
    168179        }
    169180    };
    170181
    171     // TODO: fill in the stub, when the annotation body is elaborated
    172182    private AnnotationBody convertToAnnotationBody(String input) {
    173183        if (input == null) {
     
    231241            String sql = "INSERT INTO " + annotationTableName + "(" + external_id + "," + owner_id + "," + headline + "," + body_xml + " ) VALUES (:externalId, :ownerId, :headline, :bodyXml)";
    232242            final int affectedRows = getSimpleJdbcTemplate().update(sql, params);
    233            
     243
    234244            if (affectedRows != 1) {
    235245                throw (new SQLException("Cannot add the annotation properly"));
     
    258268            if (affectedRows != 1) {
    259269                throw (new SQLException("Cannot update the body with persistent reference ID"));
    260             } 
     270            }
    261271
    262272            return result;
     
    285295    }
    286296
    287    
    288 
    289297    ///////////////////////////////////////////////////////////
    290298    private ResourceREF getResourceREF(String resourceID) {
     
    302310
    303311        Annotation result = new Annotation();
    304        
    305        
     312
    306313        AnnotationBody body = new AnnotationBody();
    307314        String bodyString = annotation.getBody().getAny().get(0).toString();
    308315        body.getAny().add(bodyString);
    309316        result.setBody(body);
    310        
     317
    311318        result.setHeadline(annotation.getHeadline());
    312        
     319
    313320        ResourceREF owner = new ResourceREF();
    314321        owner.setRef(annotation.getOwner().getRef());
    315322        result.setOwner(owner);
    316        
     323
    317324//        ResourceREF permissions = new ResourceREF();
    318325//        permissions.setRef(annotation.getPermissions().getRef());
    319326//        result.setPermissions(permissions);
    320        
     327
    321328        result.setPermissions(null); //we do not have permissions there
    322        
     329
    323330        NewOrExistingSourceInfos noesi = new NewOrExistingSourceInfos();
    324         noesi.getTarget().addAll(annotation.getTargetSources().getTarget());       
     331        noesi.getTarget().addAll(annotation.getTargetSources().getTarget());
    325332        result.setTargetSources(noesi);
    326        
     333
    327334        result.setTimeStamp(annotation.getTimeStamp());
    328335        result.setURI(annotation.getURI());
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java

    r3348 r3361  
    173173        public XMLGregorianCalendar mapRow(ResultSet rs, int rowNumber) throws SQLException {
    174174            try {
    175                 XMLGregorianCalendar result = Helpers.setXMLGregorianCalendar(rs.getDate(time_stamp));
     175                XMLGregorianCalendar result = Helpers.setXMLGregorianCalendar(rs.getTimestamp(time_stamp));
    176176                return result;
    177177            } catch (DatatypeConfigurationException e) {
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java

    r3348 r3361  
    9393        public Source mapRow(ResultSet rs, int rowNumber) throws SQLException {
    9494            try {
    95                 XMLGregorianCalendar xmlDate = Helpers.setXMLGregorianCalendar(rs.getDate(time_stamp));
     95                XMLGregorianCalendar xmlDate = Helpers.setXMLGregorianCalendar(rs.getTimestamp(time_stamp));
    9696                Source result = constructSource(new SourceIdentifier(rs.getString(external_id)), rs.getString(link_uri),
    9797                        versionDao.getExternalID(rs.getInt(version_id)), xmlDate);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java

    r3334 r3361  
    5959    public static final String _TEST_ANNOT_TO_ADD_BODY = "<html><body>the stuff to be added</body></html>";
    6060   
     61    public static final String _TEST_ANNOT_2_TIME_STAMP = "2013-08-12T11:25:00.383+02:00";
     62   
    6163    public static final String annotaiontoDeleteInDB="INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (25, 111, 'Annotation to delete','<html><body>some html 4</body></html>', '00000000-0000-0000-0000-000000000025');";
    6264   
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3347 r3361  
    1818package eu.dasish.annotation.backend.dao.impl;
    1919
     20import eu.dasish.annotation.backend.Helpers;
    2021import eu.dasish.annotation.backend.TestBackendConstants;
    2122import eu.dasish.annotation.backend.TestInstances;
     
    2829import eu.dasish.annotation.schema.AnnotationInfo;
    2930import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
    30 import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
    3131import eu.dasish.annotation.schema.NewOrExistingSourceInfos;
    3232import eu.dasish.annotation.schema.NewSourceInfo;
    3333import eu.dasish.annotation.schema.ResourceREF;
    34 import eu.dasish.annotation.schema.Source;
    3534import eu.dasish.annotation.schema.SourceInfo;
    3635import java.sql.SQLException;
     
    3938import java.util.List;
    4039import java.util.Map;
     40import javax.xml.datatype.DatatypeConfigurationException;
    4141import org.jmock.Expectations;
    4242import org.jmock.Mockery;
    4343import static org.junit.Assert.*;
    44 import org.junit.Ignore;
    4544import org.junit.Test;
    4645import org.junit.runner.RunWith;
     
    5453 */
    5554@RunWith(SpringJUnit4ClassRunner.class)
    56 @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockNotebookDao.xml", 
    57     "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockSourceDao.xml","/spring-config/annotationDao.xml"})
    58 public class JdbcAnnotationDaoTest extends JdbcResourceDaoTest{
    59    
    60     @Autowired
    61     JdbcAnnotationDao jdbcAnnotationDao;
    62    
     55@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockNotebookDao.xml",
     56    "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockSourceDao.xml", "/spring-config/annotationDao.xml"})
     57public class JdbcAnnotationDaoTest extends JdbcResourceDaoTest {
     58
     59    @Autowired
     60    JdbcAnnotationDao jdbcAnnotationDao;
    6361    @Autowired
    6462    private PermissionsDao permissionsDao;
    65    
    6663    @Autowired
    6764    private NotebookDao notebookDao;
    68    
    6965    @Autowired
    7066    private SourceDao sourceDao;
    71    
    7267    @Autowired
    7368    private Mockery mockery;
    74    
    7569    TestInstances testInstances = new TestInstances();
    76    
    77    
    78  
    7970
    8071    /**
     
    8273     * List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs)
    8374     */
    84     @Test 
     75    @Test
    8576    public void testGetAnnotationInfos() {
    8677        System.out.println("getAnnotationInfos");
    87         List<Number> annotIds = new ArrayList<Number>(); 
     78        List<Number> annotIds = new ArrayList<Number>();
    8879        annotIds.add(2);
    8980        annotIds.add(3);
    9081        annotIds.add(4);
    91        
     82
    9283        final List<AnnotationInfo> annotationInfos = jdbcAnnotationDao.getAnnotationInfos(annotIds);
    9384        assertEquals(3, annotationInfos.size());
    94        
     85
    9586        assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotationInfos.get(0).getHeadline());
    9687        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_OWNER), annotationInfos.get(0).getOwner().getRef());
    9788        //assertEquals(TestBackendConstants._TEST_ANNOT_1_TARGETS, annotationInfos.get(0).getTargetSources());
    98        
     89
    9990        assertEquals(TestBackendConstants._TEST_ANNOT_3_HEADLINE, annotationInfos.get(1).getHeadline());
    10091        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_OWNER), annotationInfos.get(1).getOwner().getRef());
    10192        //assertEquals(TestBackendConstants._TEST_ANNOT_2_TARGETS, annotationInfos.get(1).getTargetSources());
    102        
     93
    10394        assertEquals(TestBackendConstants._TEST_ANNOT_4_HEADLINE, annotationInfos.get(2).getHeadline());
    10495        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_4_OWNER), annotationInfos.get(2).getOwner().getRef());
    10596        //assertEquals(TestBackendConstants._TEST_ANNOT_3_TARGETS, annotationInfos.get(2).getTargetSources());
    106        
     97
    10798        final List<AnnotationInfo> annotationInfosNull = jdbcAnnotationDao.getAnnotationInfos(null);
    10899        assertEquals(null, annotationInfosNull);
    109        
     100
    110101        final List<AnnotationInfo> annotationInfosZeroSize = jdbcAnnotationDao.getAnnotationInfos(new ArrayList<Number>());
    111102        assertEquals(0, annotationInfosZeroSize.size());
    112        
    113        
    114     }
    115 
    116    
     103
     104
     105    }
     106
    117107    /**
    118108     * Test of getAnnotationREFs method, of class JdbcAnnotationDao.
    119109     * List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs)
    120110     */
    121     @Test 
     111    @Test
    122112    public void testGetAnnotationREFs() {
    123113        System.out.println("getAnnotationREFs");
    124         List<Number> annotIds = new ArrayList<Number>(); 
     114        List<Number> annotIds = new ArrayList<Number>();
    125115        annotIds.add(2);
    126116        annotIds.add(3);
    127117        annotIds.add(4);
    128        
    129         final  List<ResourceREF> testList = jdbcAnnotationDao.getAnnotationREFs(annotIds);
    130         assertEquals(3, testList.size());       
     118
     119        final List<ResourceREF> testList = jdbcAnnotationDao.getAnnotationREFs(annotIds);
     120        assertEquals(3, testList.size());
    131121        assertEquals(String.valueOf(2), testList.get(0).getRef());
    132122        assertEquals(String.valueOf(3), testList.get(1).getRef());
    133123        assertEquals(String.valueOf(4), testList.get(2).getRef());
    134        
    135         final  List<ResourceREF> testListTwo = jdbcAnnotationDao.getAnnotationREFs(new ArrayList<Number>());
     124
     125        final List<ResourceREF> testListTwo = jdbcAnnotationDao.getAnnotationREFs(new ArrayList<Number>());
    136126        assertEquals(0, testListTwo.size());
    137        
     127
    138128        final List<ResourceREF> testListThree = jdbcAnnotationDao.getAnnotationREFs(null);
    139129        assertEquals(null, testListThree);
    140        
    141     }
    142     /**
    143      *
    144      * Test of getAnnotationID method, of class JdbcAnnotationDao.
    145      * Integer getAnnotationID(AnnotationIdentifier externalID)
    146      */
    147     @Test
    148     public void getAnnotationID() throws SQLException{
    149        System.out.println("getAnnotationID");
    150        
    151        final Number annotaionId = jdbcAnnotationDao.getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT));
    152        assertEquals(2, annotaionId.intValue());
    153        
    154        final Number annotaionIdNE = jdbcAnnotationDao.getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_7_EXT_NOT_IN_DB));
    155        assertEquals(null, annotaionIdNE);   
    156      
    157        final Number annotaionIdNull = jdbcAnnotationDao.getInternalID(null);
    158        assertEquals(null, annotaionIdNull);
    159     }
    160    
    161      /**
    162      *
    163      * Test of getAnnotation method, of class JdbcAnnotationDao.
    164      * Annotation getAnnotation(Number annotationlID)
    165      */
    166     @Test
    167     public void getAnnotation() throws SQLException{
    168        System.out.println("getAnnotation");
    169        
    170        final Number testAnnotationID = 2;
    171        
    172        
    173        SourceInfo sourceOneInfo =  new SourceInfo();
    174        sourceOneInfo.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
    175        sourceOneInfo.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
    176        sourceOneInfo.setVersion(Integer.toString(TestBackendConstants._TEST_SOURCE_1_VERSION_ID));
    177        
    178        SourceInfo sourceTwoInfo =  new SourceInfo();
    179        sourceTwoInfo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK);
    180        sourceTwoInfo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID);
    181        sourceTwoInfo.setVersion(Integer.toString(TestBackendConstants._TEST_SOURCE_2_VERSION_ID));
    182        
    183        final List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>();
    184        sourceInfoList.add(sourceOneInfo);
    185        sourceInfoList.add(sourceTwoInfo);
    186        
    187        NewOrExistingSourceInfo noeSourceOneInfo =  new NewOrExistingSourceInfo();
    188        noeSourceOneInfo.setSource(sourceOneInfo);
    189        NewOrExistingSourceInfo noeSourceTwoInfo =  new NewOrExistingSourceInfo();
    190        noeSourceTwoInfo.setSource(sourceTwoInfo);
    191        
    192        List<NewOrExistingSourceInfo> noeSourceInfoList = new ArrayList<NewOrExistingSourceInfo>();
    193        noeSourceInfoList.add(noeSourceOneInfo);
    194        noeSourceInfoList.add(noeSourceTwoInfo);
    195        final NewOrExistingSourceInfos noeSourceInfos= new NewOrExistingSourceInfos();
    196        noeSourceInfos.getTarget().addAll(noeSourceInfoList);
    197        
     130
     131    }
     132
     133    /**
     134     *
     135     * Test of getAnnotationID method, of class JdbcAnnotationDao. Integer
     136     * getAnnotationID(AnnotationIdentifier externalID)
     137     */
     138    @Test
     139    public void getInternalID() throws SQLException {
     140        System.out.println("test getInternalID");
     141
     142        final Number annotaionId = jdbcAnnotationDao.getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT));
     143        assertEquals(2, annotaionId.intValue());
     144
     145        final Number annotaionIdNE = jdbcAnnotationDao.getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_7_EXT_NOT_IN_DB));
     146        assertEquals(null, annotaionIdNE);
     147
     148        final Number annotaionIdNull = jdbcAnnotationDao.getInternalID(null);
     149        assertEquals(null, annotaionIdNull);
     150    }
     151
     152    /**
     153     *
     154     * Test of getAnnotation method, of class JdbcAnnotationDao. Annotation
     155     * getAnnotation(Number annotationlID)
     156     */
     157    @Test
     158    public void getAnnotation() throws SQLException {
     159        System.out.println("test getAnnotation");
     160
     161        /// dummy test
     162        final Annotation annotaionNull = jdbcAnnotationDao.getAnnotation(null);
     163        assertEquals(null, annotaionNull);
     164        ////
     165
     166        final Number testAnnotationID = 2;
     167
     168
     169        SourceInfo sourceOneInfo = new SourceInfo();
     170        sourceOneInfo.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
     171        sourceOneInfo.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
     172        sourceOneInfo.setVersion(Integer.toString(TestBackendConstants._TEST_SOURCE_1_VERSION_ID));
     173
     174        SourceInfo sourceTwoInfo = new SourceInfo();
     175        sourceTwoInfo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK);
     176        sourceTwoInfo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID);
     177        sourceTwoInfo.setVersion(Integer.toString(TestBackendConstants._TEST_SOURCE_2_VERSION_ID));
     178
     179        final List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>();
     180        sourceInfoList.add(sourceOneInfo);
     181        sourceInfoList.add(sourceTwoInfo);
     182
     183        NewOrExistingSourceInfo noeSourceOneInfo = new NewOrExistingSourceInfo();
     184        noeSourceOneInfo.setSource(sourceOneInfo);
     185        NewOrExistingSourceInfo noeSourceTwoInfo = new NewOrExistingSourceInfo();
     186        noeSourceTwoInfo.setSource(sourceTwoInfo);
     187
     188        List<NewOrExistingSourceInfo> noeSourceInfoList = new ArrayList<NewOrExistingSourceInfo>();
     189        noeSourceInfoList.add(noeSourceOneInfo);
     190        noeSourceInfoList.add(noeSourceTwoInfo);
     191        final NewOrExistingSourceInfos noeSourceInfos = new NewOrExistingSourceInfos();
     192        noeSourceInfos.getTarget().addAll(noeSourceInfoList);
     193
    198194        mockery.checking(new Expectations() {
    199             { 
    200                 oneOf(sourceDao).getSourceInfos(testAnnotationID );
     195            {
     196                oneOf(sourceDao).getSourceInfos(testAnnotationID);
    201197                will(returnValue(sourceInfoList));
    202                
     198
    203199                oneOf(sourceDao).contructNewOrExistingSourceInfo(sourceInfoList);
    204200                will(returnValue(noeSourceInfos));
    205201            }
    206202        });
    207        
    208        
    209        final Annotation annotation = jdbcAnnotationDao.getAnnotation(testAnnotationID.intValue());
    210        assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotation.getHeadline());
    211        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_OWNER), annotation.getOwner().getRef());
    212        assertEquals(TestBackendConstants._TEST_ANNOT_2_BODY, annotation.getBody().getAny().get(0)); // when the body is elaborated it will be changed
    213        
    214        assertEquals(sourceOneInfo.getRef(), annotation.getTargetSources().getTarget().get(0).getSource().getRef());
    215        assertEquals(sourceOneInfo.getLink(), annotation.getTargetSources().getTarget().get(0).getSource().getLink());
    216        assertEquals(sourceOneInfo.getVersion(), annotation.getTargetSources().getTarget().get(0).getSource().getVersion());
    217        
    218        assertEquals(sourceTwoInfo.getRef(), annotation.getTargetSources().getTarget().get(1).getSource().getRef());
    219        assertEquals(sourceTwoInfo.getLink(), annotation.getTargetSources().getTarget().get(1).getSource().getLink());
    220        assertEquals(sourceTwoInfo.getVersion(), annotation.getTargetSources().getTarget().get(1).getSource().getVersion());
    221        
    222              
    223        final Annotation annotaionNull = jdbcAnnotationDao.getAnnotation(null);
    224        assertEquals(null, annotaionNull);
    225     }
    226    
     203
     204
     205        final Annotation annotation = jdbcAnnotationDao.getAnnotation(testAnnotationID);
     206        assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotation.getHeadline());
     207        assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_OWNER), annotation.getOwner().getRef());
     208        assertEquals(TestBackendConstants._TEST_ANNOT_2_BODY, annotation.getBody().getAny().get(0)); // when the body is elaborated it may be changed
     209
     210        assertEquals(sourceOneInfo.getRef(), annotation.getTargetSources().getTarget().get(0).getSource().getRef());
     211        assertEquals(sourceOneInfo.getLink(), annotation.getTargetSources().getTarget().get(0).getSource().getLink());
     212        assertEquals(sourceOneInfo.getVersion(), annotation.getTargetSources().getTarget().get(0).getSource().getVersion());
     213
     214        assertEquals(sourceTwoInfo.getRef(), annotation.getTargetSources().getTarget().get(1).getSource().getRef());
     215        assertEquals(sourceTwoInfo.getLink(), annotation.getTargetSources().getTarget().get(1).getSource().getLink());
     216        assertEquals(sourceTwoInfo.getVersion(), annotation.getTargetSources().getTarget().get(1).getSource().getVersion());
     217
     218        assertEquals(TestBackendConstants._TEST_ANNOT_2_EXT, annotation.getURI());
     219
     220        assertEquals(TestBackendConstants._TEST_ANNOT_2_TIME_STAMP, annotation.getTimeStamp().toString());
     221
     222
     223    }
     224
    227225    /**
    228226     * Test of deletAnnotation method, of class JdbcAnnotationDao.
    229227     */
    230228    @Test
    231     public void testDeleteAnnotation() throws SQLException{
    232         System.out.println("deleteAnnotation"); 
    233        
    234          mockery.checking(new Expectations() {
    235             { 
     229    public void testDeleteAnnotation() throws SQLException {
     230        System.out.println("deleteAnnotation");
     231
     232        mockery.checking(new Expectations() {
     233            {
    236234                oneOf(permissionsDao).removeAnnotation(5);
    237235                will(returnValue(1));
    238                
     236
    239237                oneOf(notebookDao).removeAnnotation(5);
    240238                will(returnValue(3));
    241239            }
    242240        });
    243        
     241
    244242        int result = jdbcAnnotationDao.deleteAnnotation(5);
    245243        assertEquals(1, result);
     
    249247        assertEquals(0, result);
    250248    }
    251    
    252    
     249
    253250    /**
    254251     * Test of addAnnotation method, of class JdbcAnnotationDao.
    255252     */
    256253    @Test
    257     public void testAddAnnotationExistingSource() throws SQLException{
     254    public void testAddAnnotationExistingSource() throws SQLException {
    258255        System.out.println("test_addAnnotation with an existing source");
    259        
     256
    260257        Annotation annotationToAdd = testInstances.getAnnotationToAdd();// existing sources
    261258        assertEquals(null, annotationToAdd.getURI());
    262259        assertEquals(null, annotationToAdd.getTimeStamp());
    263        
     260
    264261        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
    265262        SourceInfo si = new SourceInfo();
     
    268265        si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
    269266        noesi.setSource(si);
    270        
     267
    271268        final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>();
    272269        map.put(noesi, noesi);
    273        
    274        
     270
     271
    275272        mockery.checking(new Expectations() {
    276             { 
    277                oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class)));
    278                 will(returnValue(map)); 
     273            {
     274                oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class)));
     275                will(returnValue(map));
    279276            }
    280277        });
    281        
    282         Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5);       
    283         assertFalse(null==result.getURI());
    284         assertFalse(null==result.getTimeStamp());       
     278
     279        Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5);
     280        assertFalse(null == result.getURI());
     281        assertFalse(null == result.getTimeStamp());
    285282        assertEquals(annotationToAdd.getBody().getAny().get(0), result.getBody().getAny().get(0));
    286283        assertEquals(annotationToAdd.getHeadline(), result.getHeadline());
    287284        assertEquals(String.valueOf(5), result.getOwner().getRef());
    288285        assertEquals(annotationToAdd.getPermissions(), result.getPermissions());
    289        
     286
    290287        SourceInfo expectedSi = annotationToAdd.getTargetSources().getTarget().get(0).getSource();
    291288        SourceInfo resultSi = result.getTargetSources().getTarget().get(0).getSource();
    292         assertEquals(expectedSi.getLink(), resultSi.getLink());
    293         assertEquals(expectedSi.getRef(), resultSi.getRef());
    294         assertEquals(expectedSi.getVersion(), resultSi.getVersion());
    295     }
    296    
    297    
    298       /**
     289        assertEquals(expectedSi.getLink(), resultSi.getLink());
     290        assertEquals(expectedSi.getRef(), resultSi.getRef());
     291        assertEquals(expectedSi.getVersion(), resultSi.getVersion());
     292    }
     293
     294    /**
    299295     * Test of addAnnotation method, of class JdbcAnnotationDao.
    300296     */
    301297    @Test
    302     public void testAddAnnotationNewSource() throws SQLException{
     298    public void testAddAnnotationNewSource() throws SQLException {
    303299        System.out.println("test_addAnnotation with a new source");
    304        
    305        
     300
     301
    306302        Annotation annotationToAdd = testInstances.getAnnotationToAddNewSource();// existing sources
    307303        assertEquals(null, annotationToAdd.getURI());
    308304        assertEquals(null, annotationToAdd.getTimeStamp());
    309        
    310        
     305
     306
    311307        NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();
    312308        NewSourceInfo nsi = new NewSourceInfo();
     
    315311        nsi.setVersion(null);
    316312        noesi.setNewSource(nsi);
    317        
    318        
     313
     314
    319315        NewOrExistingSourceInfo noesiTwo = new NewOrExistingSourceInfo();
    320316        SourceInfo si = new SourceInfo();
     
    323319        si.setVersion(null);
    324320        noesiTwo.setSource(si);
    325        
     321
    326322        final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>();
    327323        map.put(noesi, noesiTwo);
    328        
    329        
     324
     325
    330326        mockery.checking(new Expectations() {
    331             { 
    332                oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class)));
    333                 will(returnValue(map)); 
     327            {
     328                oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class)));
     329                will(returnValue(map));
    334330            }
    335331        });
    336        
    337         Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5);       
    338         assertFalse(null==result.getURI());
    339         assertFalse(null==result.getTimeStamp());
     332
     333        Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5);
     334        assertFalse(null == result.getURI());
     335        assertFalse(null == result.getTimeStamp());
    340336        assertEquals(annotationToAdd.getHeadline(), result.getHeadline());
    341337        assertEquals(String.valueOf(5), result.getOwner().getRef());
    342338        assertEquals(annotationToAdd.getPermissions(), result.getPermissions());
    343        
     339
    344340        NewSourceInfo expectedSi = annotationToAdd.getTargetSources().getTarget().get(0).getNewSource();
    345341        SourceInfo resultSi = result.getTargetSources().getTarget().get(0).getSource();
    346         assertEquals(expectedSi.getLink(), resultSi.getLink());       
    347         assertEquals(expectedSi.getVersion(), resultSi.getVersion());   
     342        assertEquals(expectedSi.getLink(), resultSi.getLink());
     343        assertEquals(expectedSi.getVersion(), resultSi.getVersion());
    348344        //the reference is replaced with the persistent one
    349         assertEquals(si.getRef(), resultSi.getRef()); 
     345        assertEquals(si.getRef(), resultSi.getRef());
    350346        ///// 
    351        
     347
    352348        // checking the bodies: the temporary reference should be replaced
    353349        String expBody = annotationToAdd.getBody().getAny().get(0).toString().replaceAll(TestBackendConstants._TEST_TEMP_SOURCE_ID, si.getRef());
    354350        assertEquals(expBody, result.getBody().getAny().get(0).toString());
    355351    }
    356    
    357    
    358     @Test
    359     public void testGetExternalID(){
    360        System.out.println("getAnnotationID");
    361        
    362        final AnnotationIdentifier externalId = jdbcAnnotationDao.getExternalID(2);
    363        assertEquals(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT), externalId);
    364        
    365        
    366        final AnnotationIdentifier externalIdThree = jdbcAnnotationDao.getExternalID(null);
    367        assertEquals(null, externalIdThree.getUUID());
    368        
    369     }
    370    
     352
     353    @Test
     354    public void testGetExternalID() {
     355        System.out.println("getAnnotationID");
     356
     357        final AnnotationIdentifier externalId = jdbcAnnotationDao.getExternalID(2);
     358        assertEquals(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT), externalId);
     359
     360
     361        final AnnotationIdentifier externalIdThree = jdbcAnnotationDao.getExternalID(null);
     362        assertEquals(null, externalIdThree.getUUID());
     363
     364    }
    371365    //////////// helpers //////////////////////
    372    
    373    
    374366}
    375 
    376 
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql

    r3300 r3361  
    4141INSERT INTO notebook (title, owner_id, external_id) VALUES ('Notebook 6', 5, '00000000-0000-0000-0000-000000000014'); --6
    4242
    43 INSERT INTO annotation (owner_id,headline,body_xml, external_id) VALUES (3, 'Sagrada Famiglia','<html><body>some html 1</body></html>', '00000000-0000-0000-0000-000000000021'); --2
     43INSERT INTO annotation (owner_id,headline,body_xml, external_id, time_stamp) VALUES (3, 'Sagrada Famiglia','<html><body>some html 1</body></html>', '00000000-0000-0000-0000-000000000021', '2013-08-12 11:25:00.383+02:00'); --2
    4444INSERT INTO annotation (owner_id,headline,body_xml, external_id) VALUES (4, 'Gaudi','<html><body>some html 2 </body></html>', '00000000-0000-0000-0000-000000000022'); --3
    4545INSERT INTO annotation (owner_id,headline,body_xml, external_id) VALUES (5, 'Art Nuveau','<html><body>some html 3</body></html>', '00000000-0000-0000-0000-000000000023'); --4
Note: See TracChangeset for help on using the changeset viewer.