Changeset 4176


Ignore:
Timestamp:
12/10/13 17:36:30 (10 years ago)
Author:
olhsha
Message:

The integrity unit test is fully repared. Add tests for all rest-methods

File:
1 edited

Legend:

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

    r4175 r4176  
    2121import com.sun.jersey.api.client.WebResource;
    2222import com.sun.jersey.api.client.WebResource.Builder;
    23 import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
    2423import com.sun.jersey.core.util.Base64;
    2524import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
     
    3130import eu.dasish.annotation.backend.dao.impl.JdbcResourceDaoTest;
    3231import eu.dasish.annotation.schema.Annotation;
     32import eu.dasish.annotation.schema.AnnotationBody;
     33import eu.dasish.annotation.schema.AnnotationBody.TextBody;
    3334import eu.dasish.annotation.schema.ObjectFactory;
    3435import eu.dasish.annotation.schema.ResponseBody;
     
    4041import java.net.URL;
    4142import java.sql.SQLException;
    42 import java.util.ArrayList;
    43 import java.util.List;
    4443import java.util.Scanner;
    4544import java.util.UUID;
    46 import javax.servlet.http.HttpServletRequest;
    47 import javax.ws.rs.core.Context;
    4845import javax.ws.rs.core.HttpHeaders;
    4946import javax.ws.rs.core.MediaType;
     
    5451import static org.junit.Assert.*;
    5552import org.junit.Before;
    56 import org.junit.Ignore;
    5753import org.junit.runner.RunWith;
    5854import org.springframework.beans.factory.annotation.Autowired;
    5955import org.springframework.dao.DataAccessException;
    6056import org.springframework.jdbc.core.JdbcTemplate;
    61 import org.springframework.mock.web.MockHttpServletRequest;
    6257import org.springframework.test.context.ContextConfiguration;
    6358import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
     
    157152        System.out.println("requestUrl: " + requestUrl);
    158153       
    159         Builder responseBuilder = getAuthenticatedResource(resource().path(requestUrl)).accept(MediaType.TEXT_XML);
    160        
     154        Builder responseBuilder = getAuthenticatedResource(resource().path(requestUrl)).accept(MediaType.TEXT_XML);       
    161155        ClientResponse response = responseBuilder.get(ClientResponse.class);       
    162156       
     
    185179     */
    186180    @Test
    187     @Ignore
    188181    public void testDeleteAnnotation() throws SQLException {
    189182        System.out.println("testDeleteAnnotation");
    190         //final Number annotationID = daoDispatcher.getAnnotationInternalIdentifier(UUID.fromString(UUID));
    191         //int[] resultDelete = daoDispatcher.deleteAnnotation(annotationID);
    192        
    193         final int[] mockDelete = new int[4];
    194         mockDelete[0] = 1; // # deleted annotations
    195         mockDelete[3] = 1; // # deleted annotation_prinipal_permissions
    196         mockDelete[2] = 2; // # deleted  annotations_target_Targets, (5,3), (5,4)
    197         mockDelete[3] = 1; // # deletd Targets, 4
    198        
    199         final String baseURI = this.getBaseURI().toString();
    200        
    201         final String requestUrl = "annotations/" + TestBackendConstants._TEST_ANNOT_5_EXT;
     183        String externalIDstring  =  TestBackendConstants._TEST_ANNOT_5_EXT;
     184        final String requestUrl = "annotations/" + externalIDstring;
    202185        System.out.println("requestUrl: " + requestUrl);
    203         ClientResponse response = resource().path(requestUrl).delete(ClientResponse.class);
     186       
     187        Builder responseBuilder = getAuthenticatedResource(resource().path(requestUrl)).accept(MediaType.TEXT_XML);       
     188        ClientResponse response = responseBuilder.delete(ClientResponse.class);   
    204189        assertEquals(200, response.getStatus());
    205190        assertEquals("1 annotation(s) deleted.", response.getEntity(String.class));
    206        
    207        
    208191    }
    209192
     
    213196     */
    214197    @Test
    215     @Ignore
    216198    public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException, DatatypeConfigurationException, Exception {
    217199        System.out.println("test createAnnotation");
    218         // Peter's workaround on absence of "ObjectFactory.create... for annotations       
    219         //final JAXBElement<Annotation> jaxbElement = new JAXBElement<Annotation>(new QName("http://www.dasish.eu/ns/addit", "annotation"), Annotation.class, null, annotationToAdd);
    220        
    221         final String ownerString = "5";
    222         final Number ownerID = 5;
    223         final Number newAnnotationID = 6;
    224        
    225         ResponseBody responseBody = new ResponseBody();
    226         final JAXBElement<ResponseBody> jaxbElement = (new ObjectFactory()).createResponseBody(responseBody);
    227         responseBody.setPermissions(null);
    228         final Annotation addedAnnotation = new Annotation();
    229         responseBody.setAnnotation(addedAnnotation);
    230         responseBody.setActionList(null);
    231        
    232         TargetInfoList TargetInfoList = new TargetInfoList();
    233         addedAnnotation.setTargets(TargetInfoList);
    234         addedAnnotation.setOwnerRef(ownerString);
    235         addedAnnotation.setURI(TestBackendConstants._TEST_SERVLET_URI_annotations + UUID.randomUUID().toString());       
    236         addedAnnotation.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar(TestBackendConstants._TEST_ANNOT_2_TIME_STAMP));       
    237         TargetInfo TargetInfo = new TargetInfo();
    238         TargetInfo.setLink("google.nl");
    239         TargetInfo.setRef(UUID.randomUUID().toString());
    240         TargetInfo.setVersion("vandaag");
    241         TargetInfoList.getTargetInfo().add(TargetInfo);       
    242        
    243         final List<Number> Targets = new ArrayList<Number>();
    244         Targets.add(6);
    245        
    246         final String baseURI = this.getBaseURI().toString();
    247        
    248         final String requestUrl = "annotations";
    249         System.out.println("requestUrl: " + requestUrl);
    250         ClientResponse response = resource().path(requestUrl).type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML).post(ClientResponse.class, jaxbElement);
     200        System.out.println("POST "+resource().getURI().toString()+"annotations/");
     201        final String ownerString = resource().getURI().toString()+"users/"+TestBackendConstants._TEST_USER_5_EXT_ID;
     202        final Annotation annotationToAdd = new Annotation();
     203        final JAXBElement<Annotation> jaxbElement = (new ObjectFactory()).createAnnotation(annotationToAdd);
     204        annotationToAdd.setPermissions(null);
     205        annotationToAdd.setOwnerRef(ownerString);
     206        annotationToAdd.setURI(resource().getURI().toString()+"annotations/"+ UUID.randomUUID().toString());       
     207        annotationToAdd.setLastModified(DatatypeFactory.newInstance().newXMLGregorianCalendar(TestBackendConstants._TEST_ANNOT_2_TIME_STAMP));       
     208       
     209        TargetInfoList targetInfoList = new TargetInfoList();
     210        annotationToAdd.setTargets(targetInfoList);
     211        TargetInfo targetInfo = new TargetInfo();
     212        targetInfo.setLink("http://nl.wikipedia.org/wiki/Viktor_Janoekovytsj#Biografie");
     213        targetInfo.setRef(resource().getURI().toString()+"targets/"+UUID.randomUUID().toString());
     214        targetInfo.setVersion("5 apr 2013 om 18:42");
     215        targetInfoList.getTargetInfo().add(targetInfo);       
     216       
     217        AnnotationBody annotationBody = new AnnotationBody();
     218        annotationBody.setXmlBody(null);
     219        TextBody textBody = new TextBody();
     220        textBody.setMimeType("plain/text");
     221        textBody.setValue("yanuk - zek");
     222        annotationBody.setTextBody(textBody);
     223        annotationToAdd.setBody(annotationBody);
     224     
     225        Builder responseBuilder = getAuthenticatedResource(resource().path("annotations/")).type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML);       
     226        ClientResponse response = responseBuilder.post(ClientResponse.class, jaxbElement);
    251227        assertEquals(200, response.getStatus());
    252228       
    253229        ResponseBody entity = response.getEntity(ResponseBody.class);       
    254230        Annotation entityA = entity.getAnnotation();
    255         assertEquals(addedAnnotation.getBody(), entityA.getBody());
    256         assertEquals(addedAnnotation.getHeadline(), entityA.getHeadline());
    257         assertEquals(addedAnnotation.getPermissions(), entityA.getPermissions());
    258         assertEquals(addedAnnotation.getTargets().getTargetInfo().get(0).getLink(), entityA.getTargets().getTargetInfo().get(0).getLink());
    259         assertEquals(addedAnnotation.getTargets().getTargetInfo().get(0).getRef(), entityA.getTargets().getTargetInfo().get(0).getRef());
    260         assertEquals(addedAnnotation.getTargets().getTargetInfo().get(0).getVersion(), entityA.getTargets().getTargetInfo().get(0).getVersion());
    261         assertEquals(addedAnnotation.getLastModified(), entityA.getLastModified());
    262         assertEquals(addedAnnotation.getOwnerRef(), entityA.getOwnerRef());
     231        assertEquals(annotationToAdd.getBody().getTextBody().getValue(), entityA.getBody().getTextBody().getValue());
     232        assertEquals(annotationToAdd.getBody().getTextBody().getMimeType(), entityA.getBody().getTextBody().getMimeType());
     233        assertEquals(annotationToAdd.getHeadline(), entityA.getHeadline());
     234        assertEquals(1, entityA.getPermissions().getUserWithPermission().size());
     235        assertEquals("owner", entityA.getPermissions().getUserWithPermission().get(0).getPermission().value());
     236        assertEquals(annotationToAdd.getOwnerRef(), entityA.getPermissions().getUserWithPermission().get(0).getRef());
     237        assertEquals(annotationToAdd.getTargets().getTargetInfo().get(0).getLink(), entityA.getTargets().getTargetInfo().get(0).getLink());
     238        // new ref is generated
     239        //assertEquals(annotationToAdd.getTargets().getTargetInfo().get(0).getRef(), entityA.getTargets().getTargetInfo().get(0).getRef());
     240        assertEquals(annotationToAdd.getTargets().getTargetInfo().get(0).getVersion(), entityA.getTargets().getTargetInfo().get(0).getVersion());
     241        //last modified is updated by the server
     242        //assertEquals(annotationToAdd.getLastModified(), entityA.getLastModified());
     243        assertEquals(annotationToAdd.getOwnerRef(), entityA.getOwnerRef());
    263244    }
    264245   
Note: See TracChangeset for help on using the changeset viewer.