Changeset 3450


Ignore:
Timestamp:
08/20/13 15:54:35 (11 years ago)
Author:
olhsha
Message:

AnnotationResource? and its test are adjusted, however: there must an interface for DaoDispatcher? to be able to mock it. Moreover make a bean for it as well, and remove comnent annotation, so it can be autowired.

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

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/nb-configuration.xml

    r3221 r3450  
    2020        <config-files>
    2121            <config-file>src/main/resources/spring-config/sourceDao.xml</config-file>
    22             <config-file>src/main/resources/spring-config/VersionDao.xml</config-file>
    23             <config-file>src/main/resources/spring-config/CachedRepresentationDao.xml</config-file>
     22            <config-file>src/main/resources/spring-config/versionDao.xml</config-file>
     23            <config-file>src/main/resources/spring-config/cachedRepresentationDao.xml</config-file>
    2424            <config-file>src/test/resources/spring-test-config/mockVersionDao.xml</config-file>
    25             <config-file>src/test/resources/spring-test-config/mockCachedRepresenationDao.xml</config-file>
     25            <config-file>src/test/resources/spring-test-config/mockDaoDispatcher.xml</config-file>
    2626        </config-files>
    2727        <config-file-groups/>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/MockObjectsFactory.java

    r3408 r3450  
    2424import eu.dasish.annotation.backend.dao.UserDao;
    2525import eu.dasish.annotation.backend.dao.VersionDao;
     26import eu.dasish.annotation.backend.rest.DaoDispatcher;
    2627import org.jmock.Mockery;
    2728
     
    6364        return context.mock(VersionDao.class);
    6465    }
     66   
     67    public DaoDispatcher newDaoDispatcher() {
     68        return context.mock(DaoDispatcher.class);
     69    }
    6570}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3413 r3450  
    232232        assertEquals(6, newAnnotationID);
    233233       
     234        // checking
    234235        Annotation addedAnnotation= jdbcAnnotationDao.getAnnotationWithoutSources(6);
    235236        assertFalse(null == addedAnnotation.getURI());
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java

    r3413 r3450  
    123123       
    124124        Number result = jdbcCachedRepresentationDao.addCachedRepresentationInfo(cached);
     125        // checking
    125126        CachedRepresentationInfo addedCached = jdbcCachedRepresentationDao.getCachedRepresentationInfo(result);
    126127        assertEquals(8, result.intValue());
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java

    r3413 r3450  
    133133        Number result = jdbcSourceDao.addSource(freshSource);
    134134        assertEquals(6, result);
     135        // detailed checking
    135136        Source addedSource = jdbcSourceDao.getSource(result);
    136137        assertEquals(link, addedSource.getLink());
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java

    r3413 r3450  
    109109        Number result = jdbcVersionDao.addVersion(freshVersion);
    110110        assertEquals(8, result);
     111        // detailed checking
    111112        Version addedVersion = jdbcVersionDao.getVersion(result);
    112113        assertFalse(null == addedVersion.getVersion()); // extend once "version" information is fixed, and becomes different from externalID
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r3408 r3450  
    2121import eu.dasish.annotation.backend.TestBackendConstants;
    2222import eu.dasish.annotation.backend.TestInstances;
    23 import eu.dasish.annotation.backend.dao.AnnotationDao;
    24 import eu.dasish.annotation.backend.dao.NotebookDao;
    25 import eu.dasish.annotation.backend.dao.SourceDao;
    26 import eu.dasish.annotation.backend.dao.UserDao;
    2723import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2824import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2925import eu.dasish.annotation.schema.Annotation;
    30 import eu.dasish.annotation.schema.ResourceREF;
    3126import java.sql.SQLException;
    3227import javax.xml.bind.JAXBElement;
     
    4136import java.lang.InstantiationException;
    4237import javax.servlet.ServletException;
    43 import org.junit.Ignore;
    4438import org.springframework.mock.web.MockHttpServletRequest;
    4539/**
     
    4943
    5044@RunWith(value = SpringJUnit4ClassRunner.class)
    51 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml",
    52     "/spring-test-config/mockSourceDao.xml",
    53     "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
     45@ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockDaoDispatcher.xml",
     46    "/spring-test-config/mockery.xml", })
    5447public class AnnotationResourceTest {
    5548   
     
    5750    private Mockery mockery;
    5851    @Autowired
    59     private AnnotationDao annotationDao;
    60     @Autowired
    61     private UserDao userDao;
    62     @Autowired
    63     private NotebookDao notebookDao; 
    64     @Autowired
    65     private SourceDao sourceDao;
    66    
     52    private DaoDispatcher daoDispatcher;
    6753    @Autowired
    6854    private AnnotationResource annotationResource;
     
    7662     */
    7763    @Test
    78     @Ignore
    7964    public void testGetAnnotation() throws SQLException {
    8065        System.out.println("getAnnotation");
     
    8267        final int annotationID = 2;       
    8368        final Annotation expectedAnnotation = (new TestInstances()).getAnnotationOne();
    84         // the result of the mocking chain is the same as the expected annotation.       
    85 //        mockery.checking(new Expectations() {
    86 //            {
    87 //                oneOf(annotationDao).getInternalID(new AnnotationIdentifier(annotationIdentifier));               
    88 //                will(returnValue(annotationID));               
    89 //               
    90 //                oneOf(annotationDao).getAnnotation(annotationID);               
    91 //                will(returnValue(expectedAnnotation));
    92 //            }
    93 //        });
     69       
     70        //final Number annotationID = daoDispatcher.getAnnotationInternalIdentifier(new AnnotationIdentifier(annotationIdentifier));
     71        //final Annotation annotation = daoDispatcher.getAnnotation(annotationID);
     72        mockery.checking(new Expectations() {
     73            {
     74                oneOf(daoDispatcher).getAnnotationInternalIdentifier(with(aNonNull(AnnotationIdentifier.class)));               
     75                will(returnValue(annotationID));               
     76               
     77                oneOf(daoDispatcher).getAnnotation(annotationID);               
     78                will(returnValue(expectedAnnotation));
     79            }
     80        });
    9481         
    9582        JAXBElement<Annotation> result = annotationResource.getAnnotation(annotationIdentifier);
     
    10390    public void testDeleteAnnotation() throws SQLException {
    10491        System.out.println("deleteAnnotation");
    105        
     92        //final Number annotationID = daoDispatcher.getAnnotationInternalIdentifier(new AnnotationIdentifier(annotationIdentifier));
     93        //int[] resultDelete = daoDispatcher.deleteAnnotation(annotationID);
    10694       
    10795        mockery.checking(new Expectations() {
    10896            { 
    109                 oneOf(annotationDao).getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));               
     97                oneOf(daoDispatcher).getAnnotationInternalIdentifier(with(aNonNull(AnnotationIdentifier.class)));             
    11098                will(returnValue(5));     
    11199               
    112                 oneOf(annotationDao).deleteAnnotation(5);
     100                oneOf(daoDispatcher).deleteAnnotation(5);
    113101                will(returnValue(1));
    114102            }
     
    117105        String result = annotationResource.deleteAnnotation(TestBackendConstants._TEST_ANNOT_5_EXT);
    118106        assertEquals("1", result);
    119        
    120          // now, try to delete the same annotation one more time
    121         // if it has been already deleted then the method under testing should return 0
    122         mockery.checking(new Expectations() {
    123             {
    124                 oneOf(annotationDao).getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT));               
    125                 will(returnValue(5));
    126                
    127                 oneOf(annotationDao).deleteAnnotation(5);
    128                 will(returnValue(0));
    129             }
    130         });
    131        
    132         result = annotationResource.deleteAnnotation(TestBackendConstants._TEST_ANNOT_5_EXT);
    133         assertEquals("0", result);
    134107    }
    135108   
     
    138111     */
    139112    @Test
    140     @Ignore
    141113    public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException, ServletException {
    142114        System.out.println("test createAnnotation");
    143115        final Annotation annotationToAdd = new GenericType<Annotation>(){}.getRawClass().newInstance();
    144116       
    145         final Annotation addedAnnotation = annotationToAdd;
    146         final AnnotationIdentifier annotationIdentifier = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();
    147         addedAnnotation.setURI(annotationIdentifier.toString());
    148         ResourceREF ownerRef = new ResourceREF();
    149         ownerRef.setRef(String.valueOf(5));
    150         addedAnnotation.setOwner(ownerRef);
    151        
    152         final UserIdentifier owner = new UserIdentifier(TestBackendConstants._TEST_USER_5_EXT_ID);
     117//        Number userID = null;
     118//        if (remoteUser != null) {
     119//            userID = daoDispatcher.getUserInternalIdentifier(new UserIdentifier(remoteUser));
     120//        }
     121//        Number newAnnotationID =  daoDispatcher.addUsersAnnotation(annotation, userID);
     122//        Annotation newAnnotation = daoDispatcher.getAnnotation(newAnnotationID);
    153123       
    154 //        mockery.checking(new Expectations() {
    155 //            {
    156 //                oneOf(userDao).getInternalID(owner);
    157 //                will(returnValue(5));
    158 //               
    159 //                oneOf(annotationDao).addAnnotation(annotationToAdd, 5);
    160 //                will(returnValue(addedAnnotation));
    161 //           
    162 //                oneOf(permissionsDao).addAnnotationPrincipalPermission(annotationIdentifier, owner, Permission.OWNER);
    163 //                will(returnValue(1));
    164 //            }
    165 //        });
     124        mockery.checking(new Expectations() {
     125            {
     126                oneOf(daoDispatcher).getUserInternalIdentifier(with(aNonNull(UserIdentifier.class)));
     127                will(returnValue(5));
     128               
     129                oneOf(daoDispatcher).addUsersAnnotation(annotationToAdd, 5);
     130                will(returnValue(1));
     131            }
     132        });
    166133       
    167134       
     
    173140        JAXBElement<Annotation> result = annotationResource.createAnnotation(annotationToAdd);
    174141        assertEquals(String.valueOf(5), result.getValue().getOwner().getRef());
    175         assertEquals(annotationIdentifier.toString(), result.getValue().getURI());
    176        
     142        assertFalse(null == result.getValue().getURI());
    177143       
    178144    }
Note: See TracChangeset for help on using the changeset viewer.