source: DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/DaoDispatcherTest.java @ 3455

Last change on this file since 3455 was 3455, checked in by olhsha, 11 years ago

replacing DaishIdentifier?-based classes with simply UUID. tested. Works, excpet that UUID seems not be be serailizable, see e.g. getAllAnnotations in NotebookResource? where I have to use Peter's workoaroun to put UUID in JAXBElement<UUID>

File size: 25.2 KB
Line 
1/*
2 * Copyright (C) 2013 DASISH
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 */
18package eu.dasish.annotation.backend.dao.impl;
19
20import eu.dasish.annotation.backend.Helpers;
21import eu.dasish.annotation.backend.TestBackendConstants;
22import eu.dasish.annotation.backend.TestInstances;
23import eu.dasish.annotation.backend.dao.AnnotationDao;
24import eu.dasish.annotation.backend.dao.CachedRepresentationDao;
25import eu.dasish.annotation.backend.dao.NotebookDao;
26import eu.dasish.annotation.backend.dao.SourceDao;
27import eu.dasish.annotation.backend.dao.UserDao;
28import eu.dasish.annotation.backend.dao.VersionDao;
29import eu.dasish.annotation.schema.Annotation;
30import eu.dasish.annotation.schema.AnnotationBody;
31import eu.dasish.annotation.schema.CachedRepresentationInfo;
32import eu.dasish.annotation.schema.NewOrExistingSourceInfo;
33import eu.dasish.annotation.schema.NewSourceInfo;
34import eu.dasish.annotation.schema.Permission;
35import eu.dasish.annotation.schema.ResourceREF;
36import eu.dasish.annotation.schema.Source;
37import eu.dasish.annotation.schema.SourceInfo;
38import eu.dasish.annotation.schema.Version;
39import java.sql.SQLException;
40import java.sql.Timestamp;
41import java.util.ArrayList;
42import java.util.List;
43import java.util.Map;
44import java.util.UUID;
45import javax.xml.datatype.XMLGregorianCalendar;
46import org.jmock.Expectations;
47import org.jmock.Mockery;
48import org.junit.Test;
49import static org.junit.Assert.*;
50import org.junit.runner.RunWith;
51import org.springframework.beans.factory.annotation.Autowired;
52import org.springframework.test.context.ContextConfiguration;
53import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
54
55/**
56 *
57 * @author olhsha
58 */
59@RunWith(SpringJUnit4ClassRunner.class)
60@ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml",
61    "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml",
62    "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockVersionDao.xml", "/spring-test-config/mockCachedRepresentationDao.xml",
63    "/spring-config/daoDispatcher.xml"})
64public class DaoDispatcherTest {
65
66    @Autowired
67    private DaoDispatcherImpl daoDispatcher;
68    @Autowired
69    private Mockery mockery;
70    @Autowired
71    private UserDao userDao;
72    @Autowired
73    private CachedRepresentationDao cachedRepresentationDao;
74    @Autowired
75    private VersionDao versionDao;
76    @Autowired
77    private SourceDao sourceDao;
78    @Autowired
79    private AnnotationDao annotationDao;
80    @Autowired
81    private NotebookDao notebookDao;
82    TestInstances testInstances = new TestInstances();
83
84    public DaoDispatcherTest() {
85    }
86
87    ///////// GETTERS /////////////
88    /**
89     * Test of getAnnotationInternalIdentifier method, of class DaoDispatcherImpl.
90     */
91    @Test
92    public void testGetAnnotationInternalIdentifier() {
93        System.out.println("getAnnotationInternalIdentifier");
94        final UUID externalID = UUID.fromString(TestBackendConstants._TEST_ANNOT_2_EXT);
95
96        mockery.checking(new Expectations() {
97            {
98                oneOf(annotationDao).getInternalID(externalID);
99                will(returnValue(2));
100            }
101        });
102        assertEquals(2, daoDispatcher.getAnnotationInternalIdentifier(externalID));
103    }
104
105    /**
106     * Test of getAnnotationExternalIdentifier method, of class DaoDispatcherImpl.
107     */
108    @Test
109    public void testGetAnnotationExternalIdentifier() {
110        System.out.println("getAnnotationExternalIdentifier");
111        final UUID externalID = UUID.fromString(TestBackendConstants._TEST_ANNOT_2_EXT);
112
113        mockery.checking(new Expectations() {
114            {
115                oneOf(annotationDao).getExternalID(2);
116                will(returnValue(externalID));
117            }
118        });
119        assertEquals(TestBackendConstants._TEST_ANNOT_2_EXT, daoDispatcher.getAnnotationExternalIdentifier(2).toString());
120    }
121
122    /**
123     * Test of getUserInternalIdentifier method, of class DaoDispatcherImpl.
124     */
125    @Test
126    public void testGetUserInternalIdentifier() {
127        System.out.println("getUserInternalIdentifier");
128
129        final UUID externalID = UUID.fromString(TestBackendConstants._TEST_USER_5_EXT_ID);
130
131        mockery.checking(new Expectations() {
132            {
133                oneOf(userDao).getInternalID(externalID);
134                will(returnValue(5));
135            }
136        });
137        assertEquals(5, daoDispatcher.getUserInternalIdentifier(externalID));
138    }
139
140    /**
141     * Test of getUserExternalIdentifier method, of class DaoDispatcherImpl.
142     */
143    @Test
144    public void testGetUserExternalIdentifier() {
145        System.out.println("getUserExternalIdentifier");
146        final UUID externalID = UUID.fromString(TestBackendConstants._TEST_USER_5_EXT_ID);
147
148        mockery.checking(new Expectations() {
149            {
150                oneOf(userDao).getExternalID(5);
151                will(returnValue(externalID));
152            }
153        });
154        assertEquals(TestBackendConstants._TEST_USER_5_EXT_ID, daoDispatcher.getUserExternalIdentifier(5).toString());
155    }
156
157    /**
158     * Test of getAnnotation method, of class DaoDispatcherImpl.
159     */
160    @Test
161    public void testGetAnnotation() throws Exception {
162        System.out.println("test getAnnotation");
163
164        final Annotation mockAnnotation = new Annotation();// corresponds to the annotation # 2
165        mockAnnotation.setURI(TestBackendConstants._TEST_ANNOT_2_EXT);
166        mockAnnotation.setHeadline(TestBackendConstants._TEST_ANNOT_2_HEADLINE);
167        XMLGregorianCalendar mockTimeStamp = Helpers.setXMLGregorianCalendar(Timestamp.valueOf("2013-08-12 11:25:00.383000"));
168        mockAnnotation.setTimeStamp(mockTimeStamp);
169        ResourceREF mockOwner = new ResourceREF();
170        mockOwner.setRef(Integer.toString(TestBackendConstants._TEST_ANNOT_2_OWNER));
171        mockAnnotation.setOwner(mockOwner);
172        AnnotationBody mockBody = new AnnotationBody();
173        mockBody.getAny().add(TestBackendConstants._TEST_ANNOT_2_BODY); // TODO: will be changed after body serialization is fixed
174        mockAnnotation.setBody(mockBody);
175        mockAnnotation.setTargetSources(null);
176
177
178        final List<Number> mockSourceIDs = new ArrayList<Number>();
179        mockSourceIDs.add(1);
180        mockSourceIDs.add(2);
181
182        final Source mockSourceOne = new Source();
183        mockSourceOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
184        mockSourceOne.setURI(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
185        mockSourceOne.setVersion(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
186
187        final Source mockSourceTwo = new Source();
188        mockSourceTwo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK);
189        mockSourceTwo.setURI(TestBackendConstants._TEST_SOURCE_2_EXT_ID);
190        mockSourceTwo.setVersion(TestBackendConstants._TEST_SOURCE_2_EXT_ID);
191
192
193        // NOT CHECKED: time stamp for sources
194
195        mockery.checking(new Expectations() {
196            {
197                oneOf(annotationDao).getAnnotationWithoutSources(1);
198                will(returnValue(mockAnnotation));
199
200                oneOf(annotationDao).retrieveSourceIDs(1);
201                will(returnValue(mockSourceIDs));
202
203                oneOf(sourceDao).getSource(1);
204                will(returnValue(mockSourceOne));
205
206                oneOf(sourceDao).getSource(2);
207                will(returnValue(mockSourceTwo));
208
209            }
210        });
211
212        Annotation result = daoDispatcher.getAnnotation(1);
213        assertEquals(TestBackendConstants._TEST_ANNOT_2_EXT, result.getURI());
214        assertEquals(TestBackendConstants._TEST_ANNOT_2_BODY, result.getBody().getAny().get(0));
215        assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, result.getHeadline());
216        assertEquals(TestBackendConstants._TEST_ANNOT_2_TIME_STAMP, result.getTimeStamp().toString());
217        assertEquals(TestBackendConstants._TEST_ANNOT_2_OWNER, Integer.parseInt(result.getOwner().getRef()));
218        assertEquals(mockSourceOne.getLink(), result.getTargetSources().getTarget().get(0).getSource().getLink());
219        assertEquals(mockSourceOne.getURI(), result.getTargetSources().getTarget().get(0).getSource().getRef());
220        assertEquals(mockSourceOne.getVersion(), result.getTargetSources().getTarget().get(0).getSource().getVersion());
221        assertEquals(mockSourceTwo.getLink(), result.getTargetSources().getTarget().get(1).getSource().getLink());
222        assertEquals(mockSourceTwo.getURI(), result.getTargetSources().getTarget().get(1).getSource().getRef());
223        assertEquals(mockSourceTwo.getVersion(), result.getTargetSources().getTarget().get(1).getSource().getVersion());
224    }
225
226    /**
227     * Test of getFilteredAnnotationIDs method, of class DaoDispatcherImpl.
228     */
229    @Test
230    public void testGetFilteredAnnotationIDs() {
231        System.out.println("test getFilteredAnnotationIDs");
232
233        final String link = "nl.wikipedia.org";
234
235        final List<Number> mockSourceIDs = new ArrayList<Number>();
236        mockSourceIDs.add(1);
237        mockSourceIDs.add(2);
238
239        final List<Number> mockAnnotationIDs = new ArrayList<Number>();
240        mockAnnotationIDs.add(2);
241        mockAnnotationIDs.add(3);
242
243        final String text = "some html";
244        final String access = null;
245        final String namespace = null;
246        final UUID owner = UUID.fromString(TestBackendConstants._TEST_USER_3_EXT_ID);
247        final Timestamp after = new Timestamp(0);
248        final Timestamp before = new Timestamp(System.currentTimeMillis());
249
250        final List<Number> mockRetval = new ArrayList<Number>();
251        mockRetval.add(2);
252
253        mockery.checking(new Expectations() {
254            {
255                oneOf(sourceDao).getSourcesForLink(link);
256                will(returnValue(mockSourceIDs));
257
258                oneOf(annotationDao).retrieveAnnotationList(mockSourceIDs);
259                will(returnValue(mockAnnotationIDs));
260
261                oneOf(userDao).getInternalID(owner);
262                will(returnValue(3));
263
264                oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs, text, access, namespace, 3, after, before);
265                will(returnValue(mockRetval));
266
267            }
268        });
269
270
271        List result = daoDispatcher.getFilteredAnnotationIDs(link, text, access, namespace, owner, after, before);
272        assertEquals(1, result.size());
273        assertEquals(2, result.get(0));
274    }
275
276    ////////////// ADDERS /////////////////////////
277    /**
278     * Test of addCachedForVersion method, of class DaoDispatcherImpl.
279     */
280    @Test
281    public void testAddCachedForVersion() {
282        System.out.println("addCachedForVersion");
283        String mime = "text/html";
284        String type = "text";
285        String tool = "latex";
286        final CachedRepresentationInfo newCached = new CachedRepresentationInfo();
287        newCached.setMimeType(mime);
288        newCached.setType(type);
289        newCached.setTool(tool);
290        final Number newCachedID = 8;
291        final Number versionID = 1;
292        mockery.checking(new Expectations() {
293            {
294                oneOf(cachedRepresentationDao).getInternalID(null);
295                will(returnValue(null));
296
297                oneOf(cachedRepresentationDao).addCachedRepresentationInfo(newCached);
298                will(returnValue(newCachedID));
299
300                one(versionDao).addVersionCachedRepresentation(versionID, newCachedID);
301                will(returnValue(1));
302
303            }
304        });
305
306
307        Number[] result = daoDispatcher.addCachedForVersion(versionID, newCached);
308        assertEquals(2, result.length);
309        assertEquals(1, result[0]);
310        assertEquals(newCachedID, result[1]);
311    }
312
313    /**
314     * Test of addSiblingVersionForSource method, of class DaoDispatcherImpl.
315     */
316    @Test
317    public void testAddSiblingVersionForSource() throws Exception {
318        System.out.println("test addSiblingVersionForSource ");
319
320        // test adding completely new version
321        final Version mockVersion = new Version(); // should be # 8
322        final UUID mockUUID = UUID.randomUUID();
323        mockVersion.setVersion(mockUUID.toString());
324
325        mockery.checking(new Expectations() {
326            {
327                oneOf(versionDao).getInternalID(mockUUID);
328                will(returnValue(null));
329
330                oneOf(versionDao).addVersion(mockVersion);
331                will(returnValue(8));
332
333                oneOf(sourceDao).addSourceVersion(1, 8);
334                will(returnValue(1));
335
336            }
337        });
338
339        Number[] result = daoDispatcher.addSiblingVersionForSource(1, mockVersion);
340        assertEquals(2, result.length);
341        assertEquals(1, result[0]);
342        assertEquals(8, result[1]);
343
344
345        // Another test: connecting the existing version to the source
346
347        final Version mockVersionTwo = new Version(); // should be # 3
348        final UUID mockUUIDTwo = UUID.fromString(TestBackendConstants._TEST_VERSION_3_EXT_ID);
349        mockVersionTwo.setVersion(mockUUIDTwo.toString());
350
351        mockery.checking(new Expectations() {
352            {
353                oneOf(versionDao).getInternalID(mockUUIDTwo);
354                will(returnValue(3));
355
356                oneOf(sourceDao).addSourceVersion(1, 3);
357                will(returnValue(1));
358            }
359        });
360        Number[] resultTwo = daoDispatcher.addSiblingVersionForSource(1, mockVersionTwo);
361        assertEquals(2, resultTwo.length);
362        assertEquals(1, resultTwo[0]);
363        assertEquals(3, resultTwo[1]);
364    }
365
366    /**
367     * Test of addSourcesForAnnotation method, of class DaoDispatcherImpl.
368     */
369    @Test
370    public void testAddSourcesForAnnotation() throws Exception {
371        System.out.println("test addSourcesForAnnotation");
372
373        // test 1: adding an existing source
374        NewOrExistingSourceInfo testSourceOne = new NewOrExistingSourceInfo();
375        final UUID mockUUIDOne = UUID.fromString(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
376        SourceInfo testOldSource = new SourceInfo();
377        testOldSource.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);
378        testOldSource.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);
379        testOldSource.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);
380        testSourceOne.setSource(testOldSource);
381        List<NewOrExistingSourceInfo> mockSourceSOne = new ArrayList<NewOrExistingSourceInfo>();
382        mockSourceSOne.add(testSourceOne);
383
384        mockery.checking(new Expectations() {
385            {
386                oneOf(sourceDao).getInternalID(with(aNonNull(UUID.class)));
387                will(returnValue(1));
388
389                oneOf(annotationDao).addAnnotationSourcePair(1, 1);
390                will(returnValue(1));
391            }
392        });
393
394        Map<String, String> result = daoDispatcher.addSourcesForAnnotation(1, mockSourceSOne);
395        assertEquals(0, result.size());
396
397        // test 2: adding a new source
398
399        NewOrExistingSourceInfo testSourceTwo = new NewOrExistingSourceInfo();
400        NewSourceInfo testNewSource = new NewSourceInfo();
401        testNewSource.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
402        testNewSource.setVersion(null);
403        testSourceTwo.setNewSource(testNewSource);
404        List<NewOrExistingSourceInfo> mockSourceSTwo = new ArrayList<NewOrExistingSourceInfo>();
405        mockSourceSTwo.add(testSourceTwo);
406
407//        final Source mockNewSource = daoDispatcher.createSource(testNewSource);
408//        final Version mockNewVersion = daoDispatcher.createVersion(testNewSource);
409
410        mockery.checking(new Expectations() {
411            {
412                oneOf(sourceDao).addSource(with(aNonNull(Source.class)));
413                will(returnValue(6)); //# the next new number is 6, we have already 5 sources
414
415                ////////////  mockery in the call addSiblingVersionForSource //////////////
416
417                oneOf(versionDao).getInternalID(with(aNonNull(UUID.class)));
418                will(returnValue(null));
419
420                oneOf(versionDao).addVersion(with(aNonNull(Version.class)));
421                will(returnValue(8)); // next free nummber
422
423                oneOf(sourceDao).addSourceVersion(6, 8);
424                will(returnValue(1));
425
426                //////////////////////////////////////
427
428                oneOf(annotationDao).addAnnotationSourcePair(1, 6);
429                will(returnValue(1));
430
431            }
432        });
433
434        Map<String, String> resultTwo = daoDispatcher.addSourcesForAnnotation(1, mockSourceSTwo);
435        assertEquals(1, resultTwo.size());
436        assertFalse(null == resultTwo.get(testNewSource.getId()));
437
438    }
439
440    /**
441     * Test of addUsersAnnotation method, of class DaoDispatcherImpl.
442     */
443    @Test
444    public void testAddUsersAnnotation() throws Exception {
445        System.out.println("test addUsersAnnotation");
446
447        // expectations for addUsersannotation itself
448        final Annotation testAnnotation = testInstances.getAnnotationToAdd();
449
450        mockery.checking(new Expectations() {
451            {
452                oneOf(annotationDao).addAnnotation(testAnnotation, 5);
453                will(returnValue(6)); // the next free number is 6
454
455                //  expectations for addSourcesForannotation
456                oneOf(sourceDao).getInternalID(with(aNonNull(UUID.class)));
457                will(returnValue(1));
458
459                oneOf(annotationDao).addAnnotationSourcePair(6, 1);
460                will(returnValue(1)); // the source is old, no new persistent identifier were produced
461
462                ///////////
463
464                oneOf(annotationDao).updateBody(6, testAnnotation.getBody().getAny().get(0).toString());// will be changed after serialization is fixed
465                will(returnValue(1)); // the DB update will be called at perform anyway, even if the body is not changed (can be optimized)
466
467                oneOf(annotationDao).addAnnotationPrincipalPermission(6, 5, Permission.OWNER);
468                will(returnValue(1));
469            }
470        });
471
472        Number result = daoDispatcher.addUsersAnnotation(testAnnotation, 5);
473        assertEquals(6, result);
474    }
475
476    //////////////////// DELETERS ////////////////
477    /**
478     * Test of deleteCachedForVersion method, of class DaoDispatcherImpl.
479     */
480    @Test
481    public void testDeleteCachedForVersion() {
482        System.out.println("deleteCachedForVersion");
483        mockery.checking(new Expectations() {
484            {
485                oneOf(versionDao).deleteVersionCachedRepresentation(6, 5);
486                will(returnValue(1));
487
488                oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5);
489                will(returnValue(0)); // cached is used by another version
490
491            }
492        });
493
494        int[] result = daoDispatcher.deleteCachedOfVersion(6, 5);
495        assertEquals(2, result.length);
496        assertEquals(1, result[0]);
497        assertEquals(0, result[1]);
498    }
499
500    /////////////////////////////////////////////
501    @Test
502    public void testDeleteAalCachedOfVersion() {
503        System.out.println("deleteVersion");
504        final List<Number> cachedList = new ArrayList<Number>();
505        cachedList.add(5);
506
507        mockery.checking(new Expectations() {
508            {
509                oneOf(versionDao).versionIsInUse(6);
510                will(returnValue(false));
511
512                oneOf(versionDao).retrieveCachedRepresentationList(6);
513                will(returnValue(cachedList));
514
515                oneOf(versionDao).deleteAllVersionCachedRepresentation(6);
516                will(returnValue(1));
517
518                oneOf(versionDao).deleteVersion(6);
519                will(returnValue(1));
520
521                oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5);
522                will(returnValue(0)); // cached is used by another version
523            }
524        });
525
526        int[] result = daoDispatcher.deleteAllCachedOfVersion(6);
527        assertEquals(1, result[0]); //version
528        assertEquals(1, result[1]); // versions-cached
529        assertEquals(0, result[2]);//cached 5 is in use
530
531        //Another test
532
533
534        mockery.checking(new Expectations() {
535            {
536                oneOf(versionDao).versionIsInUse(5);
537                will(returnValue(true));
538            }
539        });
540
541
542        int[] resultTwo = daoDispatcher.deleteAllCachedOfVersion(5); // version is in use by the source 4
543        assertEquals(0, resultTwo[0]);
544        assertEquals(0, resultTwo[1]);
545        assertEquals(0, resultTwo[2]);
546
547    }
548
549    @Test
550    public void testDeleteAllVersionsOfSource() throws SQLException {
551        // test 1: source in use by some annotation
552        mockery.checking(new Expectations() {
553            {
554                oneOf(sourceDao).sourceIsInUse(1);
555                will(returnValue(true));
556            }
557        });
558
559        int[] result = daoDispatcher.deleteAllVersionsOfSource(1); //the source is in use, should not be deleted
560        assertEquals(0, result[0]); //
561        assertEquals(0, result[1]);
562
563        // test 2 : source is not used by annotations     
564        final List<Number> versionList = new ArrayList<Number>();
565        versionList.add(7);
566        mockery.checking(new Expectations() {
567            {
568                oneOf(sourceDao).sourceIsInUse(5);
569                will(returnValue(false));
570
571                oneOf(sourceDao).retrieveVersionList(5);
572                will(returnValue(versionList));
573
574                oneOf(sourceDao).deleteAllSourceVersion(5);
575                will(returnValue(1));
576
577                oneOf(sourceDao).deleteSource(5);
578                will(returnValue(1));
579
580                oneOf(versionDao).versionIsInUse(7);
581                will(returnValue(false)); //not mentioned in the table "sources_versions" after deleteing(5,7)
582
583                oneOf(versionDao).retrieveCachedRepresentationList(7);
584                will(returnValue(new ArrayList<Number>())); // no cached representations for version 7, the list is just empty
585
586                oneOf(versionDao).deleteAllVersionCachedRepresentation(7);
587
588                oneOf(versionDao).deleteVersion(7);
589                will(returnValue(1));
590            }
591        });
592
593
594        int[] resultTwo = daoDispatcher.deleteAllVersionsOfSource(5);// the source will be deleted because it is not referred by any annotation
595        assertEquals(3, resultTwo.length);
596        assertEquals(1, resultTwo[0]); // source 7 is deleted
597        assertEquals(1, resultTwo[1]); // row (5,7) in "sorces_versions" is deleted
598        assertEquals(1, resultTwo[2]); // version 7 is deleted
599    }
600
601    /**
602     * Test of deleteAnnotationWithSources method, of class DaoDispatcherImpl.
603     */
604    @Test
605    public void testDeleteAnnotation() throws Exception {
606        System.out.println("deleteAnnotation ");
607
608        // deleting annotation 3, which has its target source 2  (used by annotation # 1)
609        final List<Number> mockSourceIDs = new ArrayList<Number>();
610        mockSourceIDs.add(2);
611
612        mockery.checking(new Expectations() {
613            {
614                oneOf(annotationDao).deleteAnnotationPrincipalPermissions(3);
615                will(returnValue(3));
616
617                oneOf(annotationDao).retrieveSourceIDs(3);
618                will(returnValue(mockSourceIDs));
619
620                oneOf(annotationDao).deleteAllAnnotationSource(3);
621                will(returnValue(1));
622
623                oneOf(annotationDao).deleteAnnotation(3);
624                will(returnValue(1));
625
626                oneOf(sourceDao).sourceIsInUse(2); // expectation for deleteAllVersionsOfSource
627                will(returnValue(true));
628            }
629        });
630        int[] result = daoDispatcher.deleteAnnotation(3);// the source will be deleted because it is not referred by any annotation
631        assertEquals(4, result.length);
632        assertEquals(1, result[0]); // annotation 3 is deleted
633        assertEquals(3, result[1]); // 3 rows in "annotation proncipal permissions are deleted"
634        assertEquals(1, result[2]);  // row (3,2) in "annotations_sources" is deleted
635        assertEquals(0, result[3]); //the source 2 is not deleted because it is still in use by anntation 2
636    }
637   
638   
639//    @Test
640//    public void testCreateSource(){ 
641//        NewSourceInfo newSourceInfo = new NewSourceInfo();
642//        newSourceInfo.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
643//        newSourceInfo.setVersion(null);
644//       
645//        Source result = daoDispatcher.createSource(newSourceInfo);
646//        assertEquals(TestBackendConstants._TEST_NEW_SOURCE_LINK, result.getLink());
647//        assertFalse(null == result.getURI());
648//       
649//    }
650//   
651//    @Test
652//    public void testCreateVersion(){ 
653//        NewSourceInfo newSourceInfo = new NewSourceInfo();
654//        newSourceInfo.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
655//        newSourceInfo.setVersion(null);
656//       
657//        Version result = daoDispatcher.createVersion(newSourceInfo);
658//        assertFalse(null == result.getVersion()); // will be chnaged once the schema for version is fixed: ID is added
659//       
660//    }
661}
662
663
Note: See TracBrowser for help on using the repository browser.