Ignore:
Timestamp:
12/19/13 14:36:04 (10 years ago)
Author:
olhsha
Message:

adding trasnactional, refactoring and fixing bugs in updated annotations, removing try-catch from resource methods (The Greek's advice)

File:
1 edited

Legend:

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

    r4173 r4207  
    295295        mockAnnotationIDs1.add(3);
    296296        mockAnnotationIDs1.add(4);
     297        mockAnnotationIDs1.add(5);
    297298       
    298299        final List<Number> mockAnnotationIDs2 = new ArrayList<Number>();
     
    300301        mockAnnotationIDs2.add(3);
    301302
    302         final String text = "some html";
     303       
    303304        final UUID owner = UUID.fromString(TestBackendConstants._TEST_USER_4_EXT_ID);
    304305        final Timestamp after = new Timestamp(0);
     
    306307
    307308        final List<Number> mockRetval = new ArrayList<Number>();
    308         mockRetval.add(2);
    309        
    310        
     309        mockRetval.add(3);
     310       
     311        final String[] accessModes = new String[2];
     312        accessModes[0] = "reader";
     313        accessModes[1] = "writer";
    311314
    312315        mockeryDao.checking(new Expectations() {
     
    315318                will(returnValue(mockTargetIDs));
    316319
    317                 oneOf(annotationDao).getAnnotationIDsForUserWithPermission(3, "reader");
     320                oneOf(annotationDao).getAnnotationIDsForUserWithPermission(3, accessModes);
    318321                will(returnValue(mockAnnotationIDs1));
    319322
     
    326329               
    327330               
    328                 oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, text, null, 4, after, before);
     331                oneOf(annotationDao).getFilteredAnnotationIDs(mockAnnotationIDs1, "some html", null, 4, after, before);
    329332                will(returnValue(mockRetval));
    330333
     
    333336
    334337
    335         List result = dbIntegrityService.getFilteredAnnotationIDs(word, text, 3, "reader", null, owner, after, before);
     338        List result = dbIntegrityService.getFilteredAnnotationIDs(word, "some html", 3, accessModes, null, owner, after, before);
    336339        assertEquals(1, result.size());
    337         assertEquals(2, result.get(0));
     340        assertEquals(3, result.get(0));
    338341    }
    339342
     
    388391        mockTargetIDs.add(2);
    389392
    390          final List<Number> mockAnnotationIDs1 = new ArrayList<Number>();
     393        final List<Number> mockAnnotationIDs1 = new ArrayList<Number>();
    391394        mockAnnotationIDs1.add(3);
    392395        mockAnnotationIDs1.add(4);
     396        mockAnnotationIDs1.add(5);
    393397       
    394398        final List<Number> mockAnnotationIDs2 = new ArrayList<Number>();
     
    403407
    404408        final List<Number> mockAnnotIDs = new ArrayList<Number>();
    405         mockAnnotIDs.add(2);
     409        mockAnnotIDs.add(3);
    406410       
    407411        final AnnotationInfo mockAnnotInfo = new AnnotationInfo();
    408412       
    409         mockAnnotInfo.setHeadline(TestBackendConstants._TEST_ANNOT_2_HEADLINE);       
    410         mockAnnotInfo.setRef(TestBackendConstants._TEST_SERVLET_URI_annotations + TestBackendConstants._TEST_ANNOT_2_EXT);
     413        mockAnnotInfo.setHeadline(TestBackendConstants._TEST_ANNOT_3_HEADLINE);       
     414        mockAnnotInfo.setRef(TestBackendConstants._TEST_SERVLET_URI_annotations + TestBackendConstants._TEST_ANNOT_3_EXT);
    411415       
    412416        final List<Number> TargetIDs = new ArrayList<Number>();
    413         TargetIDs.add(1);
    414417        TargetIDs.add(2);
    415418       
    416         final Map<AnnotationInfo,Number> mockPair = new HashMap<AnnotationInfo, Number>();
    417         mockPair.put(mockAnnotInfo, 3);
    418        
    419         mockeryDao.checking(new Expectations() {
    420             {
    421                 oneOf(annotationDao).getAnnotationIDsForUserWithPermission(3, "reader");
     419        final Map<AnnotationInfo,Number> mockPair = new HashMap<AnnotationInfo, Number>(); // annotationInfo-ownerID
     420        mockPair.put(mockAnnotInfo, 4);
     421       
     422        final String[] accessModes = new String[2];
     423        accessModes[0] = "reader";
     424        accessModes[1] = "writer";
     425       
     426        mockeryDao.checking(new Expectations() {
     427            {
     428                oneOf(annotationDao).getAnnotationIDsForUserWithPermission(3, accessModes);
    422429                will(returnValue(mockAnnotationIDs1));
    423430
     
    439446//                ///////////////////////////////////
    440447//               
    441                 oneOf(annotationDao).getAnnotationInfoWithoutTargets(2);
     448                oneOf(annotationDao).getAnnotationInfoWithoutTargets(3);
    442449                will(returnValue(mockPair));
    443450               
    444451                ////
    445                 oneOf(annotationDao).retrieveTargetIDs(2);
     452                oneOf(annotationDao).retrieveTargetIDs(3);
    446453                will(returnValue(TargetIDs));
    447454               
    448                 oneOf(targetDao).getURIFromInternalID(1);
    449                 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_Targets +TestBackendConstants._TEST_Target_1_EXT_ID));
    450455               
    451456                oneOf(targetDao).getURIFromInternalID(2);
     
    453458                ////
    454459               
    455                 oneOf(userDao).getURIFromInternalID(3);
    456                 will(returnValue(TestBackendConstants._TEST_SERVLET_URI_users +TestBackendConstants._TEST_USER_3_EXT_ID));
     460                oneOf(userDao).getURIFromInternalID(4);
     461                will(returnValue(TestBackendConstants._TEST_SERVLET_URI_users +TestBackendConstants._TEST_USER_4_EXT_ID));
    457462             
    458463               
     
    461466       
    462467     
    463         AnnotationInfoList result = dbIntegrityService.getFilteredAnnotationInfos(word, text, 3, "reader", null, ownerUUID, after, before);
     468        AnnotationInfoList result = dbIntegrityService.getFilteredAnnotationInfos(word, text, 3, accessModes, null, ownerUUID, after, before);
    464469        assertEquals(1, result.getAnnotationInfo().size());
    465470        AnnotationInfo resultAnnotInfo = result.getAnnotationInfo().get(0);
    466471        assertEquals(mockAnnotInfo.getHeadline(), resultAnnotInfo.getHeadline());
    467         assertEquals(TestBackendConstants._TEST_SERVLET_URI_users +TestBackendConstants._TEST_USER_3_EXT_ID, resultAnnotInfo.getOwnerRef());
     472        assertEquals(TestBackendConstants._TEST_SERVLET_URI_users +TestBackendConstants._TEST_USER_4_EXT_ID, resultAnnotInfo.getOwnerRef());
    468473        assertEquals(mockAnnotInfo.getRef(),result.getAnnotationInfo().get(0).getRef() );
    469         assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets +TestBackendConstants._TEST_Target_1_EXT_ID, resultAnnotInfo.getTargets().getRef().get(0));
    470         assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets +TestBackendConstants._TEST_Target_2_EXT_ID, resultAnnotInfo.getTargets().getRef().get(1));
     474        assertEquals(TestBackendConstants._TEST_SERVLET_URI_Targets +TestBackendConstants._TEST_Target_2_EXT_ID, resultAnnotInfo.getTargets().getRef().get(0));
    471475         
    472476    }
     
    690694                ///////////
    691695
    692                 oneOf(annotationDao).updateAnnotationBodyText(6, testAnnotation.getBody().getTextBody().getValue());
     696                oneOf(annotationDao).updateAnnotationBody(6, testAnnotation.getBody().getTextBody().getValue(), testAnnotation.getBody().getTextBody().getMimeType(), false);
    693697                will(returnValue(1)); // the DB update will be called at perform anyway, even if the body is not changed (can be optimized)
    694698
Note: See TracChangeset for help on using the changeset viewer.