Changeset 3361
- Timestamp:
- 08/12/13 11:26:15 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/Helpers.java
r3334 r3361 18 18 package eu.dasish.annotation.backend; 19 19 20 import java.sql.Timestamp; 21 import java.text.ParseException; 22 import java.text.SimpleDateFormat; 20 23 import java.util.Date; 21 24 import java.util.GregorianCalendar; 25 import java.util.Locale; 22 26 import javax.xml.datatype.DatatypeConfigurationException; 23 27 import javax.xml.datatype.DatatypeFactory; … … 30 34 public class Helpers { 31 35 32 public static XMLGregorianCalendar setXMLGregorianCalendar(Date timeStamp) throws DatatypeConfigurationException { 33 GregorianCalendar c = new GregorianCalendar(); 34 c.setTime(timeStamp); 35 return DatatypeFactory.newInstance().newXMLGregorianCalendar(c); 36 36 public static XMLGregorianCalendar setXMLGregorianCalendar(Timestamp timeStamp) throws DatatypeConfigurationException { 37 GregorianCalendar gc = new GregorianCalendar(); 38 gc.setTime(timeStamp); 39 return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); 37 40 } 38 41 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDao.java
r3348 r3361 41 41 import javax.sql.DataSource; 42 42 import javax.xml.datatype.DatatypeConfigurationException; 43 import javax.xml.datatype.XMLGregorianCalendar;44 43 import org.springframework.beans.factory.annotation.Autowired; 45 44 import org.springframework.dao.DataAccessException; … … 154 153 public Annotation mapRow(ResultSet rs, int rowNumber) throws SQLException { 155 154 Annotation result = new Annotation(); 156 result.setHeadline(rs.getString(headline));157 155 158 156 ResourceREF ownerREF = new ResourceREF(); … … 160 158 result.setOwner(ownerREF); 161 159 160 result.setHeadline(rs.getString(headline)); 161 162 result.setBody(convertToAnnotationBody(rs.getString(body_xml))); 163 162 164 List<SourceInfo> sourceInfoList = jdbcSourceDao.getSourceInfos(rs.getInt(annotation_id)); 163 165 NewOrExistingSourceInfos noeSourceInfos = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList); 164 166 result.setTargetSources(noeSourceInfos); 165 167 166 result.setBody(convertToAnnotationBody(rs.getString(body_xml))); 167 return result; 168 // TODO: fix: rpelace URI in the schema with external id, or make here the conversion: 169 // from external ID in the DB to the URI for the class 170 result.setURI(rs.getString(external_id)); 171 172 try { 173 result.setTimeStamp(Helpers.setXMLGregorianCalendar(rs.getTimestamp(time_stamp))); 174 return result; 175 } catch (DatatypeConfigurationException e) { 176 System.out.println(e); 177 return result; // no date-time is set 178 } 168 179 } 169 180 }; 170 181 171 // TODO: fill in the stub, when the annotation body is elaborated172 182 private AnnotationBody convertToAnnotationBody(String input) { 173 183 if (input == null) { … … 231 241 String sql = "INSERT INTO " + annotationTableName + "(" + external_id + "," + owner_id + "," + headline + "," + body_xml + " ) VALUES (:externalId, :ownerId, :headline, :bodyXml)"; 232 242 final int affectedRows = getSimpleJdbcTemplate().update(sql, params); 233 243 234 244 if (affectedRows != 1) { 235 245 throw (new SQLException("Cannot add the annotation properly")); … … 258 268 if (affectedRows != 1) { 259 269 throw (new SQLException("Cannot update the body with persistent reference ID")); 260 } 270 } 261 271 262 272 return result; … … 285 295 } 286 296 287 288 289 297 /////////////////////////////////////////////////////////// 290 298 private ResourceREF getResourceREF(String resourceID) { … … 302 310 303 311 Annotation result = new Annotation(); 304 305 312 306 313 AnnotationBody body = new AnnotationBody(); 307 314 String bodyString = annotation.getBody().getAny().get(0).toString(); 308 315 body.getAny().add(bodyString); 309 316 result.setBody(body); 310 317 311 318 result.setHeadline(annotation.getHeadline()); 312 319 313 320 ResourceREF owner = new ResourceREF(); 314 321 owner.setRef(annotation.getOwner().getRef()); 315 322 result.setOwner(owner); 316 323 317 324 // ResourceREF permissions = new ResourceREF(); 318 325 // permissions.setRef(annotation.getPermissions().getRef()); 319 326 // result.setPermissions(permissions); 320 327 321 328 result.setPermissions(null); //we do not have permissions there 322 329 323 330 NewOrExistingSourceInfos noesi = new NewOrExistingSourceInfos(); 324 noesi.getTarget().addAll(annotation.getTargetSources().getTarget()); 331 noesi.getTarget().addAll(annotation.getTargetSources().getTarget()); 325 332 result.setTargetSources(noesi); 326 333 327 334 result.setTimeStamp(annotation.getTimeStamp()); 328 335 result.setURI(annotation.getURI()); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcResourceDao.java
r3348 r3361 173 173 public XMLGregorianCalendar mapRow(ResultSet rs, int rowNumber) throws SQLException { 174 174 try { 175 XMLGregorianCalendar result = Helpers.setXMLGregorianCalendar(rs.get Date(time_stamp));175 XMLGregorianCalendar result = Helpers.setXMLGregorianCalendar(rs.getTimestamp(time_stamp)); 176 176 return result; 177 177 } catch (DatatypeConfigurationException e) { -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDao.java
r3348 r3361 93 93 public Source mapRow(ResultSet rs, int rowNumber) throws SQLException { 94 94 try { 95 XMLGregorianCalendar xmlDate = Helpers.setXMLGregorianCalendar(rs.get Date(time_stamp));95 XMLGregorianCalendar xmlDate = Helpers.setXMLGregorianCalendar(rs.getTimestamp(time_stamp)); 96 96 Source result = constructSource(new SourceIdentifier(rs.getString(external_id)), rs.getString(link_uri), 97 97 versionDao.getExternalID(rs.getInt(version_id)), xmlDate); -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java
r3334 r3361 59 59 public static final String _TEST_ANNOT_TO_ADD_BODY = "<html><body>the stuff to be added</body></html>"; 60 60 61 public static final String _TEST_ANNOT_2_TIME_STAMP = "2013-08-12T11:25:00.383+02:00"; 62 61 63 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');"; 62 64 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3347 r3361 18 18 package eu.dasish.annotation.backend.dao.impl; 19 19 20 import eu.dasish.annotation.backend.Helpers; 20 21 import eu.dasish.annotation.backend.TestBackendConstants; 21 22 import eu.dasish.annotation.backend.TestInstances; … … 28 29 import eu.dasish.annotation.schema.AnnotationInfo; 29 30 import eu.dasish.annotation.schema.NewOrExistingSourceInfo; 30 import eu.dasish.annotation.schema.NewOrExistingSourceInfo;31 31 import eu.dasish.annotation.schema.NewOrExistingSourceInfos; 32 32 import eu.dasish.annotation.schema.NewSourceInfo; 33 33 import eu.dasish.annotation.schema.ResourceREF; 34 import eu.dasish.annotation.schema.Source;35 34 import eu.dasish.annotation.schema.SourceInfo; 36 35 import java.sql.SQLException; … … 39 38 import java.util.List; 40 39 import java.util.Map; 40 import javax.xml.datatype.DatatypeConfigurationException; 41 41 import org.jmock.Expectations; 42 42 import org.jmock.Mockery; 43 43 import static org.junit.Assert.*; 44 import org.junit.Ignore;45 44 import org.junit.Test; 46 45 import org.junit.runner.RunWith; … … 54 53 */ 55 54 @RunWith(SpringJUnit4ClassRunner.class) 56 @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockNotebookDao.xml", 57 "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockSourceDao.xml","/spring-config/annotationDao.xml"}) 58 public class JdbcAnnotationDaoTest extends JdbcResourceDaoTest{ 59 60 @Autowired 61 JdbcAnnotationDao jdbcAnnotationDao; 62 55 @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockNotebookDao.xml", 56 "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockSourceDao.xml", "/spring-config/annotationDao.xml"}) 57 public class JdbcAnnotationDaoTest extends JdbcResourceDaoTest { 58 59 @Autowired 60 JdbcAnnotationDao jdbcAnnotationDao; 63 61 @Autowired 64 62 private PermissionsDao permissionsDao; 65 66 63 @Autowired 67 64 private NotebookDao notebookDao; 68 69 65 @Autowired 70 66 private SourceDao sourceDao; 71 72 67 @Autowired 73 68 private Mockery mockery; 74 75 69 TestInstances testInstances = new TestInstances(); 76 77 78 79 70 80 71 /** … … 82 73 * List<AnnotationInfo> getAnnotationInfos(List<Number> annotationIDs) 83 74 */ 84 @Test 75 @Test 85 76 public void testGetAnnotationInfos() { 86 77 System.out.println("getAnnotationInfos"); 87 List<Number> annotIds = new ArrayList<Number>(); 78 List<Number> annotIds = new ArrayList<Number>(); 88 79 annotIds.add(2); 89 80 annotIds.add(3); 90 81 annotIds.add(4); 91 82 92 83 final List<AnnotationInfo> annotationInfos = jdbcAnnotationDao.getAnnotationInfos(annotIds); 93 84 assertEquals(3, annotationInfos.size()); 94 85 95 86 assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotationInfos.get(0).getHeadline()); 96 87 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_OWNER), annotationInfos.get(0).getOwner().getRef()); 97 88 //assertEquals(TestBackendConstants._TEST_ANNOT_1_TARGETS, annotationInfos.get(0).getTargetSources()); 98 89 99 90 assertEquals(TestBackendConstants._TEST_ANNOT_3_HEADLINE, annotationInfos.get(1).getHeadline()); 100 91 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_3_OWNER), annotationInfos.get(1).getOwner().getRef()); 101 92 //assertEquals(TestBackendConstants._TEST_ANNOT_2_TARGETS, annotationInfos.get(1).getTargetSources()); 102 93 103 94 assertEquals(TestBackendConstants._TEST_ANNOT_4_HEADLINE, annotationInfos.get(2).getHeadline()); 104 95 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_4_OWNER), annotationInfos.get(2).getOwner().getRef()); 105 96 //assertEquals(TestBackendConstants._TEST_ANNOT_3_TARGETS, annotationInfos.get(2).getTargetSources()); 106 97 107 98 final List<AnnotationInfo> annotationInfosNull = jdbcAnnotationDao.getAnnotationInfos(null); 108 99 assertEquals(null, annotationInfosNull); 109 100 110 101 final List<AnnotationInfo> annotationInfosZeroSize = jdbcAnnotationDao.getAnnotationInfos(new ArrayList<Number>()); 111 102 assertEquals(0, annotationInfosZeroSize.size()); 112 113 114 } 115 116 103 104 105 } 106 117 107 /** 118 108 * Test of getAnnotationREFs method, of class JdbcAnnotationDao. 119 109 * List<ResourceREF> getAnnotationREFs(List<Number> annotationIDs) 120 110 */ 121 @Test 111 @Test 122 112 public void testGetAnnotationREFs() { 123 113 System.out.println("getAnnotationREFs"); 124 List<Number> annotIds = new ArrayList<Number>(); 114 List<Number> annotIds = new ArrayList<Number>(); 125 115 annotIds.add(2); 126 116 annotIds.add(3); 127 117 annotIds.add(4); 128 129 final 130 assertEquals(3, testList.size()); 118 119 final List<ResourceREF> testList = jdbcAnnotationDao.getAnnotationREFs(annotIds); 120 assertEquals(3, testList.size()); 131 121 assertEquals(String.valueOf(2), testList.get(0).getRef()); 132 122 assertEquals(String.valueOf(3), testList.get(1).getRef()); 133 123 assertEquals(String.valueOf(4), testList.get(2).getRef()); 134 135 final 124 125 final List<ResourceREF> testListTwo = jdbcAnnotationDao.getAnnotationREFs(new ArrayList<Number>()); 136 126 assertEquals(0, testListTwo.size()); 137 127 138 128 final List<ResourceREF> testListThree = jdbcAnnotationDao.getAnnotationREFs(null); 139 129 assertEquals(null, testListThree); 140 141 } 142 /** 143 * 144 * Test of getAnnotationID method, of class JdbcAnnotationDao. 145 * Integer getAnnotationID(AnnotationIdentifier externalID) 146 */ 147 @Test 148 public void getAnnotationID() throws SQLException{ 149 System.out.println("getAnnotationID"); 150 151 final Number annotaionId = jdbcAnnotationDao.getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT)); 152 assertEquals(2, annotaionId.intValue()); 153 154 final Number annotaionIdNE = jdbcAnnotationDao.getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_7_EXT_NOT_IN_DB)); 155 assertEquals(null, annotaionIdNE); 156 157 final Number annotaionIdNull = jdbcAnnotationDao.getInternalID(null); 158 assertEquals(null, annotaionIdNull); 159 } 160 161 /** 162 * 163 * Test of getAnnotation method, of class JdbcAnnotationDao. 164 * Annotation getAnnotation(Number annotationlID) 165 */ 166 @Test 167 public void getAnnotation() throws SQLException{ 168 System.out.println("getAnnotation"); 169 170 final Number testAnnotationID = 2; 171 172 173 SourceInfo sourceOneInfo = new SourceInfo(); 174 sourceOneInfo.setLink(TestBackendConstants._TEST_SOURCE_1_LINK); 175 sourceOneInfo.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID); 176 sourceOneInfo.setVersion(Integer.toString(TestBackendConstants._TEST_SOURCE_1_VERSION_ID)); 177 178 SourceInfo sourceTwoInfo = new SourceInfo(); 179 sourceTwoInfo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK); 180 sourceTwoInfo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID); 181 sourceTwoInfo.setVersion(Integer.toString(TestBackendConstants._TEST_SOURCE_2_VERSION_ID)); 182 183 final List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>(); 184 sourceInfoList.add(sourceOneInfo); 185 sourceInfoList.add(sourceTwoInfo); 186 187 NewOrExistingSourceInfo noeSourceOneInfo = new NewOrExistingSourceInfo(); 188 noeSourceOneInfo.setSource(sourceOneInfo); 189 NewOrExistingSourceInfo noeSourceTwoInfo = new NewOrExistingSourceInfo(); 190 noeSourceTwoInfo.setSource(sourceTwoInfo); 191 192 List<NewOrExistingSourceInfo> noeSourceInfoList = new ArrayList<NewOrExistingSourceInfo>(); 193 noeSourceInfoList.add(noeSourceOneInfo); 194 noeSourceInfoList.add(noeSourceTwoInfo); 195 final NewOrExistingSourceInfos noeSourceInfos= new NewOrExistingSourceInfos(); 196 noeSourceInfos.getTarget().addAll(noeSourceInfoList); 197 130 131 } 132 133 /** 134 * 135 * Test of getAnnotationID method, of class JdbcAnnotationDao. Integer 136 * getAnnotationID(AnnotationIdentifier externalID) 137 */ 138 @Test 139 public void getInternalID() throws SQLException { 140 System.out.println("test getInternalID"); 141 142 final Number annotaionId = jdbcAnnotationDao.getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT)); 143 assertEquals(2, annotaionId.intValue()); 144 145 final Number annotaionIdNE = jdbcAnnotationDao.getInternalID(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_7_EXT_NOT_IN_DB)); 146 assertEquals(null, annotaionIdNE); 147 148 final Number annotaionIdNull = jdbcAnnotationDao.getInternalID(null); 149 assertEquals(null, annotaionIdNull); 150 } 151 152 /** 153 * 154 * Test of getAnnotation method, of class JdbcAnnotationDao. Annotation 155 * getAnnotation(Number annotationlID) 156 */ 157 @Test 158 public void getAnnotation() throws SQLException { 159 System.out.println("test getAnnotation"); 160 161 /// dummy test 162 final Annotation annotaionNull = jdbcAnnotationDao.getAnnotation(null); 163 assertEquals(null, annotaionNull); 164 //// 165 166 final Number testAnnotationID = 2; 167 168 169 SourceInfo sourceOneInfo = new SourceInfo(); 170 sourceOneInfo.setLink(TestBackendConstants._TEST_SOURCE_1_LINK); 171 sourceOneInfo.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID); 172 sourceOneInfo.setVersion(Integer.toString(TestBackendConstants._TEST_SOURCE_1_VERSION_ID)); 173 174 SourceInfo sourceTwoInfo = new SourceInfo(); 175 sourceTwoInfo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK); 176 sourceTwoInfo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID); 177 sourceTwoInfo.setVersion(Integer.toString(TestBackendConstants._TEST_SOURCE_2_VERSION_ID)); 178 179 final List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>(); 180 sourceInfoList.add(sourceOneInfo); 181 sourceInfoList.add(sourceTwoInfo); 182 183 NewOrExistingSourceInfo noeSourceOneInfo = new NewOrExistingSourceInfo(); 184 noeSourceOneInfo.setSource(sourceOneInfo); 185 NewOrExistingSourceInfo noeSourceTwoInfo = new NewOrExistingSourceInfo(); 186 noeSourceTwoInfo.setSource(sourceTwoInfo); 187 188 List<NewOrExistingSourceInfo> noeSourceInfoList = new ArrayList<NewOrExistingSourceInfo>(); 189 noeSourceInfoList.add(noeSourceOneInfo); 190 noeSourceInfoList.add(noeSourceTwoInfo); 191 final NewOrExistingSourceInfos noeSourceInfos = new NewOrExistingSourceInfos(); 192 noeSourceInfos.getTarget().addAll(noeSourceInfoList); 193 198 194 mockery.checking(new Expectations() { 199 { 200 oneOf(sourceDao).getSourceInfos(testAnnotationID 195 { 196 oneOf(sourceDao).getSourceInfos(testAnnotationID); 201 197 will(returnValue(sourceInfoList)); 202 198 203 199 oneOf(sourceDao).contructNewOrExistingSourceInfo(sourceInfoList); 204 200 will(returnValue(noeSourceInfos)); 205 201 } 206 202 }); 207 208 209 final Annotation annotation = jdbcAnnotationDao.getAnnotation(testAnnotationID.intValue()); 210 assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotation.getHeadline()); 211 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_OWNER), annotation.getOwner().getRef()); 212 assertEquals(TestBackendConstants._TEST_ANNOT_2_BODY, annotation.getBody().getAny().get(0)); // when the body is elaborated it will be changed 213 214 assertEquals(sourceOneInfo.getRef(), annotation.getTargetSources().getTarget().get(0).getSource().getRef()); 215 assertEquals(sourceOneInfo.getLink(), annotation.getTargetSources().getTarget().get(0).getSource().getLink()); 216 assertEquals(sourceOneInfo.getVersion(), annotation.getTargetSources().getTarget().get(0).getSource().getVersion()); 217 218 assertEquals(sourceTwoInfo.getRef(), annotation.getTargetSources().getTarget().get(1).getSource().getRef()); 219 assertEquals(sourceTwoInfo.getLink(), annotation.getTargetSources().getTarget().get(1).getSource().getLink()); 220 assertEquals(sourceTwoInfo.getVersion(), annotation.getTargetSources().getTarget().get(1).getSource().getVersion()); 221 222 223 final Annotation annotaionNull = jdbcAnnotationDao.getAnnotation(null); 224 assertEquals(null, annotaionNull); 225 } 226 203 204 205 final Annotation annotation = jdbcAnnotationDao.getAnnotation(testAnnotationID); 206 assertEquals(TestBackendConstants._TEST_ANNOT_2_HEADLINE, annotation.getHeadline()); 207 assertEquals(String.valueOf(TestBackendConstants._TEST_ANNOT_2_OWNER), annotation.getOwner().getRef()); 208 assertEquals(TestBackendConstants._TEST_ANNOT_2_BODY, annotation.getBody().getAny().get(0)); // when the body is elaborated it may be changed 209 210 assertEquals(sourceOneInfo.getRef(), annotation.getTargetSources().getTarget().get(0).getSource().getRef()); 211 assertEquals(sourceOneInfo.getLink(), annotation.getTargetSources().getTarget().get(0).getSource().getLink()); 212 assertEquals(sourceOneInfo.getVersion(), annotation.getTargetSources().getTarget().get(0).getSource().getVersion()); 213 214 assertEquals(sourceTwoInfo.getRef(), annotation.getTargetSources().getTarget().get(1).getSource().getRef()); 215 assertEquals(sourceTwoInfo.getLink(), annotation.getTargetSources().getTarget().get(1).getSource().getLink()); 216 assertEquals(sourceTwoInfo.getVersion(), annotation.getTargetSources().getTarget().get(1).getSource().getVersion()); 217 218 assertEquals(TestBackendConstants._TEST_ANNOT_2_EXT, annotation.getURI()); 219 220 assertEquals(TestBackendConstants._TEST_ANNOT_2_TIME_STAMP, annotation.getTimeStamp().toString()); 221 222 223 } 224 227 225 /** 228 226 * Test of deletAnnotation method, of class JdbcAnnotationDao. 229 227 */ 230 228 @Test 231 public void testDeleteAnnotation() throws SQLException {232 System.out.println("deleteAnnotation"); 233 234 235 { 229 public void testDeleteAnnotation() throws SQLException { 230 System.out.println("deleteAnnotation"); 231 232 mockery.checking(new Expectations() { 233 { 236 234 oneOf(permissionsDao).removeAnnotation(5); 237 235 will(returnValue(1)); 238 236 239 237 oneOf(notebookDao).removeAnnotation(5); 240 238 will(returnValue(3)); 241 239 } 242 240 }); 243 241 244 242 int result = jdbcAnnotationDao.deleteAnnotation(5); 245 243 assertEquals(1, result); … … 249 247 assertEquals(0, result); 250 248 } 251 252 249 253 250 /** 254 251 * Test of addAnnotation method, of class JdbcAnnotationDao. 255 252 */ 256 253 @Test 257 public void testAddAnnotationExistingSource() throws SQLException {254 public void testAddAnnotationExistingSource() throws SQLException { 258 255 System.out.println("test_addAnnotation with an existing source"); 259 256 260 257 Annotation annotationToAdd = testInstances.getAnnotationToAdd();// existing sources 261 258 assertEquals(null, annotationToAdd.getURI()); 262 259 assertEquals(null, annotationToAdd.getTimeStamp()); 263 260 264 261 NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 265 262 SourceInfo si = new SourceInfo(); … … 268 265 si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID); 269 266 noesi.setSource(si); 270 267 271 268 final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>(); 272 269 map.put(noesi, noesi); 273 274 270 271 275 272 mockery.checking(new Expectations() { 276 { 277 oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class)));278 will(returnValue(map)); 273 { 274 oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class))); 275 will(returnValue(map)); 279 276 } 280 277 }); 281 282 Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5); 283 assertFalse(null ==result.getURI());284 assertFalse(null ==result.getTimeStamp());278 279 Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5); 280 assertFalse(null == result.getURI()); 281 assertFalse(null == result.getTimeStamp()); 285 282 assertEquals(annotationToAdd.getBody().getAny().get(0), result.getBody().getAny().get(0)); 286 283 assertEquals(annotationToAdd.getHeadline(), result.getHeadline()); 287 284 assertEquals(String.valueOf(5), result.getOwner().getRef()); 288 285 assertEquals(annotationToAdd.getPermissions(), result.getPermissions()); 289 286 290 287 SourceInfo expectedSi = annotationToAdd.getTargetSources().getTarget().get(0).getSource(); 291 288 SourceInfo resultSi = result.getTargetSources().getTarget().get(0).getSource(); 292 assertEquals(expectedSi.getLink(), resultSi.getLink()); 293 assertEquals(expectedSi.getRef(), resultSi.getRef()); 294 assertEquals(expectedSi.getVersion(), resultSi.getVersion()); 295 } 296 297 298 /** 289 assertEquals(expectedSi.getLink(), resultSi.getLink()); 290 assertEquals(expectedSi.getRef(), resultSi.getRef()); 291 assertEquals(expectedSi.getVersion(), resultSi.getVersion()); 292 } 293 294 /** 299 295 * Test of addAnnotation method, of class JdbcAnnotationDao. 300 296 */ 301 297 @Test 302 public void testAddAnnotationNewSource() throws SQLException {298 public void testAddAnnotationNewSource() throws SQLException { 303 299 System.out.println("test_addAnnotation with a new source"); 304 305 300 301 306 302 Annotation annotationToAdd = testInstances.getAnnotationToAddNewSource();// existing sources 307 303 assertEquals(null, annotationToAdd.getURI()); 308 304 assertEquals(null, annotationToAdd.getTimeStamp()); 309 310 305 306 311 307 NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 312 308 NewSourceInfo nsi = new NewSourceInfo(); … … 315 311 nsi.setVersion(null); 316 312 noesi.setNewSource(nsi); 317 318 313 314 319 315 NewOrExistingSourceInfo noesiTwo = new NewOrExistingSourceInfo(); 320 316 SourceInfo si = new SourceInfo(); … … 323 319 si.setVersion(null); 324 320 noesiTwo.setSource(si); 325 321 326 322 final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>(); 327 323 map.put(noesi, noesiTwo); 328 329 324 325 330 326 mockery.checking(new Expectations() { 331 { 332 oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class)));333 will(returnValue(map)); 327 { 328 oneOf(sourceDao).addTargetSources(with(aNonNull(Number.class)), with(aNonNull(List.class))); 329 will(returnValue(map)); 334 330 } 335 331 }); 336 337 Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5); 338 assertFalse(null ==result.getURI());339 assertFalse(null ==result.getTimeStamp());332 333 Annotation result = jdbcAnnotationDao.addAnnotation(annotationToAdd, 5); 334 assertFalse(null == result.getURI()); 335 assertFalse(null == result.getTimeStamp()); 340 336 assertEquals(annotationToAdd.getHeadline(), result.getHeadline()); 341 337 assertEquals(String.valueOf(5), result.getOwner().getRef()); 342 338 assertEquals(annotationToAdd.getPermissions(), result.getPermissions()); 343 339 344 340 NewSourceInfo expectedSi = annotationToAdd.getTargetSources().getTarget().get(0).getNewSource(); 345 341 SourceInfo resultSi = result.getTargetSources().getTarget().get(0).getSource(); 346 assertEquals(expectedSi.getLink(), resultSi.getLink()); 347 assertEquals(expectedSi.getVersion(), resultSi.getVersion()); 342 assertEquals(expectedSi.getLink(), resultSi.getLink()); 343 assertEquals(expectedSi.getVersion(), resultSi.getVersion()); 348 344 //the reference is replaced with the persistent one 349 assertEquals(si.getRef(), resultSi.getRef()); 345 assertEquals(si.getRef(), resultSi.getRef()); 350 346 ///// 351 347 352 348 // checking the bodies: the temporary reference should be replaced 353 349 String expBody = annotationToAdd.getBody().getAny().get(0).toString().replaceAll(TestBackendConstants._TEST_TEMP_SOURCE_ID, si.getRef()); 354 350 assertEquals(expBody, result.getBody().getAny().get(0).toString()); 355 351 } 356 357 358 @Test 359 public void testGetExternalID(){ 360 System.out.println("getAnnotationID"); 361 362 final AnnotationIdentifier externalId = jdbcAnnotationDao.getExternalID(2); 363 assertEquals(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT), externalId); 364 365 366 final AnnotationIdentifier externalIdThree = jdbcAnnotationDao.getExternalID(null); 367 assertEquals(null, externalIdThree.getUUID()); 368 369 } 370 352 353 @Test 354 public void testGetExternalID() { 355 System.out.println("getAnnotationID"); 356 357 final AnnotationIdentifier externalId = jdbcAnnotationDao.getExternalID(2); 358 assertEquals(new AnnotationIdentifier(TestBackendConstants._TEST_ANNOT_2_EXT), externalId); 359 360 361 final AnnotationIdentifier externalIdThree = jdbcAnnotationDao.getExternalID(null); 362 assertEquals(null, externalIdThree.getUUID()); 363 364 } 371 365 //////////// helpers ////////////////////// 372 373 374 366 } 375 376 -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/resources/test-data/InsertTestData.sql
r3300 r3361 41 41 INSERT INTO notebook (title, owner_id, external_id) VALUES ('Notebook 6', 5, '00000000-0000-0000-0000-000000000014'); --6 42 42 43 INSERT INTO annotation (owner_id,headline,body_xml, external_id ) VALUES (3, 'Sagrada Famiglia','<html><body>some html 1</body></html>', '00000000-0000-0000-0000-000000000021'); --243 INSERT INTO annotation (owner_id,headline,body_xml, external_id, time_stamp) VALUES (3, 'Sagrada Famiglia','<html><body>some html 1</body></html>', '00000000-0000-0000-0000-000000000021', '2013-08-12 11:25:00.383+02:00'); --2 44 44 INSERT INTO annotation (owner_id,headline,body_xml, external_id) VALUES (4, 'Gaudi','<html><body>some html 2 </body></html>', '00000000-0000-0000-0000-000000000022'); --3 45 45 INSERT INTO annotation (owner_id,headline,body_xml, external_id) VALUES (5, 'Art Nuveau','<html><body>some html 3</body></html>', '00000000-0000-0000-0000-000000000023'); --4
Note: See TracChangeset
for help on using the changeset viewer.