Changeset 3453


Ignore:
Timestamp:
08/21/13 13:02:59 (11 years ago)
Author:
olhsha
Message:

Tests: AnnotationTest? and Annotations went well for all three main methods: get, delete and add Annotation

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

Legend:

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

    r3452 r3453  
    8787    public JAXBElement<Annotation> createAnnotation(Annotation annotation) throws SQLException {
    8888        String remoteUser = httpServletRequest.getRemoteUser();
    89         Number userID = null;
    90         if (remoteUser != null) {
    91             userID = daoDispatcher.getUserInternalIdentifier(new UserIdentifier(remoteUser));
    92         }
     89        Number userID = daoDispatcher.getUserInternalIdentifier(new UserIdentifier(remoteUser));
    9390        Number newAnnotationID =  daoDispatcher.addUsersAnnotation(annotation, userID);
    9491        Annotation newAnnotation = daoDispatcher.getAnnotation(newAnnotationID);
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestInstances.java

    r3347 r3453  
    3535    final private Annotation _annotationOne;
    3636    final private Annotation _annotationToAdd;
    37     final private Annotation _annotationToAddNewSource;
    3837   
    3938    public TestInstances(){
    4039        _annotationOne = makeAnnotationOne();
    41         _annotationToAdd = makeAnnotationToAdd();
    42         _annotationToAddNewSource = makeAnnotationToAddNewSource();       
     40        _annotationToAdd = makeAnnotationToAdd();   
    4341    }
    4442   
     
    6664    }
    6765   
    68     private Annotation makeAnnotationToAddNewSource(){
    69        Annotation result = makeAnnotation(TestBackendConstants._TEST_ANNOT_TO_ADD_NEW_SOURCE_BODY, TestBackendConstants._TEST_ANNOT_TO_ADD_NEW_SOURCE_HEADLINE, 5);
    70        
    71        NewSourceInfo newSourceInfo =  new NewSourceInfo();
    72        newSourceInfo.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);
    73        newSourceInfo.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);
    74        // TODO: so far, the version is the external version id generated when a version is added
    75        // because for now the version is used to keep external id of the version, not is human-friendly headline
    76        // fix it by adding external Id to the version
    77        newSourceInfo.setVersion(null);
    78        
    79        NewOrExistingSourceInfo noeSourceInfo =  new NewOrExistingSourceInfo();
    80        noeSourceInfo.setNewSource(newSourceInfo);
    81        NewOrExistingSourceInfos noeSourceInfos =  new NewOrExistingSourceInfos();
    82        noeSourceInfos.getTarget().add(noeSourceInfo);
    83        result.setTargetSources(noeSourceInfos);
    84        
    85        return result;
    86     }
    87    
    88    
    89     // so far tests only adding annot with existing sources!!!
    90     // TODO: add non-existing sources
     66
    9167    private Annotation makeAnnotation(String bodyTxt, String headline, int ownerId){
    9268        Annotation result = new Annotation();
     
    10884    }
    10985   
    110     //private
    111    
    11286   
    11387    public Annotation getAnnotationOne(){
     
    11993    }
    12094   
    121    public Annotation getAnnotationToAddNewSource(){
    122         return _annotationToAddNewSource;
    123     }
    12495   
    12596}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r3452 r3453  
    140140        owner.setRef(ownerString);
    141141        addedAnnotation.setOwner(owner);
    142         addedAnnotation.setURI((new AnnotationIdentifier()).toString());
     142        addedAnnotation.setURI((new AnnotationIdentifier()).toString());       
     143        addedAnnotation.setTimeStamp(Helpers.setXMLGregorianCalendar(Timestamp.valueOf("2013-08-12 11:25:00.383000")));
    143144       
    144         addedAnnotation.setTimeStamp(Helpers.setXMLGregorianCalendar(Timestamp.valueOf("2013-08-12 11:25:00.383000")));
    145145        mockery.checking(new Expectations() {
    146146            {
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java

    r3452 r3453  
    2020import eu.dasish.annotation.backend.dao.DaoDispatcher;
    2121import com.sun.jersey.api.client.ClientResponse;
     22import com.sun.jersey.api.client.GenericType;
    2223import eu.dasish.annotation.backend.Helpers;
    2324import eu.dasish.annotation.backend.TestBackendConstants;
    24 import eu.dasish.annotation.backend.TestInstances;
    2525import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2626import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2727import eu.dasish.annotation.schema.Annotation;
     28import eu.dasish.annotation.schema.AnnotationBody;
    2829import eu.dasish.annotation.schema.ObjectFactory;
    2930import eu.dasish.annotation.schema.ResourceREF;
     
    5657     */
    5758    @Test
    58     public void testGetAnnotation() throws SQLException{
     59    public void testGetAnnotation() throws SQLException, DatatypeConfigurationException{
    5960        System.out.println("testGetAnnotation");
    6061        final String annotationIdentifier= TestBackendConstants._TEST_ANNOT_2_EXT;
    6162        final int annotationID = 2;
    62         final Annotation testAnnotation = new ObjectFactory().createAnnotation();
    63         final Annotation expectedAnnotation = (new TestInstances()).getAnnotationOne();
     63        final Annotation testAnnotation = new Annotation();
     64        ResourceREF owner = new ResourceREF();
     65        owner.setRef("5");
     66        testAnnotation.setOwner(owner);
     67        testAnnotation.setURI((new AnnotationIdentifier()).toString());
     68        testAnnotation.setTimeStamp(Helpers.setXMLGregorianCalendar(Timestamp.valueOf("2013-08-12 11:25:00.383000")));
    6469       
    6570        //final Number annotationID = daoDispatcher.getAnnotationInternalIdentifier(new AnnotationIdentifier(annotationIdentifier));
     
    7176               
    7277                oneOf(daoDispatcher).getAnnotation(annotationID);               
    73                 will(returnValue(expectedAnnotation));
     78                will(returnValue(testAnnotation));
    7479            }
    7580        });
     
    8287        assertEquals(testAnnotation.getBody(), entity.getBody());
    8388        assertEquals(testAnnotation.getHeadline(), entity.getHeadline());
    84         assertEquals(testAnnotation.getOwner(), entity.getOwner());
     89        assertEquals(testAnnotation.getOwner().getRef(), entity.getOwner().getRef());
    8590        assertEquals(testAnnotation.getPermissions(), entity.getPermissions());
    8691        assertEquals(testAnnotation.getTargetSources(), entity.getTargetSources());
     
    128133    public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException, DatatypeConfigurationException{
    129134        System.out.println("test createAnnotation");
    130         final Annotation annotationToAdd = new ObjectFactory().createAnnotation();
     135        // Peter's workaround on absence of "ObjectFactory.create... for annotations
     136
     137        final Annotation annotationToAdd = new Annotation();
     138
     139        final JAXBElement<Annotation> jaxbElement = new JAXBElement<Annotation>(new QName("http://www.dasish.eu/ns/addit", "annotation"), Annotation.class, null, annotationToAdd);
     140         //final Annotation annotToAddJB = jaxbElement.getValue();
    131141       
    132 //        Number userID = null;
    133 //        if (remoteUser != null) {
    134 //            userID = daoDispatcher.getUserInternalIdentifier(new UserIdentifier(remoteUser));
    135 //        }
    136 //        Number newAnnotationID =  daoDispatcher.addUsersAnnotation(annotation, userID);
    137 //        Annotation newAnnotation = daoDispatcher.getAnnotation(newAnnotationID);
     142          // for setting up mockery
     143        //userID = daoDispatcher.getUserInternalIdentifier(new UserIdentifier(remoteUser));
     144        //Number newAnnotationID =  daoDispatcher.addUsersAnnotation(annotation, userID);
     145        //Annotation newAnnotation = daoDispatcher.getAnnotation(newAnnotationID);
    138146        final String ownerString = "5";
    139147        final Number ownerID =  5;
     
    151159                will(returnValue(ownerID));
    152160               
    153                 oneOf(daoDispatcher).addUsersAnnotation(annotationToAdd, ownerID);
     161                //oneOf(daoDispatcher).addUsersAnnotation(annotToAddJB, ownerID);
     162                oneOf(daoDispatcher).addUsersAnnotation(with(aNonNull(Annotation.class)), with(aNonNull(Number.class)));
    154163                will(returnValue(newAnnotationID));
    155164               
     
    159168        });
    160169       
    161          // Peter's workaround on absence of "ObjectFactory.create... for annotations       
    162         final JAXBElement<Annotation> jaxbElement = new JAXBElement<Annotation>(new QName("http://www.dasish.eu/ns/addit", "annotation"), Annotation.class, null, annotationToAdd);
     170             
    163171       
    164172        final String requestUrl = "annotations";
    165173        System.out.println("requestUrl: " + requestUrl);
    166         ClientResponse response = resource().path(requestUrl).accept(MediaType.APPLICATION_XML).type(MediaType.APPLICATION_XML).post(ClientResponse.class, jaxbElement);
     174        ClientResponse response = resource().path(requestUrl).type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML).post(ClientResponse.class, jaxbElement);
    167175        assertEquals(200, response.getStatus());
    168176       
    169177        Annotation entity = response.getEntity(Annotation.class);
    170         assertEquals(annotationToAdd.getBody(), entity.getBody());
    171         assertEquals(annotationToAdd.getHeadline(), entity.getHeadline());
    172         assertEquals(annotationToAdd.getPermissions(), entity.getPermissions());
    173         assertEquals(annotationToAdd.getTargetSources(), entity.getTargetSources());
    174         assertEquals(annotationToAdd.getTimeStamp(), entity.getTimeStamp());
     178        assertEquals(addedAnnotation.getBody(), entity.getBody());
     179        assertEquals(addedAnnotation.getHeadline(), entity.getHeadline());
     180        assertEquals(addedAnnotation.getPermissions(), entity.getPermissions());
     181        assertEquals(addedAnnotation.getTargetSources(), entity.getTargetSources());
     182        assertEquals(addedAnnotation.getTimeStamp(), entity.getTimeStamp());
     183        assertEquals(addedAnnotation.getOwner().getRef(), entity.getOwner().getRef());
    175184    }
    176185}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java

    r3408 r3453  
    4747@RunWith(value = SpringJUnit4ClassRunner.class)
    4848@ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml",
    49     "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"})
     49    "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockDaoDispatcher.xml", "/spring-test-config/mockery.xml"})
    5050public class NotebookResourceTest {
    5151
Note: See TracChangeset for help on using the changeset viewer.