Changeset 3168
- Timestamp:
- 07/19/13 15:23:58 (11 years ago)
- 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 31 31 public static final int USER_HASH_PARAM_1 = 5; 32 32 public static final int USER_HASH_PARAM_2 = 19; 33 33 public static final String regExpIdentifier = "[a-zA-Z0-9_-]*"; 34 34 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r3167 r3168 66 66 */ 67 67 68 public int delete Notebook(Number annotationId) throws SQLException;68 public int deleteAnnotation(Number annotationId) throws SQLException; 69 69 70 70 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3167 r3168 223 223 224 224 225 public int delete Notebook(Number annotationId) throws SQLException{225 public int deleteAnnotation(Number annotationId) throws SQLException{ 226 226 String sqlAnnotation = "DELETE FROM " + annotationTableName + " where "+annotation_id + " = ?"; 227 227 //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 18 18 package eu.dasish.annotation.backend.rest; 19 19 20 import eu.dasish.annotation.backend.BackendConstants; 20 21 import eu.dasish.annotation.backend.dao.AnnotationDao; 21 22 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; … … 23 24 import eu.dasish.annotation.schema.ObjectFactory; 24 25 import java.sql.SQLException; 26 import javax.ws.rs.DELETE; 25 27 import javax.ws.rs.GET; 26 28 import javax.ws.rs.Path; … … 45 47 @GET 46 48 @Produces(MediaType.TEXT_XML) 47 @Path("{annotationid: [a-zA-Z0-9_-]*}")49 @Path("{annotationid: "+BackendConstants.regExpIdentifier+"}") 48 50 public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException{ 49 51 final Annotation annotation = annotationDao.getAnnotation(annotationDao.getAnnotationID(new AnnotationIdentifier(annotationIdentifier))); … … 51 53 } 52 54 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 } 53 63 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java
r3152 r3168 45 45 public static final String _TEST_ANNOT_3_EXT = "00000000-0000-0000-0000-000000000023"; 46 46 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"; 47 48 48 49 public static final int _TEST_ANNOT_1_INT = 21; 49 50 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; 51 52 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; 52 54 53 55 public static final String _TEST_ANNOT_1_HEADLINE = "Sagrada Famiglia"; … … 61 63 public static final String _TEST_ANNOT_1_BODY = "<html><body>some html 1</body></html>"; 62 64 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 63 67 } 64 68 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3152 r3168 20 20 import eu.dasish.annotation.backend.TestBackendConstants; 21 21 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 22 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; 22 23 import eu.dasish.annotation.schema.Annotation; 23 24 import eu.dasish.annotation.schema.AnnotationInfo; … … 26 27 import java.util.ArrayList; 27 28 import java.util.List; 29 import java.util.UUID; 28 30 import static org.junit.Assert.*; 29 31 import org.junit.Test; … … 155 157 } 156 158 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 157 173 } 174 175 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r3154 r3168 23 23 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 24 24 import eu.dasish.annotation.schema.Annotation; 25 import eu.dasish.annotation.schema.ObjectFactory;25 import java.sql.SQLException; 26 26 import javax.xml.bind.JAXBElement; 27 27 import org.jmock.Expectations; … … 44 44 45 45 @Autowired 46 private Mockery mockery AnnotDao;46 private Mockery mockery; 47 47 @Autowired 48 48 private AnnotationDao annotationDao; … … 58 58 */ 59 59 @Test 60 public void testGetAnnotation() throws Exception {60 public void testGetAnnotation() throws SQLException { 61 61 System.out.println("getAnnotation"); 62 62 final String annotationIdentifier= TestBackendConstants._TEST_ANNOT_1_EXT; … … 64 64 final Annotation expectedAnnotation = (new TestInstances()).getAnnotationOne(); 65 65 // the result of the mocking chain is the same as the expected annotation. 66 mockery AnnotDao.checking(new Expectations() {66 mockery.checking(new Expectations() { 67 67 { 68 68 oneOf(annotationDao).getAnnotationID(new AnnotationIdentifier(annotationIdentifier)); … … 77 77 assertEquals(expectedAnnotation, result.getValue()); 78 78 } 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 } 79 114 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r3154 r3168 19 19 20 20 import 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;25 21 import eu.dasish.annotation.backend.TestBackendConstants; 26 22 import eu.dasish.annotation.backend.dao.AnnotationDao; 27 23 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 24 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; 28 25 import eu.dasish.annotation.schema.Annotation; 29 import eu.dasish.annotation.schema.NotebookInfos;30 26 import eu.dasish.annotation.schema.ObjectFactory; 31 27 import java.sql.SQLException; 28 import java.util.UUID; 32 29 import javax.ws.rs.core.MediaType; 33 30 import org.jmock.Expectations; 34 import org.jmock.Mockery;35 31 import org.junit.Test; 36 import org.springframework.web.context.ContextLoaderListener;37 import org.springframework.web.context.WebApplicationContext;38 32 import static org.junit.Assert.*; 39 33 /** … … 41 35 * @author olhsha 42 36 */ 43 public class Annotations URLTest extends JerseyTest{37 public class AnnotationsTest extends ResourcesTest{ 44 38 45 private Mockery mockery;46 39 private AnnotationDao annotationDao; 47 40 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()); 61 43 annotationDao = webAppContext.getBean(AnnotationDao.class); 62 44 } … … 96 78 assertEquals(testAnnotation.getTimeStamp(), entity.getTimeStamp()); 97 79 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 } 99 123 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebooksTest.java
r3110 r3168 21 21 import com.sun.jersey.api.client.GenericType; 22 22 import 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;26 23 import eu.dasish.annotation.backend.dao.NotebookDao; 27 24 import eu.dasish.annotation.backend.identifiers.NotebookIdentifier; … … 38 35 import org.jmock.Expectations; 39 36 import static org.jmock.Expectations.returnValue; 40 import org.jmock.Mockery;41 37 import org.junit.Test; 42 38 import static org.junit.Assert.*; 43 39 import org.junit.Ignore; 44 import org.springframework.web.context.ContextLoaderListener;45 import org.springframework.web.context.WebApplicationContext;46 40 47 41 /** … … 50 44 * @author Peter Withers <peter.withers@mpi.nl> 51 45 */ 52 public class NotebooksTest extends JerseyTest { 53 54 private Mockery mockery; 46 public class NotebooksTest extends ResourcesTest { 47 55 48 private NotebookDao notebookDao; 56 49 57 50 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()); 69 52 notebookDao = webAppContext.getBean(NotebookDao.class); 70 53 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql
r3152 r3168 39 39 INSERT 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'); 40 40 INSERT 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'); 41 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'); 42 43 41 44 42 45 INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (11,21);
Note: See TracChangeset
for help on using the changeset viewer.