Changeset 3206
- Timestamp:
- 07/30/13 09:08:46 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/AnnotationDao.java
r3189 r3206 74 74 * @return annotationIdentifier of the newly added annotation; returns null if something went wrong and annotation was not added or more than one row in the annotation table was affected 75 75 */ 76 public Annotation Identifier addAnnotation(Annotation annotation);76 public Annotation addAnnotation(Annotation annotation, Number ownerID); 77 77 78 78 /** -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3189 r3206 227 227 } 228 228 229 230 ////////////////////////////////////////////// 231 /* CREATE TABLE annotation ( 232 annotation_id SERIAL UNIQUE NOT NULL, 233 external_id UUID UNIQUE NOT NULL, 234 time_stamp timestamp with time zone default now(), 235 owner_id integer, 236 headline text, 237 body_xml xml */ 238 239 229 230 231 // TODO: so far URI in the xml is the same as the external_id in the DB!! 232 // Chnage it when the decision is taken!!! 240 233 @Override 241 public AnnotationIdentifier addAnnotation(Annotation annotation) { 234 public Annotation addAnnotation(Annotation annotation, Number ownerID) { 235 236 if (annotation == null) { 237 return null; 238 } 239 242 240 try { 241 Annotation result = makeFreshCopy(annotation); 242 243 ResourceREF ownerRef = new ResourceREF(); 244 ownerRef.setRef(String.valueOf(ownerID)); 245 result.setOwner(ownerRef); 246 243 247 AnnotationIdentifier annotationIdentifier = new AnnotationIdentifier(); 248 result.setURI(annotationIdentifier.toString()); 249 244 250 Map<String, Object> params = new HashMap<String, Object>(); 245 251 params.put("externalId", annotationIdentifier.toString()); 246 params.put("timeStamp", annotation.getTimeStamp()); 247 params.put("ownerId", annotation.getOwner().getRef());252 params.put("timeStamp", annotation.getTimeStamp()); 253 params.put("ownerId", ownerID); 248 254 params.put("headline", annotation.getHeadline()); 249 255 // may be changed once we elaborate the body … … 252 258 final int affectedRows = getSimpleJdbcTemplate().update(sql, params); 253 259 if (affectedRows == 1) { 254 return annotationIdentifier;260 return result; 255 261 } 256 262 else { … … 327 333 } 328 334 335 //TODO: update when target sources and permissions are added 336 private Annotation makeFreshCopy(Annotation annotation){ 337 338 if (annotation == null) { 339 return null; 340 } 341 342 Annotation result = new Annotation(); 343 result.setBody(annotation.getBody()); 344 result.setHeadline(annotation.getHeadline()); 345 result.setOwner(annotation.getOwner()); 346 result.setPermissions(annotation.getPermissions()); 347 result.setTargetSources(annotation.getTargetSources()); 348 result.setTimeStamp(annotation.getTimeStamp()); 349 result.setURI(annotation.getURI()); 350 351 return result; 352 } 329 353 330 354 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java
r3205 r3206 20 20 import eu.dasish.annotation.backend.dao.UserDao; 21 21 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 22 import eu.dasish.annotation.schema.Annotation;23 22 import java.sql.ResultSet; 24 23 import java.sql.SQLException; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r3192 r3206 20 20 import eu.dasish.annotation.backend.BackendConstants; 21 21 import eu.dasish.annotation.backend.dao.AnnotationDao; 22 import eu.dasish.annotation.backend.dao.UserDao; 22 23 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 24 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 23 25 import eu.dasish.annotation.schema.Annotation; 24 26 import eu.dasish.annotation.schema.ObjectFactory; 25 27 import java.sql.SQLException; 28 import javax.servlet.ServletContext; 29 import javax.servlet.http.HttpServletRequest; 26 30 import javax.ws.rs.Consumes; 27 31 import javax.ws.rs.DELETE; … … 31 35 import javax.ws.rs.PathParam; 32 36 import javax.ws.rs.Produces; 37 import javax.ws.rs.core.Context; 33 38 import javax.ws.rs.core.MediaType; 34 39 import javax.xml.bind.JAXBElement; … … 46 51 @Autowired 47 52 private AnnotationDao annotationDao; 48 53 @Autowired 54 private UserDao userDao; 55 56 //for Peter, see also http://stackoverflow.com/questions/6140697/jersey-the-context-annotation-for-injection-how-does-it-work 57 @Context 58 private HttpServletRequest httpServletRequest; 59 60 @Context 61 private ServletContext servletContext; 62 63 64 public void setHttpRequest(HttpServletRequest request){ 65 this.httpServletRequest = request; 66 } 67 68 public AnnotationResource(){ 69 } 70 71 /*public AnnotationResource(@Context HttpServletRequest request){ 72 this.httpServletRequest = request; 73 }*/ 74 75 49 76 @GET 50 77 @Produces(MediaType.TEXT_XML) … … 65 92 66 93 // TODO: should be returning the envelope!!! 67 @POST 94 @POST 68 95 @Consumes(MediaType.APPLICATION_XML) 69 96 @Produces(MediaType.APPLICATION_XML) 70 97 @Path("") 71 98 public JAXBElement<Annotation> createAnnotation(Annotation annotation) { 72 AnnotationIdentifier newAnnotationIdentifier = annotationDao.addAnnotation(annotation); 73 //return newAnnotationIdentifier.toString(); 74 if (newAnnotationIdentifier == null) { 99 100 String remoteUser = httpServletRequest.getRemoteUser(); 101 Number userID; 102 103 if (remoteUser == null) { 104 // happens in client testing 105 userID = null; 106 } 107 else { 108 userID= userDao.getInternalID(new UserIdentifier(remoteUser)); 109 } 110 111 Annotation newAnnotation = annotationDao.addAnnotation(annotation, userID); 112 if (newAnnotation == null) { 75 113 return null; 76 114 } else { 77 return (new ObjectFactory().createAnnotation( annotation));115 return (new ObjectFactory().createAnnotation(newAnnotation)); 78 116 } 79 117 } 118 80 119 81 120 82 121 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/sql/DashishAnnotatorCreate.sql
r3100 r3206 36 36 SET default_with_oids = false; 37 37 38 39 ---------- BASE TABLES ---------------------------------------------- 40 41 --<xs:complexType name="User"> 42 -- <xs:sequence> 43 -- <xs:element name="additionalInfo"> 44 -- <xs:complexType> 45 -- <xs:sequence> 46 -- <xs:any processContents="lax" maxOccurs="unbounded"/> 47 -- </xs:sequence> 48 -- <xs:anyAttribute processContents="lax"/> 49 -- </xs:complexType> 50 -- </xs:element> 51 -- </xs:sequence> 52 -- <xs:attribute name="URI" type="xs:anyURI" use="required"/> 53 -- <xs:attribute name="displayName" type="xs:string" use="required"/> 54 -- <xs:attribute name="eMail" type="xs:string" use="required"/> 55 -- </xs:complexType> 56 57 58 CREATE TABLE principal ( 59 principal_id SERIAL UNIQUE NOT NULL, 60 external_id UUID UNIQUE NOT NULL, 61 principal_name text, 62 e_mail text, 63 additional_info text 64 ); 65 66 67 ------------------------------------------------------------------------ 68 -- <xs:complexType name="Annotation"> 69 -- <xs:sequence> 70 -- <xs:element name="owner" type="ResourceREF" minOccurs="1"/> 71 -- <xs:element name="headline" type="xs:string" minOccurs="1"/> 72 -- <!-- schematron checks the length <== 100 --> 73 -- <xs:element name="body" type="AnnotationBody" minOccurs="1"/> 74 -- <xs:element name="targetSources" type="NewOrExistingSourceInfos" minOccurs="1"/> 75 -- <xs:element name="permissions" type="ResourceREF"/> 76 -- </xs:sequence> 77 -- <xs:attribute name="URI" type="xs:anyURI" use="required"/> 78 -- <xs:attribute name="timeStamp" type="xs:dateTime" use="required"/> 79 -- </xs:complexType> 80 81 38 82 CREATE TABLE annotation ( 39 annotation_id SERIAL UNIQUE NOT NULL, 83 annotation_id SERIAL UNIQUE NOT NULL, 40 84 external_id UUID UNIQUE NOT NULL, 41 85 time_stamp timestamp with time zone default now(), 42 owner_id integer, 86 owner_id integer REFERENCES principal(principal_id), 87 -- there must be exactly one owner ++ 88 -- and this owner must be in the table "permissions" as owner!! 43 89 headline text, 44 90 body_xml xml 45 91 ); 92 93 ----------------------------------------------------------------------- 94 -- <xs:complexType name="CachedRepresentationInfo"> 95 -- <xs:attribute name="ref" type="xs:anyURI" use="required"/> 96 -- <xs:attribute name="mimeType" type="xs:string" use="required"/> 97 -- <xs:attribute name="tool" type="xs:string" use="required"/> 98 -- <xs:attribute name="type" type="xs:string" use="required"/> 99 -- </xs:complexType> 100 101 CREATE TABLE cached_representation_info ( 102 cached_representation_id SERIAL UNIQUE NOT NULL, 103 external_id UUID UNIQUE NOT NULL, 104 mime_type text, 105 tool text, 106 type_ text, 107 where_is_the_file text -- DIFFERS FROM the schema 108 ); 109 110 -- soundness there must be at least one version referring to this cahced representation 111 112 113 ---------------------------------------------------------------------- 114 -- <xs:complexType name="Version"> 115 -- <xs:sequence> 116 -- <xs:element name="version" type="xs:string"/> 117 -- <xs:element name="cachedRepresentations" type="CachedRepresentations"/> 118 -- </xs:sequence> 119 -- </xs:complexType> 120 121 CREATE TABLE version ( 122 version_id SERIAL UNIQUE NOT NULL, 123 external_id UUID UNIQUE NOT NULL, 124 version text, 125 -- SOUNDNESS: there must be at least one row with this version_id in the verions_cached_representations table 126 ); 127 128 ---------------------------------------------------------------- 129 130 -- <xs:complexType name="Source"> 131 -- <xs:sequence> 132 -- <xs:element name="versions-siblings" type="ResourceREF" minOccurs="1"/> 133 -- </xs:sequence> 134 -- <xs:attribute name="URI" type="xs:anyURI" use="required"/> 135 -- <xs:attribute name="timeSatmp" type="xs:dateTime" use="required"/> 136 -- <xs:attribute name="link" type="xs:anyURI" use="required"/> 137 -- <xs:attribute name="version" type="xs:string" use="required"/> 138 -- </xs:complexType> 139 140 CREATE TABLE target_source ( 141 source_id SERIAL UNIQUE NOT NULL, 142 external_id UUID UNIQUE NOT NULL, 143 time_stamp timestamp with time zone default now(), 144 link_uri text, 145 version_id integer REFERENCES version(version_id), ---- DIFFERS from the xml structure, 146 -- SOUNDNESS: there must be exactly version at the version table ++ 147 -- soundness: there must be at least one annotation referring to this source 148 ); 149 150 151 ----------------------------------------------------------------------------------- 46 152 47 153 CREATE TABLE notebook ( … … 51 157 title text, 52 158 owner_id integer NOT NULL 53 ); 159 -- soundness: there must be at least one target source in the annotations_target_sources table 160 ); 161 162 163 164 ----------------------------------------------------------------------- 165 --------------------- JOINT TABLES ------------------------------------ 166 167 CREATE TABLE annotations_target_sources ( 168 annotation_id integer REFERENCES annotation(annotation_id), -- defining a foreign key: there must be a uniquely defined row in "annotation", that is defined by "annotation_id" 169 source_id integer REFERENCES target_source(source_id), 170 unique(annotation_id, source_id), 171 ); 172 173 54 174 55 175 CREATE TABLE notebooks_annotations ( 56 176 notebook_id integer REFERENCES notebook(notebook_id), 57 annotation_id integer REFERENCES annotation(annotation_id) 58 ); 59 60 CREATE TABLE principal ( 61 principal_id SERIAL NOT NULL, 62 external_id UUID UNIQUE NOT NULL, 63 principal_name text 64 ); 65 177 annotation_id integer REFERENCES annotation(annotation_id), 178 unique(notebook_id, annotation_id), 179 ); 180 181 CREATE TABLE sources_versions ( 182 source_id integer REFERENCES target_source(source_id), 183 version_id integer REFERENCES version(version_id), 184 unique(source_id, version_id), 185 ); 186 187 CREATE TABLE versions_cached_representations ( 188 version_id integer REFERENCES version(version_id), 189 cached_representation_id integer REFERENCES cached_representation_info(cached_representation_id), 190 unique(version_id, cached_representation_id), 191 ); 192 193 194 --------------------------------------------------------------------------------------------- 66 195 ALTER TABLE ONLY annotation 67 196 ADD CONSTRAINT annotation_primary_key PRIMARY KEY (annotation_id); … … 92 221 -- PostgreSQL database dump complete 93 222 -- 94 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java
r3188 r3206 63 63 public static final String _TEST_ANNOT_TO_ADD_HEADLINE = "Annotation to add to test DAO"; 64 64 65 public static final int _TEST_ANNOT_1_OWNER = 111;66 public static final int _TEST_ANNOT_2_OWNER = 112;67 public static final int _TEST_ANNOT_3_OWNER = 113;68 public static final int _TEST_ANNOT_TO_ADD_OWNER = 117;65 public static final int _TEST_ANNOT_1_OWNER = 3; 66 public static final int _TEST_ANNOT_2_OWNER = 4; 67 public static final int _TEST_ANNOT_3_OWNER = 5; 68 public static final int _TEST_ANNOT_TO_ADD_OWNER = 5; 69 69 70 70 public static final String _TEST_ANNOT_1_BODY = "<html><body>some html 1</body></html>"; … … 73 73 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');"; 74 74 75 public static final String _TEST_OWNER_3_EXT_ID = "00000000-0000-0000-0000-000000000111"; 76 public static final String _TEST_OWNER_4_EXT_ID = "00000000-0000-0000-0000-000000000112"; 77 public static final String _TEST_OWNER_5_EXT_ID = "00000000-0000-0000-0000-000000000113"; 78 75 79 } 76 80 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3189 r3206 180 180 System.out.println("test_addAnnotation"); 181 181 Annotation annotationToAdd = testInstances.getAnnotationToAdd(); 182 Annotation Identifier result = jdbcAnnotationDao.addAnnotation(annotationToAdd);182 Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, TestBackendConstants._TEST_ANNOT_TO_ADD_OWNER); 183 183 assertFalse(result == null); 184 184 185 Annotation addedAnnotation = jdbcAnnotationDao.getAnnotation(jdbcAnnotationDao.getAnnotationID(result)); 185 AnnotationIdentifier generatedAnnotationExternalID = new AnnotationIdentifier(result.getURI()); 186 187 Annotation addedAnnotation = jdbcAnnotationDao.getAnnotation(jdbcAnnotationDao.getAnnotationID(generatedAnnotationExternalID)); 186 188 assertEquals(annotationToAdd.getBody().getAny().get(0), addedAnnotation.getBody().getAny().get(0)); 187 189 assertEquals(annotationToAdd.getHeadline(), addedAnnotation.getHeadline()); 188 assertEquals(annotationToAdd.getOwner().getRef(), addedAnnotation.getOwner().getRef()); 190 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_TO_ADD_OWNER), addedAnnotation.getOwner().getRef()); 191 assertEquals(annotationToAdd.getPermissions(), addedAnnotation.getPermissions()); 192 assertEquals(annotationToAdd.getTargetSources(), addedAnnotation.getTargetSources()); 193 assertEquals(annotationToAdd.getTimeStamp(), addedAnnotation.getTimeStamp()); 189 194 190 195 // try to add an already existing annptation, should produce null -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcNotebookDaoTest.java
r3189 r3206 49 49 */ 50 50 @RunWith(SpringJUnit4ClassRunner.class) 51 @ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", 51 @ContextConfiguration({"/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", 52 52 "/spring-test-config/dataSource.xml", "/spring-config/notebookDao.xml"}) 53 53 public class JdbcNotebookDaoTest extends JdbcResourceDaoTest{ -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java
r3192 r3206 22 22 import eu.dasish.annotation.backend.TestInstances; 23 23 import eu.dasish.annotation.backend.dao.AnnotationDao; 24 import eu.dasish.annotation.backend.dao.UserDao; 24 25 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 26 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 25 27 import eu.dasish.annotation.schema.Annotation; 26 import eu.dasish.annotation.schema. ObjectFactory;28 import eu.dasish.annotation.schema.ResourceREF; 27 29 import java.sql.SQLException; 28 30 import javax.xml.bind.JAXBElement; … … 36 38 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 37 39 import java.lang.InstantiationException; 40 import javax.servlet.ServletException; 41 import org.springframework.mock.web.MockHttpServletRequest; 42 import org.springframework.web.context.ContextLoaderListener; 43 import org.springframework.web.context.WebApplicationContext; 38 44 /** 39 45 * … … 42 48 43 49 @RunWith(value = SpringJUnit4ClassRunner.class) 44 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mock NotebookDao.xml", "/spring-test-config/mockery.xml"})50 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"}) 45 51 public class AnnotationResourceTest { 46 52 … … 50 56 private AnnotationDao annotationDao; 51 57 @Autowired 52 private AnnotationResource annotationResource; 58 private UserDao userDao; 59 60 @Autowired 61 private AnnotationResource annotationResource; 53 62 54 63 public AnnotationResourceTest() { … … 119 128 */ 120 129 @Test 121 public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException {130 public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException, ServletException { 122 131 System.out.println("test createAnnotation"); 123 132 final Annotation annotationToAdd = new GenericType<Annotation>(){}.getRawClass().newInstance(); 124 final AnnotationIdentifier newAnnotationID = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance();125 133 134 final Annotation addedAnnotation = annotationToAdd; 135 AnnotationIdentifier annotationIdentifier = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance(); 136 addedAnnotation.setURI(annotationIdentifier.toString()); 137 ResourceREF ownerRef = new ResourceREF(); 138 ownerRef.setRef(String.valueOf(TestBackendConstants._TEST_ANNOT_TO_ADD_OWNER)); 139 addedAnnotation.setOwner(ownerRef); 140 141 126 142 mockery.checking(new Expectations() { 127 143 { 128 oneOf(annotationDao).addAnnotation(annotationToAdd); 129 will(returnValue(newAnnotationID)); 144 oneOf(userDao).getInternalID(new UserIdentifier(TestBackendConstants._TEST_OWNER_5_EXT_ID)); 145 will(returnValue(TestBackendConstants._TEST_ANNOT_TO_ADD_OWNER)); 146 147 oneOf(annotationDao).addAnnotation(annotationToAdd, TestBackendConstants._TEST_ANNOT_TO_ADD_OWNER); 148 will(returnValue(addedAnnotation)); 130 149 } 131 150 }); 132 151 133 152 153 154 final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); 155 httpServletRequest.setRemoteUser(TestBackendConstants._TEST_OWNER_5_EXT_ID); 156 annotationResource.setHttpRequest(httpServletRequest); 157 134 158 JAXBElement<Annotation> result = annotationResource.createAnnotation(annotationToAdd); 135 assertTrue(annotationToAdd.equals(result.getValue())); 159 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_TO_ADD_OWNER), result.getValue().getOwner().getRef()); 160 assertEquals(annotationIdentifier.toString(), result.getValue().getURI()); 161 162 136 163 } 137 164 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationsTest.java
r3192 r3206 22 22 import eu.dasish.annotation.backend.TestBackendConstants; 23 23 import eu.dasish.annotation.backend.dao.AnnotationDao; 24 import eu.dasish.annotation.backend.dao.UserDao; 24 25 import eu.dasish.annotation.backend.identifiers.AnnotationIdentifier; 26 import eu.dasish.annotation.backend.identifiers.UserIdentifier; 25 27 import eu.dasish.annotation.schema.Annotation; 26 import eu.dasish.annotation.schema.Notebook;27 28 import eu.dasish.annotation.schema.ObjectFactory; 29 import eu.dasish.annotation.schema.ResourceREF; 28 30 import java.sql.SQLException; 29 import javax. ws.rs.core.GenericEntity;31 import javax.servlet.http.HttpServletRequest; 30 32 import javax.ws.rs.core.MediaType; 31 33 import javax.xml.bind.JAXBElement; … … 41 43 42 44 private AnnotationDao annotationDao; 45 private UserDao userDao; 43 46 44 47 public AnnotationsTest() { 45 48 super(AnnotationResource.class.getPackage().getName()); 46 49 annotationDao = webAppContext.getBean(AnnotationDao.class); 50 userDao = webAppContext.getBean(UserDao.class); 47 51 } 48 52 … … 132 136 public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException{ 133 137 System.out.println("test createAnnotation"); 134 //final Annotation annotationToAdd = new ObjectFactory().createAnnotation(); 135 final Annotation annotationToAdd = new GenericType<Annotation>(){}.getRawClass().newInstance(); 136 final AnnotationIdentifier newAnnotationID = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance(); 138 final Annotation annotationToAdd = new ObjectFactory().createAnnotation(); 139 140 // Peter's workaround on absence of "ObjectFactory.create... for annotations 141 final JAXBElement<Annotation> jaxbElement = new JAXBElement<Annotation>(new QName("http://www.dasish.eu/ns/addit", "annotation"), Annotation.class, null, annotationToAdd); 142 143 144 final Annotation addedAnnotation = annotationToAdd; 145 AnnotationIdentifier annotationIdentifier = new GenericType<AnnotationIdentifier>(){}.getRawClass().newInstance(); 146 addedAnnotation.setURI(annotationIdentifier.toString()); 137 147 138 148 mockery.checking(new Expectations() { 139 { 140 oneOf(annotationDao).addAnnotation(with(a NonNull(Annotation.class)));141 will(returnValue( newAnnotationID));149 { 150 oneOf(annotationDao).addAnnotation(with(any(Annotation.class)), with(any(Number.class))); 151 will(returnValue(addedAnnotation)); 142 152 } 143 153 }); 154 155 144 156 145 146 147 final String requestUrl = "annotations/"; 157 final String requestUrl = "annotations"; 148 158 System.out.println("requestUrl: " + requestUrl); 149 159 150 // Peter's workaround on absence of "PnjectFactory.create... for annotations 151 final JAXBElement<Annotation> jaxbElement = new JAXBElement<Annotation>(new QName("http://www.dasish.eu/ns/addit", "annotation"), Annotation.class, null, annotationToAdd); 152 153 ClientResponse response = resource().path(requestUrl).type(MediaType.APPLICATION_XML).post(ClientResponse.class, jaxbElement); 160 // Peter's workaround on absence of "ObjectFactory.create... for annotations 161 162 ClientResponse response = resource().path(requestUrl).accept(MediaType.APPLICATION_XML).type(MediaType.APPLICATION_XML).post(ClientResponse.class, jaxbElement); 154 163 assertEquals(200, response.getStatus()); 155 164 … … 160 169 assertEquals(annotationToAdd.getTargetSources(), entity.getTargetSources()); 161 170 assertEquals(annotationToAdd.getTimeStamp(), entity.getTimeStamp()); 162 assertEquals(annotationToAdd.getURI(), entity.getURI());163 171 } 164 172 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java
r3190 r3206 47 47 */ 48 48 @RunWith(value = SpringJUnit4ClassRunner.class) 49 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mock NotebookDao.xml", "/spring-test-config/mockery.xml"})49 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockAnnotationDao.xml", "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml", "/spring-test-config/mockery.xml"}) 50 50 public class NotebookResourceTest { 51 51 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/ResourcesTest.java
r3205 r3206 49 49 50 50 // Get the context and mock objects from the context by their type 51 mockery = webAppContext.getBean(Mockery.class); 51 mockery = webAppContext.getBean(Mockery.class); 52 52 } 53 53 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql
r3168 r3206 17 17 -- 18 18 19 INSERT INTO principal (principal_name, external_id) VALUES ('a user', '00000000-0000-0000-0000-000000000003'); 20 INSERT INTO principal (principal_name, external_id) VALUES ('b user', '00000000-0000-0000-0000-000000000004'); 19 INSERT INTO principal (principal_name, external_id) VALUES ('a user', '00000000-0000-0000-0000-000000000003'); -- 1 20 INSERT INTO principal (principal_name, external_id) VALUES ('b user', '00000000-0000-0000-0000-000000000004');-- 2 21 21 22 INSERT INTO notebook (title, owner_id, external_id) VALUES ('a notebook', 1, '00000000-0000-0000-0000-000000000001');22 INSERT INTO notebook (title, owner_id, external_id) VALUES ('a notebook', 2, '00000000-0000-0000-0000-000000000001'); 23 23 -- INSERT INTO notebook (title, owner_id, external_id) VALUES ('a notebook', 1, 1); 24 24 INSERT INTO annotation (owner_id,headline,body_xml, external_id) VALUES (1, 'a headline','<html><body>some html</body></html>', '00000000-0000-0000-0000-000000000005'); 25 25 26 INSERT INTO notebook (title, owner_id, external_id) VALUES ('a second notebook', 1, '00000000-0000-0000-0000-000000000002');26 INSERT INTO notebook (title, owner_id, external_id) VALUES ('a second notebook', 2, '00000000-0000-0000-0000-000000000002'); 27 27 -- INSERT INTO notebook (title, owner_id, external_id) VALUES ('a second notebook', 1, 2); 28 28 INSERT INTO notebooks_annotations (notebook_id,annotation_id) VALUES (1,1); … … 32 32 -- Test data for jdbcAnnotationDao -- 33 33 34 INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (11, 'Notebook 11', 111, '00000000-0000-0000-0000-000000000011');35 INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (12, 'Notebook 12', 112, '00000000-0000-0000-0000-000000000012');36 INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (13, 'Notebook 13', 113, '00000000-0000-0000-0000-000000000013');34 INSERT INTO principal (principal_name, external_id) VALUES ('Twan', '00000000-0000-0000-0000-000000000111'); --3 35 INSERT INTO principal (principal_name, external_id) VALUES ('Peter', '00000000-0000-0000-0000-000000000112'); -- 4 36 INSERT INTO principal (principal_name, external_id) VALUES ('Olha', '00000000-0000-0000-0000-000000000113'); -- 5 37 37 38 INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (21, 111, 'Sagrada Famiglia','<html><body>some html 1</body></html>', '00000000-0000-0000-0000-000000000021'); 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 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'); 38 INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (11, 'Notebook 11', 3, '00000000-0000-0000-0000-000000000011'); 39 INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (12, 'Notebook 12', 4, '00000000-0000-0000-0000-000000000012'); 40 INSERT INTO notebook (notebook_id, title, owner_id, external_id) VALUES (13, 'Notebook 13', 5, '00000000-0000-0000-0000-000000000013'); 41 42 INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (21, 3, 'Sagrada Famiglia','<html><body>some html 1</body></html>', '00000000-0000-0000-0000-000000000021'); 43 INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (22, 4, 'Gaudi','<html><body>some html 2 </body></html>', '00000000-0000-0000-0000-000000000022'); 44 INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (23, 5, 'Art Nuveau','<html><body>some html 3</body></html>', '00000000-0000-0000-0000-000000000023'); 45 INSERT INTO annotation (annotation_id, owner_id,headline,body_xml, external_id) VALUES (25, 3, 'Annotation to delete','<html><body>some html 4</body></html>', '00000000-0000-0000-0000-000000000025'); 42 46 43 47 … … 48 52 49 53 54 55
Note: See TracChangeset
for help on using the changeset viewer.