Changeset 3168


Ignore:
Timestamp:
07/19/13 15:23:58 (11 years ago)
Author:
olhsha
Message:

Refactored AnnotationsTest? and NotebooksTest?. by adding their common parent ResourceTest?. Implementing the whole "vertical" for DELETE annotations/<aid>

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
1 added
9 edited
1 moved

Legend:

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

    r3137 r3168  
    3131    public static final int USER_HASH_PARAM_1 =  5;
    3232    public static final int USER_HASH_PARAM_2 =  19;
    33    
     33    public static final String regExpIdentifier = "[a-zA-Z0-9_-]*";
    3434}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java

    r3167 r3168  
    6666     */
    6767   
    68     public int deleteNotebook(Number annotationId) throws SQLException;
     68    public int deleteAnnotation(Number annotationId) throws SQLException;
    6969
    7070}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java

    r3167 r3168  
    223223     
    224224     
    225      public int deleteNotebook(Number annotationId) throws SQLException{
     225     public int deleteAnnotation(Number annotationId) throws SQLException{
    226226        String sqlAnnotation = "DELETE FROM " + annotationTableName + " where "+annotation_id + " = ?";
    227227        //String sqSources = "DELETE FROM " + sourceTableName + " where "+ notebook_id +"= ?";
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r3154 r3168  
    1818package eu.dasish.annotation.backend.rest;
    1919
     20import eu.dasish.annotation.backend.BackendConstants;
    2021import eu.dasish.annotation.backend.dao.AnnotationDao;
    2122import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
     
    2324import eu.dasish.annotation.schema.ObjectFactory;
    2425import java.sql.SQLException;
     26import javax.ws.rs.DELETE;
    2527import javax.ws.rs.GET;
    2628import javax.ws.rs.Path;
     
    4547    @GET
    4648    @Produces(MediaType.TEXT_XML)
    47     @Path("{annotationid: [a-zA-Z0-9_-]*}")
     49    @Path("{annotationid: "+BackendConstants.regExpIdentifier+"}")
    4850    public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException{
    4951        final Annotation annotation = annotationDao.getAnnotation(annotationDao.getAnnotationID(new AnnotationIdentifier(annotationIdentifier)));
     
    5153    }
    5254   
     55    @DELETE
     56    @Path("{annotationid: "+BackendConstants.regExpIdentifier+"}")
     57    /*
     58     Delete _aid_. The related sources that are not related to other annotations must be deleted as well (TODO)
     59     */
     60    public String deleteAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException{
     61        return Integer.toString(annotationDao.deleteAnnotation(annotationDao.getAnnotationID(new AnnotationIdentifier(annotationIdentifier))));
     62    }
    5363}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java

    r3152 r3168  
    4545    public static final String _TEST_ANNOT_3_EXT = "00000000-0000-0000-0000-000000000023";
    4646    public static final String _TEST_ANNOT_4_EXT_NOT_IN_THE_DB = "00000000-0000-0000-0000-000000000024";
     47    public static final String _TEST_ANNOT_5_EXT_TO_BE_DELETED = "00000000-0000-0000-0000-000000000025";
    4748   
    4849    public static final int _TEST_ANNOT_1_INT = 21;
    4950    public static final int _TEST_ANNOT_2_INT = 22;
    50     public static final int _TEST_ANNOT_3_INT = 23;
     51    public static final int _TEST_ANNOT_3_INT = 23;   
    5152    public static final int _TEST_ANNOT_4_INT_NOT_IN_THE_DB = 24;
     53    public static final int _TEST_ANNOT_5_INT_TO_BE_DELETED = 25;
    5254   
    5355    public static final String _TEST_ANNOT_1_HEADLINE = "Sagrada Famiglia";
     
    6163    public static final String _TEST_ANNOT_1_BODY = "<html><body>some html 1</body></html>";
    6264   
     65    public static final String annotaiontoDeleteInDB="INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (25, 111, 'Annotation to delete','<html><body>some html 4</body></html>', '00000000-0000-0000-0000-000000000025');";
     66   
    6367}
    6468
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java

    r3152 r3168  
    2020import eu.dasish.annotation.backend.TestBackendConstants;
    2121import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
     22import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    2223import eu.dasish.annotation.schema.Annotation;
    2324import eu.dasish.annotation.schema.AnnotationInfo;
     
    2627import java.util.ArrayList;
    2728import java.util.List;
     29import java.util.UUID;
    2830import static org.junit.Assert.*;
    2931import org.junit.Test;
     
    155157    }
    156158   
     159    /**
     160     * Test of deletAnnotation method, of class JdbcAnnotationDao.
     161     */
     162    @Test
     163    public void testDeleteAnnotation() throws SQLException{
     164        System.out.println("deleteAnnotation");       
     165        int result = jdbcAnnotationDao.deleteAnnotation(TestBackendConstants._TEST_ANNOT_5_INT_TO_BE_DELETED);
     166        assertEquals(1, result);
     167        // now, try to delete the same annotation one more time
     168        // if it has been already deleted then the method under testing should return 0
     169        result = jdbcAnnotationDao.deleteAnnotation(TestBackendConstants._TEST_ANNOT_5_INT_TO_BE_DELETED);
     170        assertEquals(0, result);
     171    }
     172   
    157173}
     174
     175
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r3154 r3168  
    2323import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
    2424import eu.dasish.annotation.schema.Annotation;
    25 import eu.dasish.annotation.schema.ObjectFactory;
     25import java.sql.SQLException;
    2626import javax.xml.bind.JAXBElement;
    2727import org.jmock.Expectations;
     
    4444   
    4545    @Autowired
    46     private Mockery mockeryAnnotDao;
     46    private Mockery mockery;
    4747    @Autowired
    4848    private AnnotationDao annotationDao;
     
    5858     */
    5959    @Test
    60     public void testGetAnnotation() throws Exception {
     60    public void testGetAnnotation() throws SQLException {
    6161        System.out.println("getAnnotation");
    6262        final String annotationIdentifier= TestBackendConstants._TEST_ANNOT_1_EXT;
     
    6464        final Annotation expectedAnnotation = (new TestInstances()).getAnnotationOne();
    6565        // the result of the mocking chain is the same as the expected annotation.       
    66         mockeryAnnotDao.checking(new Expectations() {
     66        mockery.checking(new Expectations() {
    6767            {
    6868                oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(annotationIdentifier));               
     
    7777        assertEquals(expectedAnnotation, result.getValue());
    7878    }
     79   
     80    /**
     81     * Test of deleteAnnotation method, of class AnnotationResource.
     82     */
     83    @Test
     84    public void testDeleteAnnotation() throws SQLException {
     85        System.out.println("deleteAnnotation");
     86        mockery.checking(new Expectations() {
     87            {
     88                oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT_TO_BE_DELETED));               
     89                will(returnValue(TestBackendConstants._TEST_ANNOT_5_INT_TO_BE_DELETED));
     90               
     91                oneOf(annotationDao).deleteAnnotation(TestBackendConstants._TEST_ANNOT_5_INT_TO_BE_DELETED);
     92                will(returnValue(1));
     93            }
     94        });
     95       
     96        String result = annotationResource.deleteAnnotation(TestBackendConstants._TEST_ANNOT_5_EXT_TO_BE_DELETED);
     97        assertEquals("1", result);
     98       
     99         // now, try to delete the same annotation one more time
     100        // if it has been already deleted then the method under testing should return 0
     101        mockery.checking(new Expectations() {
     102            {
     103                oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT_TO_BE_DELETED));               
     104                will(returnValue(TestBackendConstants._TEST_ANNOT_5_INT_TO_BE_DELETED));
     105               
     106                oneOf(annotationDao).deleteAnnotation(TestBackendConstants._TEST_ANNOT_5_INT_TO_BE_DELETED);
     107                will(returnValue(0));
     108            }
     109        });
     110       
     111        result = annotationResource.deleteAnnotation(TestBackendConstants._TEST_ANNOT_5_EXT_TO_BE_DELETED);
     112        assertEquals("0", result);
     113    }
    79114}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java

    r3154 r3168  
    1919
    2020import com.sun.jersey.api.client.ClientResponse;
    21 import com.sun.jersey.api.client.GenericType;
    22 import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
    23 import com.sun.jersey.test.framework.JerseyTest;
    24 import com.sun.jersey.test.framework.WebAppDescriptor;
    2521import eu.dasish.annotation.backend.TestBackendConstants;
    2622import eu.dasish.annotation.backend.dao.AnnotationDao;
    2723import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier;
     24import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
    2825import eu.dasish.annotation.schema.Annotation;
    29 import eu.dasish.annotation.schema.NotebookInfos;
    3026import eu.dasish.annotation.schema.ObjectFactory;
    3127import java.sql.SQLException;
     28import java.util.UUID;
    3229import javax.ws.rs.core.MediaType;
    3330import org.jmock.Expectations;
    34 import org.jmock.Mockery;
    3531import org.junit.Test;
    36 import org.springframework.web.context.ContextLoaderListener;
    37 import org.springframework.web.context.WebApplicationContext;
    3832import static org.junit.Assert.*;
    3933/**
     
    4135 * @author olhsha
    4236 */
    43 public class AnnotationsURLTest extends JerseyTest{
     37public class AnnotationsTest extends ResourcesTest{
    4438   
    45     private Mockery mockery;
    4639    private AnnotationDao annotationDao;
    4740   
    48     public AnnotationsURLTest() {
    49        
    50         super(new WebAppDescriptor.Builder(AnnotationResource.class.getPackage().getName())
    51                 .servletClass(SpringServlet.class)
    52                 .contextParam("contextConfigLocation", "classpath*:spring-test-config/**/*.xml")
    53                 .contextListenerClass(ContextLoaderListener.class)
    54                 .build());
    55 
    56         // Get the web application context that has been instantiated in the Grizzly container
    57         final WebApplicationContext webAppContext = ContextLoaderListener.getCurrentWebApplicationContext();
    58 
    59         // Get the context and mock objects from the context by their type
    60         mockery = webAppContext.getBean(Mockery.class);
     41    public AnnotationsTest() {
     42        super(AnnotationResource.class.getPackage().getName());
    6143        annotationDao = webAppContext.getBean(AnnotationDao.class);
    6244    }
     
    9678        assertEquals(testAnnotation.getTimeStamp(), entity.getTimeStamp());
    9779        assertEquals(testAnnotation.getURI(), entity.getURI());
    98     }   
     80    } 
     81   
     82     /**
     83     * Test of deleteAnnotation method, of class AnnotationResource. Delete <nid>.
     84     * DELETE api/annotations/<aid>
     85     */
     86    @Test
     87    public void testDeleteAnnotation() throws SQLException{
     88        System.out.println("testDeleteAnnotation");
     89       
     90        mockery.checking(new Expectations() {
     91            {
     92                oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT_TO_BE_DELETED));               
     93                will(returnValue(TestBackendConstants._TEST_ANNOT_5_INT_TO_BE_DELETED));
     94               
     95                oneOf(annotationDao).deleteAnnotation(TestBackendConstants._TEST_ANNOT_5_INT_TO_BE_DELETED);
     96                will(returnValue(1));
     97            }
     98        });
     99       
     100        final String requestUrl = "annotations/" + TestBackendConstants._TEST_ANNOT_5_EXT_TO_BE_DELETED;
     101        System.out.println("requestUrl: " + requestUrl);
     102        ClientResponse response = resource().path(requestUrl).delete(ClientResponse.class);
     103        assertEquals(200, response.getStatus());
     104        assertEquals("1", response.getEntity(String.class));
     105       
     106         // now, try to delete the same annotation one more time
     107        // if it has been already deleted then the method under testing should return 0
     108       
     109        mockery.checking(new Expectations() {
     110            {
     111                oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_5_EXT_TO_BE_DELETED));               
     112                will(returnValue(TestBackendConstants._TEST_ANNOT_5_INT_TO_BE_DELETED));
     113               
     114                oneOf(annotationDao).deleteAnnotation(TestBackendConstants._TEST_ANNOT_5_INT_TO_BE_DELETED);
     115                will(returnValue(0));
     116            }
     117        });
     118       
     119        response = resource().path(requestUrl).delete(ClientResponse.class);
     120        assertEquals(200, response.getStatus());
     121        assertEquals("0", response.getEntity(String.class));
     122    }
    99123}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebooksTest.java

    r3110 r3168  
    2121import com.sun.jersey.api.client.GenericType;
    2222import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
    23 import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
    24 import com.sun.jersey.test.framework.JerseyTest;
    25 import com.sun.jersey.test.framework.WebAppDescriptor;
    2623import eu.dasish.annotation.backend.dao.NotebookDao;
    2724import eu.dasish.annotation.backend.identifiers.NotebookIdentifier;
     
    3835import org.jmock.Expectations;
    3936import static org.jmock.Expectations.returnValue;
    40 import org.jmock.Mockery;
    4137import org.junit.Test;
    4238import static org.junit.Assert.*;
    4339import org.junit.Ignore;
    44 import org.springframework.web.context.ContextLoaderListener;
    45 import org.springframework.web.context.WebApplicationContext;
    4640
    4741/**
     
    5044 * @author Peter Withers <peter.withers@mpi.nl>
    5145 */
    52 public class NotebooksTest extends JerseyTest {
    53 
    54     private Mockery mockery;
     46public class NotebooksTest extends ResourcesTest {
     47
    5548    private NotebookDao notebookDao;
    5649
    5750    public NotebooksTest() {
    58         super(new WebAppDescriptor.Builder(NotebookResource.class.getPackage().getName())
    59                 .servletClass(SpringServlet.class)
    60                 .contextParam("contextConfigLocation", "classpath*:spring-test-config/**/*.xml")
    61                 .contextListenerClass(ContextLoaderListener.class)
    62                 .build());
    63 
    64         // Get the web application context that has been instantiated in the Grizzly container
    65         final WebApplicationContext webAppContext = ContextLoaderListener.getCurrentWebApplicationContext();
    66 
    67         // Get the context and mock objects from the context by their type
    68         mockery = webAppContext.getBean(Mockery.class);
     51        super(NotebookResource.class.getPackage().getName());
    6952        notebookDao = webAppContext.getBean(NotebookDao.class);
    7053    }
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql

    r3152 r3168  
    3939INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (22, 112, 'Gaudi','<html><body>some html 2 </body></html>', '00000000-0000-0000-0000-000000000022');
    4040INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (23, 113, 'Art Nuveau','<html><body>some html 3</body></html>', '00000000-0000-0000-0000-000000000023');
     41INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (25, 111, 'Annotation to delete','<html><body>some html 4</body></html>', '00000000-0000-0000-0000-000000000025');
     42
     43
    4144
    4245INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (11,21);
Note: See TracChangeset for help on using the changeset viewer.