Changeset 3429
- Timestamp:
- 08/19/13 16:16:37 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java
r3409 r3429 45 45 public class AnnotationResource { 46 46 47 private DaoDispatcher requestor;47 private DaoDispatcher daoDispatcher; 48 48 @Context 49 49 private HttpServletRequest httpServletRequest; … … 60 60 @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}") 61 61 public JAXBElement<Annotation> getAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException { 62 final Number annotationID = requestor.getAnnotationInternalIdentifier(new AnnotationIdentifier(annotationIdentifier));63 final Annotation annotation = requestor.getAnnotation(annotationID);62 final Number annotationID = daoDispatcher.getAnnotationInternalIdentifier(new AnnotationIdentifier(annotationIdentifier)); 63 final Annotation annotation = daoDispatcher.getAnnotation(annotationID); 64 64 return new ObjectFactory().createAnnotation(annotation); 65 65 } … … 70 70 @Path("{annotationid: " + BackendConstants.regExpIdentifier + "}") 71 71 public String deleteAnnotation(@PathParam("annotationid") String annotationIdentifier) throws SQLException { 72 final Number annotationID = requestor.getAnnotationInternalIdentifier(new AnnotationIdentifier(annotationIdentifier));73 int[] resultDelete = requestor.deleteAnnotationWithSourcesAndPermissions(annotationID);72 final Number annotationID = daoDispatcher.getAnnotationInternalIdentifier(new AnnotationIdentifier(annotationIdentifier)); 73 int[] resultDelete = daoDispatcher.deleteAnnotation(annotationID); 74 74 String result = Integer.toString(resultDelete[0]); 75 75 return result; … … 86 86 Number userID = null; 87 87 if (remoteUser != null) { 88 userID = requestor.getUserInternalIdentifier(new UserIdentifier(remoteUser));88 userID = daoDispatcher.getUserInternalIdentifier(new UserIdentifier(remoteUser)); 89 89 } 90 Annotation newAnnotation = requestor.addAnnotationWithTargetSources(annotation, userID);90 Annotation newAnnotation = daoDispatcher.addUsersAnnotation(annotation, userID); 91 91 return (new ObjectFactory().createAnnotation(newAnnotation)); 92 92 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/DaoDispatcher.java
r3414 r3429 37 37 import eu.dasish.annotation.schema.Source; 38 38 import eu.dasish.annotation.schema.SourceInfo; 39 import eu.dasish.annotation.schema.Version; 39 40 import java.sql.SQLException; 40 41 import java.sql.Timestamp; … … 64 65 @Autowired 65 66 NotebookDao notebookDao; 67 68 ///////////// GETTERS ////////////////////////// 66 69 67 70 public Number getAnnotationInternalIdentifier(AnnotationIdentifier annotationIdentifier) { … … 81 84 } 82 85 83 /** 84 * 85 * @param versionID 86 * @param cachedID 87 * @return result[0] # deleted rows (versionID, cachedID) in the table 88 * "versions_cached_representations" result[1] # deleted rows in the table 89 * "cached_representation" 90 */ 91 public int[] deleteCachedForVersion(Number versionID, Number cachedID) { 92 int[] result = new int[2]; 93 result[0] = versionDao.deleteVersionCachedRepresentation(versionID, cachedID); 94 if (result[0] > 0) { 95 result[1] = cachedRepresentationDao.deleteCachedRepresentationInfo(cachedID); 96 } else { 97 result[1] = 0; 98 99 } 100 return result; 101 } 102 103 /** 104 * 105 * @param versionID 106 * @param cached 107 * @return result[0] = the internalId of the added (if it is not yet in th 108 * DB) cached representation result[1] # added rows to 109 * "versions_cached_representations" 110 */ 111 public Number[] addCachedForVersion(Number versionID, CachedRepresentationInfo cached) { 112 Number[] result = new Number[2]; 113 result[0] = cachedRepresentationDao.getInternalID(new CachedRepresentationIdentifier(cached.getRef())); 114 if (result[0] == null) { 115 result[0] = cachedRepresentationDao.addCachedRepresentationInfo(cached); 116 } 117 result[1] = versionDao.addVersionCachedRepresentation(versionID, result[0]); 118 return result; 119 } 120 121 /** 122 * 123 * @param versionID 124 * @return result[0] # deleted rows in "version" table result[1] # deleted 125 * rows in the joint table "versions_cached_representations" result[2] # 126 * deleted cached representations (which are not referred by other versions) 127 * 128 */ 129 public int[] deleteVersionWithCachedRepresentations(Number versionID) { 130 int[] result = new int[3]; 131 if (!versionDao.versionIsInUse(versionID)) { 132 List<Number> cachedRepresentations = versionDao.retrieveCachedRepresentationList(versionID); 133 result[1] = versionDao.deleteAllVersionCachedRepresentation(versionID); 134 result[0] = versionDao.deleteVersion(versionID); 135 result[2] = 0; 136 for (Number cachedID : cachedRepresentations) { 137 result[2] = result[2] + cachedRepresentationDao.deleteCachedRepresentationInfo(cachedID); 138 139 } 140 } else { 141 result[0] = 0; 142 result[1] = 0; 143 result[2] = 0; 144 } 145 return result; 146 } 147 148 /** 149 * 150 * @param sourceID 151 * @return result[0] # deleted rows in "source" table result[1] # deleted 152 * rows in "sources_versions" table name result[2] # deleted rows in 153 * "version" table 154 */ 155 public int[] deleteSourceWithVersions(Number sourceID) throws SQLException { 156 int[] result = new int[3]; 157 if (!sourceDao.sourceIsInUse(sourceID)) { 158 List<Number> versions = sourceDao.retrieveVersionList(sourceID); 159 result[1] = sourceDao.deleteAllSourceVersion(sourceID); 160 result[0] = sourceDao.deleteSource(sourceID); 161 result[2] = 0; 162 for (Number versionID : versions) { 163 int[] deleteVersion = deleteVersionWithCachedRepresentations(versionID); 164 result[2] = result[2] + deleteVersion[0]; 165 } 166 } else { 167 result[0] = 0; 168 result[1] = 0; 169 result[2] = 0; 170 } 171 return result; 172 173 } 174 175 /** 176 * @param source 177 * @return internal Id of the newly added source or -1 if the source is not 178 * added because no version for it; in the last case the rest-interface will 179 * return envelope asking to add a version (with the cached representation); 180 * after the clinet adds the version (s)he gets the version external ID 181 * which is to be set in source; the the client asks to add the source 182 * again. 183 * @throws SQLException 184 */ 185 public Number addSourceAndPairSourceVersion(NewSourceInfo newSource) throws SQLException { 186 Number versionID = versionDao.getInternalID(new VersionIdentifier(newSource.getVersion())); 187 if (versionID == null) { 188 System.out.println("Cannot add source because there is no version for it, and no cached representation. Create them first and try again."); 189 return -1; 190 } 191 Source source = new Source(); 192 SourceIdentifier externalIdentifier = new SourceIdentifier(); 193 source.setURI(externalIdentifier.toString()); 194 source.setLink(newSource.getLink()); 195 source.setVersion(newSource.getVersion()); 196 Number result = sourceDao.addSource(source); 197 final int sourceVersions = sourceDao.addSourceVersion(result, versionID); 198 return result; 199 } 200 201 /////////////////////////////////////////////// 202 /** 203 * 204 * @param annotationID 205 * @param sources 206 * @return the mapping temporarySourceID -> peristenExternalSOurceId adds a 207 * source from "sources" to the DB if it is not there, to the table 208 * "target_source" adds (annotationID, sourceID) to the joint table "annotations_sources" 209 * @throws SQLException 210 */ 211 public Map<String, String> addTargetSourcesToAnnotation(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException { 212 Map<String, String> result = new HashMap<String, String>(); 213 for (NewOrExistingSourceInfo noesi : sources) { 214 SourceInfo source = noesi.getSource(); 215 if (source != null) { 216 int affectedRows = annotationDao.addAnnotationSourcePair(annotationID, sourceDao.getInternalID(new SourceIdentifier(source.getRef()))); 217 } else { 218 Number newSourceID = addSourceAndPairSourceVersion(noesi.getNewSource()); 219 if (newSourceID.intValue() == -1) { 220 result.put(noesi.getNewSource().getId(), null); 221 } else { 222 result.put(noesi.getNewSource().getId(), sourceDao.getExternalID(newSourceID).toString()); 223 int affectedRows = annotationDao.addAnnotationSourcePair(annotationID, newSourceID); 224 } 225 } 226 } 227 return result; 228 } 229 230 //////////////////////////////////////////////////////////////////////// 231 public List<Number> getFilteredAnnotationIDs(String link, String text, String access, String namespace, UserIdentifier owner, Timestamp after, Timestamp before) { 232 233 List<Number> annotationIDs = null; 234 235 if (link != null) { 236 List<Number> sourceIDs = sourceDao.getSourcesForLink(link); 237 annotationIDs = annotationDao.retrieveAnnotationList(sourceIDs); 238 } 239 240 Number ownerID = null; 241 if (owner != null) { 242 ownerID = userDao.getInternalID(owner); 243 } 244 245 return annotationDao.getFilteredAnnotationIDs(annotationIDs, text, access, namespace, ownerID, after, before); 246 } 247 248 /** 249 * 250 * @param annotationId 251 * @return result[0] = # removed annotation rows (should be 1) result[1] = # 252 * removed "annotations_principals_permissions" rows result[2] = # removed 253 * "annotations_target_sources" rows result[3] = # deleted sources 254 */ 255 public int[] deleteAnnotationWithSourcesAndPermissions(Number annotationID) throws SQLException { 256 int[] result = new int[4]; 257 result[1] = annotationDao.deleteAnnotationPrincipalPermissions(annotationID); 258 List<Number> sourceIDs = annotationDao.retrieveSourceIDs(annotationID); 259 result[2] = annotationDao.deleteAllAnnotationSource(annotationID); 260 result[0] = annotationDao.deleteAnnotation(annotationID); 261 result[3] = 0; 262 for (Number sourceID : sourceIDs) { 263 int[] deleteSource = deleteSourceWithVersions(sourceID); 264 result[3] = result[3] + deleteSource[1]; 265 } 266 return result; 267 } 268 269 public Annotation getAnnotation(Number annotationID) throws SQLException { 86 public Annotation getAnnotation(Number annotationID) throws SQLException { 270 87 Annotation result = annotationDao.getAnnotationWithoutSources(annotationID); 271 88 List<Number> sourceIDs = annotationDao.retrieveSourceIDs(annotationID); … … 283 100 } 284 101 285 //need to return an envelope! 286 public Annotation addAnnotationWithTargetSources(Annotation annotation, Number userID) throws SQLException { 102 //////////////////////////////////////////////////////////////////////// 103 public List<Number> getFilteredAnnotationIDs(String link, String text, String access, String namespace, UserIdentifier owner, Timestamp after, Timestamp before) { 104 105 List<Number> annotationIDs = null; 106 107 if (link != null) { 108 List<Number> sourceIDs = sourceDao.getSourcesForLink(link); 109 annotationIDs = annotationDao.retrieveAnnotationList(sourceIDs); 110 } 111 112 Number ownerID = null; 113 if (owner != null) { 114 ownerID = userDao.getInternalID(owner); 115 } 116 117 return annotationDao.getFilteredAnnotationIDs(annotationIDs, text, access, namespace, ownerID, after, before); 118 } 119 120 121 122 /////////////// ADDERS ///////////////////////////////// 123 124 125 126 public Number[] addCachedForVersion(Number versionID, CachedRepresentationInfo cached) { 127 Number[] result = new Number[2]; 128 result[1] = cachedRepresentationDao.getInternalID(new CachedRepresentationIdentifier(cached.getRef())); 129 if (result[1] == null) { 130 result[1] = cachedRepresentationDao.addCachedRepresentationInfo(cached); 131 } 132 result[0] = versionDao.addVersionCachedRepresentation(versionID, result[1]); 133 return result; 134 135 } 136 137 138 public Number[] addSiblingVersionForSource(Number sourceID, Version version) throws SQLException { 139 Number[] result = new Number[2]; 140 result[0] = versionDao.getInternalID(new VersionIdentifier(version.getVersion())); // TOT: change to getURI after the schem is fixed 141 if (result[0] == null) { 142 result[0] = versionDao.addVersion(version); 143 } 144 result[1] = sourceDao.addSourceVersion(sourceID, result[0]); 145 return result; 146 } 147 148 149 public Map<String, String> addSourcesForAnnotation(Number annotationID, List<NewOrExistingSourceInfo> sources) throws SQLException { 150 Map<String, String> result = new HashMap<String, String>(); 151 for (NewOrExistingSourceInfo noesi : sources) { 152 SourceInfo source = noesi.getSource(); 153 if (source != null) { 154 int affectedRows = annotationDao.addAnnotationSourcePair(annotationID, sourceDao.getInternalID(new SourceIdentifier(source.getRef()))); 155 } else { 156 Source newSource = createSource(noesi.getNewSource()); 157 Version newVersion = createVersion(noesi.getNewSource()); 158 newSource.setVersion(newVersion.getVersion()); // TOTO: change to getURI after the schema is fixed 159 Number sourceID = sourceDao.addSource(newSource); 160 Number[] intermediateResult = addSiblingVersionForSource(sourceID, newVersion); 161 result.put(noesi.getNewSource().getId(), newSource.getURI().toString()); 162 int affectedRows = annotationDao.addAnnotationSourcePair(annotationID, sourceID); 163 } 164 } 165 return result; 166 } 167 168 169 public Annotation addUsersAnnotation(Annotation annotation, Number userID) throws SQLException { 287 170 288 171 Number annotationID = annotationDao.addAnnotation(annotation, userID); 289 172 290 173 List<NewOrExistingSourceInfo> sources = annotation.getTargetSources().getTarget(); 291 Map<String, String> sourceIdPairs = addTargetSourcesToAnnotation(annotationID, sources); 292 293 if (sourceIdPairs.containsValue(null)) { 294 // for one of the soirces there was no version and cached representation 295 // envelope 296 return annotation; 297 } 174 Map<String, String> sourceIdPairs = addSourcesForAnnotation(annotationID, sources); 175 298 176 String body = Helpers.serializeBody(annotation.getBody()); 299 177 String newBody = Helpers.replace(body, sourceIdPairs); … … 306 184 return newAnnotation; 307 185 } 186 187 188 ////////////// DELETERS ////////////////// 189 190 public int[] deleteCachedOfVersion(Number versionID, Number cachedID) { 191 int[] result = new int[2]; 192 result[0] = versionDao.deleteVersionCachedRepresentation(versionID, cachedID); 193 if (result[0] > 0) { 194 result[1] = cachedRepresentationDao.deleteCachedRepresentationInfo(cachedID); 195 } else { 196 result[1] = 0; 197 198 } 199 return result; 200 } 201 202 public int[] deleteAllCachedOfVersion(Number versionID) { 203 int[] result = new int[3]; 204 if (!versionDao.versionIsInUse(versionID)) { 205 List<Number> cachedRepresentations = versionDao.retrieveCachedRepresentationList(versionID); 206 result[1] = versionDao.deleteAllVersionCachedRepresentation(versionID); 207 result[0] = versionDao.deleteVersion(versionID); 208 result[2] = 0; 209 for (Number cachedID : cachedRepresentations) { 210 result[2] = result[2] + cachedRepresentationDao.deleteCachedRepresentationInfo(cachedID); 211 212 } 213 } else { 214 result[0] = 0; 215 result[1] = 0; 216 result[2] = 0; 217 } 218 return result; 219 } 220 221 222 223 public int[] deleteAllVersionsOfSource(Number sourceID) throws SQLException { 224 int[] result = new int[3]; 225 if (!sourceDao.sourceIsInUse(sourceID)) { 226 List<Number> versions = sourceDao.retrieveVersionList(sourceID); 227 result[1] = sourceDao.deleteAllSourceVersion(sourceID); 228 result[0] = sourceDao.deleteSource(sourceID); 229 result[2] = 0; 230 for (Number versionID : versions) { 231 int[] deleteVersion = deleteAllCachedOfVersion(versionID); 232 result[2] = result[2] + deleteVersion[0]; 233 } 234 } else { 235 result[0] = 0; 236 result[1] = 0; 237 result[2] = 0; 238 } 239 return result; 240 241 } 242 243 244 public int[] deleteAnnotation(Number annotationID) throws SQLException { 245 int[] result = new int[4]; 246 result[1] = annotationDao.deleteAnnotationPrincipalPermissions(annotationID); 247 List<Number> sourceIDs = annotationDao.retrieveSourceIDs(annotationID); 248 result[2] = annotationDao.deleteAllAnnotationSource(annotationID); 249 result[0] = annotationDao.deleteAnnotation(annotationID); 250 result[3] = 0; 251 for (Number sourceID : sourceIDs) { 252 int[] deleteSource = deleteAllVersionsOfSource(sourceID); 253 result[3] = result[3] + deleteSource[1]; 254 } 255 return result; 256 } 257 258 259 260 ////////////// HELPERS //////////////////// 261 private Source createSource(NewSourceInfo newSource) { 262 Source source = new Source(); 263 SourceIdentifier externalIdentifier = new SourceIdentifier(); 264 source.setURI(externalIdentifier.toString()); 265 source.setLink(newSource.getLink()); 266 return source; 267 } 268 269 ///////////////////////////////////////// 270 private Version createVersion(NewSourceInfo newSource) { 271 Version version = new Version(); 272 VersionIdentifier versionIdentifier = new VersionIdentifier(); 273 version.setVersion(versionIdentifier.toString()); // TODO change after the schem is fixed, shoul be setURI, 274 return version; 275 } 308 276 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/TestBackendConstants.java
r3380 r3429 79 79 public static final String _TEST_SOURCE_2_LINK = "http://nl.wikipedia.org/wiki/Antoni_Gaud%C3%AD"; 80 80 81 public static final int _TEST_SOURCE_1_VERSION_ID = 1;82 public static final int _TEST_SOURCE_2_VERSION_ID = 3;81 //public static final int _TEST_SOURCE_1_VERSION_ID = 1; 82 //public static final int _TEST_SOURCE_2_VERSION_ID = 3; 83 83 84 84 public static final String _TEST_CACHED_REPRESENTATION_1_EXT_ID_ = "00000000-0000-0000-0000-000000000051"; -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/DaoDispatcherTest.java
r3414 r3429 39 39 import java.sql.Timestamp; 40 40 import java.util.ArrayList; 41 import java.util.HashMap;42 41 import java.util.List; 43 42 import java.util.Map; … … 61 60 public class DaoDispatcherTest { 62 61 63 64 65 62 @Autowired 66 63 private DaoDispatcher daoDispatcher; 67 68 64 @Autowired 69 65 private Mockery mockery; 70 71 66 @Autowired 72 67 private UserDao userDao; … … 171 166 }); 172 167 173 int[] result = daoDispatcher.deleteCached ForVersion(6, 5);168 int[] result = daoDispatcher.deleteCachedOfVersion(6, 5); 174 169 assertEquals(2, result.length); 175 170 assertEquals(1, result[0]); … … 223 218 oneOf(versionDao).versionIsInUse(6); 224 219 will(returnValue(false)); 225 220 226 221 oneOf(versionDao).retrieveCachedRepresentationList(6); 227 222 will(returnValue(cachedList)); … … 229 224 oneOf(versionDao).deleteAllVersionCachedRepresentation(6); 230 225 will(returnValue(1)); 231 226 232 227 oneOf(versionDao).deleteVersion(6); 233 228 will(returnValue(1)); … … 235 230 oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5); 236 231 will(returnValue(0)); // cached is used by another version 237 238 239 240 } 241 }); 242 243 int[] result = daoDispatcher.delete VersionWithCachedRepresentations(6);232 233 234 235 } 236 }); 237 238 int[] result = daoDispatcher.deleteAllCachedOfVersion(6); 244 239 assertEquals(1, result[0]); //version 245 240 assertEquals(1, result[1]); // versions-cached 246 241 assertEquals(0, result[2]);//cached 5 is in use 247 242 248 243 //Another test 249 250 244 245 251 246 mockery.checking(new Expectations() { 252 247 { … … 257 252 258 253 259 int[] resultTwo = daoDispatcher.delete VersionWithCachedRepresentations(5); // version is in use by the source 4254 int[] resultTwo = daoDispatcher.deleteAllCachedOfVersion(5); // version is in use by the source 4 260 255 assertEquals(0, resultTwo[0]); 261 256 assertEquals(0, resultTwo[1]); … … 267 262 public void testDeleteSourceSourceWithVersions() throws SQLException { 268 263 // test 1: source in use by some annotation 269 264 mockery.checking(new Expectations() { 270 265 { 271 266 oneOf(sourceDao).sourceIsInUse(1); … … 274 269 }); 275 270 276 int[] result = daoDispatcher.delete SourceWithVersions(1); //the source is in use, should not be deleted271 int[] result = daoDispatcher.deleteAllVersionsOfSource(1); //the source is in use, should not be deleted 277 272 assertEquals(0, result[0]); // 278 273 assertEquals(0, result[1]); … … 285 280 oneOf(sourceDao).sourceIsInUse(5); 286 281 will(returnValue(false)); 287 282 288 283 oneOf(sourceDao).retrieveVersionList(5); 289 284 will(returnValue(versionList)); … … 291 286 oneOf(sourceDao).deleteAllSourceVersion(5); 292 287 will(returnValue(1)); 293 288 294 289 oneOf(sourceDao).deleteSource(5); 295 290 will(returnValue(1)); 296 291 297 292 oneOf(versionDao).versionIsInUse(7); 298 293 will(returnValue(false)); //not mentioned in the table "sources_versions" after deleteing(5,7) 299 294 300 295 oneOf(versionDao).retrieveCachedRepresentationList(7); 301 296 will(returnValue(new ArrayList<Number>())); // no cached representations for version 7, the list is just empty 302 297 303 298 oneOf(versionDao).deleteAllVersionCachedRepresentation(7); 304 299 305 300 oneOf(versionDao).deleteVersion(7); 306 301 will(returnValue(1)); 307 302 } 308 303 }); 309 310 311 int[] resultTwo = daoDispatcher.delete SourceWithVersions(5);// the source will be deleted because it is not referred by any annotation304 305 306 int[] resultTwo = daoDispatcher.deleteAllVersionsOfSource(5);// the source will be deleted because it is not referred by any annotation 312 307 assertEquals(3, resultTwo.length); 313 308 assertEquals(1, resultTwo[0]); // source 7 is deleted … … 316 311 } 317 312 318 319 320 321 313 /** 322 314 * Test of addSourceAndPairSourceVersion method, of class DaoDispatcher. … … 325 317 public void testAddSourceAndPairSourceVersion() throws Exception { 326 318 System.out.println("addSourceAndPairSourceVersion"); 327 finalNewSourceInfo newSource = new NewSourceInfo();328 newSource.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);329 newSource.setVersion(TestBackendConstants._TEST_VERSION_3_EXT_ID);// already added version, existing330 331 mockery.checking(new Expectations() {332 {333 oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_3_EXT_ID));334 will(returnValue(3));335 336 oneOf(sourceDao).addSource(with(aNonNull(Source.class)));337 will(returnValue(6));338 339 oneOf(sourceDao).addSourceVersion(6, 3);340 will(returnValue(1));341 342 }343 });344 345 Number result = daoDispatcher.addSourceAndPairSourceVersion(newSource);346 assertEquals(6, result.intValue());347 348 // Another test349 350 finalNewSourceInfo newSourceTwo = new NewSourceInfo();351 newSourceTwo.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);352 newSourceTwo.setVersion(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID);353 mockery.checking(new Expectations() {354 {355 oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID));356 will(returnValue(null));357 358 }359 });360 Number resultTwo = daoDispatcher.addSourceAndPairSourceVersion(newSourceTwo);361 assertEquals(-1, resultTwo.intValue());362 363 319 final NewSourceInfo newSource = new NewSourceInfo(); 320 newSource.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 321 newSource.setVersion(TestBackendConstants._TEST_VERSION_3_EXT_ID);// already added version, existing 322 323 // mockery.checking(new Expectations() { 324 // { 325 // oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_3_EXT_ID)); 326 // will(returnValue(3)); 327 // 328 // oneOf(sourceDao).addSource(with(aNonNull(Source.class))); 329 // will(returnValue(6)); 330 // 331 // oneOf(sourceDao).addSourceVersion(6, 3); 332 // will(returnValue(1)); 333 // 334 // } 335 // }); 336 // 337 // Number result = daoDispatcher.addSiblingVersionForSource(newSource); 338 // assertEquals(6, result.intValue()); 339 // 340 // // Another test 341 // 342 // final NewSourceInfo newSourceTwo = new NewSourceInfo(); 343 // newSourceTwo.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 344 // newSourceTwo.setVersion(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID); 345 // mockery.checking(new Expectations() { 346 // { 347 // oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID)); 348 // will(returnValue(null)); 349 // 350 // } 351 // }); 352 // Number resultTwo = daoDispatcher.addSourceAndPairSourceVersion(newSourceTwo); 353 // assertEquals(-1, resultTwo.intValue()); 354 355 364 356 } 365 357 … … 370 362 public void testAddTargetSourcesToAnnotation() throws Exception { 371 363 System.out.println("addTargetSourcesToAnnotation"); 372 373 NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 374 NewSourceInfo nsi = new NewSourceInfo(); 375 nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 376 nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID); 377 nsi.setVersion(null); 378 noesi.setNewSource(nsi); 379 380 381 NewOrExistingSourceInfo noesiTwo = new NewOrExistingSourceInfo(); 364 365 // test 1: adding an existing source 366 NewOrExistingSourceInfo noesiOne = new NewOrExistingSourceInfo(); 367 // this corresponds to the Source # 1 in teh test database 368 final SourceIdentifier sourceIdentifier = new SourceIdentifier(TestBackendConstants._TEST_SOURCE_1_EXT_ID); 382 369 SourceInfo si = new SourceInfo(); 383 si.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 384 final SourceIdentifier sourceIdentifier = new SourceIdentifier(); 385 si.setRef(sourceIdentifier.toString()); 386 si.setVersion(null); 387 noesiTwo.setSource(si); 388 389 final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>(); 390 map.put(noesi, noesiTwo); 370 si.setLink(TestBackendConstants._TEST_SOURCE_1_LINK); 371 si.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID); 372 si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID); 373 noesiOne.setSource(si); 374 List<NewOrExistingSourceInfo> sources = new ArrayList<NewOrExistingSourceInfo>(); 375 sources.add(noesiOne); 376 377 // mockery.checking(new Expectations() { 378 // { 379 // oneOf(sourceDao).getInternalID(sourceIdentifier); 380 // will(returnValue(1)); 381 // 382 // oneOf(annotationDao).addAnnotationSourcePair(1, 1); 383 // will(returnValue(1)); 384 // } 385 // }); 386 // 387 // Map<String, String> result = daoDispatcher.addTargetSourcesToAnnotation(1, sources); 388 // assertEquals(0, result.size()); 389 // 390 // // test 2: adding a new source 391 // 392 // NewOrExistingSourceInfo noesiTwo = new NewOrExistingSourceInfo(); 393 // NewSourceInfo nsi = new NewSourceInfo(); 394 // nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 395 // nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID); 396 // nsi.setVersion(null); 397 // noesiTwo.setNewSource(nsi); 398 // 399 // 400 // NewOrExistingSourceInfo noesiTwoImage = new NewOrExistingSourceInfo(); 401 // SourceInfo siTwo = new SourceInfo(); 402 // siTwo.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 403 // final SourceIdentifier sourceIdentifierTwo = new SourceIdentifier(); 404 // si.setRef(sourceIdentifier.toString()); 405 // si.setVersion(null); 406 // noesiTwo.setSource(si); 407 // 408 // final Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> map = new HashMap<NewOrExistingSourceInfo, NewOrExistingSourceInfo>(); 409 // map.put(noesi, noesiTwo); 391 410 392 411 … … 406 425 407 426 408 427 409 428 } 410 429 … … 435 454 @Test 436 455 public void testDeleteAnnotationWithSources() throws Exception { 437 System.out.println("deleteAnnotationWithSources");438 Number annotationID = null;439 DaoDispatcher instance = new DaoDispatcher();440 int[] expResult = null;441 int[] result = instance.deleteAnnotationWithSourcesAndPermissions(annotationID);442 assertArrayEquals(expResult, result);443 // TODO review the generated test code and remove the default call to fail.444 fail("The test case is a prototype.");456 // System.out.println("deleteAnnotationWithSources"); 457 // Number annotationID = null; 458 // DaoDispatcher instance = new DaoDispatcher(); 459 // int[] expResult = null; 460 // int[] result = instance.deleteAnnotationAllSourcesAndPermissions(annotationID); 461 // assertArrayEquals(expResult, result); 462 // // TODO review the generated test code and remove the default call to fail. 463 // fail("The test case is a prototype."); 445 464 } 446 465 … … 450 469 @Test 451 470 public void testGetAnnotation() throws Exception { 452 System.out.println("getAnnotation");453 Number annotationID = null;454 DaoDispatcher instance = new DaoDispatcher();455 Annotation expResult = null;456 Annotation result = instance.getAnnotation(annotationID);457 assertEquals(expResult, result);458 // TODO review the generated test code and remove the default call to fail.459 fail("The test case is a prototype.");471 // System.out.println("getAnnotation"); 472 // Number annotationID = null; 473 // DaoDispatcher instance = new DaoDispatcher(); 474 // Annotation expResult = null; 475 // Annotation result = instance.getAnnotation(annotationID); 476 // assertEquals(expResult, result); 477 // // TODO review the generated test code and remove the default call to fail. 478 // fail("The test case is a prototype."); 460 479 } 461 480 … … 474 493 // result[2] = # removed annotation rows (should be 1) 475 494 476 int[] result = daoDispatcher.deleteAnnotationWithSourcesAndPermissions(5);477 assertEquals(3, result[0]);478 assertEquals(2, result[1]);479 assertEquals(1, result[2]);480 481 // now, try to delete the same annotation one more time482 // if it has been already deleted then the method under testing should return 0483 484 result = daoDispatcher.deleteAnnotationWithSourcesAndPermissions(5);485 assertEquals(0, result[0]);486 assertEquals(0, result[1]);487 assertEquals(0, result[2]);495 // int[] result = daoDispatcher.deleteAnnotationWithSourcesAndPermissions(5); 496 // assertEquals(3, result[0]); 497 // assertEquals(2, result[1]); 498 // assertEquals(1, result[2]); 499 // 500 // // now, try to delete the same annotation one more time 501 // // if it has been already deleted then the method under testing should return 0 502 // 503 // result = daoDispatcher.deleteAnnotationWithSourcesAndPermissions(5); 504 // assertEquals(0, result[0]); 505 // assertEquals(0, result[1]); 506 // assertEquals(0, result[2]); 488 507 } 489 508
Note: See TracChangeset
for help on using the changeset viewer.