Changeset 3396
- Timestamp:
- 08/15/13 17:01:59 (11 years ago)
- Location:
- DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcAnnotationDaoTest.java
r3380 r3396 215 215 will(returnValue(sourceInfoList)); 216 216 217 oneOf(sourceDao).contructNewOrExistingSourceInfo(sourceInfoList);218 will(returnValue(noeSourceInfos));219 217 } 220 218 }); … … 349 347 sources.add(1); 350 348 sources.add(2); 351 List<Number> result = jdbcAnnotationDao. getAnnotationIDsForSources(sources);349 List<Number> result = jdbcAnnotationDao.retrieveAnnotationList(sources); 352 350 assertEquals (2, result.size()); 353 351 assertEquals(2, result.get(0)); … … 466 464 } 467 465 468 //////////// helpers ////////////////////// 466 /** 467 * Test of contructNewOrExistingSourceInfo method, of class JdbcSourceDao. 468 */ 469 @Test 470 public void testContructNewOrExistingSourceInfo() { 471 System.out.println("contructNewOrExistingSourceInfo"); 472 473 List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>(); 474 475 SourceInfo sourceInfoOne = new SourceInfo(); 476 sourceInfoOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK); 477 sourceInfoOne.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID); 478 sourceInfoOne.setRef(TestBackendConstants._TEST_VERSION_1_EXT_ID); 479 480 SourceInfo sourceInfoTwo = new SourceInfo(); 481 sourceInfoTwo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK); 482 sourceInfoTwo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID); 483 sourceInfoTwo.setRef(TestBackendConstants._TEST_VERSION_3_EXT_ID); 484 485 sourceInfoList.add(sourceInfoOne); 486 sourceInfoList.add(sourceInfoTwo); 487 488 // NewOrExistingSourceInfos result = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList); 489 // assertEquals(2, result.getTarget().size()); 490 // assertEquals(sourceInfoOne, result.getTarget().get(0).getSource()); 491 // assertEquals(sourceInfoTwo, result.getTarget().get(1).getSource()); 492 493 } 494 495 // /** 496 // * Test of addTargetSources method, of class JdbcSourceDao. public 497 // * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> 498 // * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> 499 // * sources) 500 // */ 501 // @Test 502 // public void testAddTargetSourcesOnExistingSource() { 503 // System.out.println("addTargetSources : adding the old source"); 504 // 505 // NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 506 // SourceInfo si = new SourceInfo(); 507 // si.setLink(TestBackendConstants._TEST_SOURCE_1_LINK); 508 // si.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID); 509 // si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID); 510 // noesi.setSource(si); 511 // 512 // List<NewOrExistingSourceInfo> listnoesi = new ArrayList<NewOrExistingSourceInfo>(); 513 // listnoesi.add(noesi); 514 // 515 // try { 516 // Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesi); 517 // assertEquals(0, result.size()); // no new peristsent source IDs are produced 518 // } catch (SQLException e) { 519 // System.out.println(e); 520 // } 521 // } 522 // 523 // /** 524 // * Test of addTargetSources method, of class JdbcSourceDao. public 525 // * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo> 526 // * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo> 527 // * sources) 528 // */ 529 // @Test 530 // public void testAddTargetSourcesOnNewSource() { 531 // System.out.println("addTargetSources : adding the new source"); 532 // 533 // NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo(); 534 // NewSourceInfo nsi = new NewSourceInfo(); 535 // nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK); 536 // nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID); 537 // nsi.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID); 538 // noesi.setNewSource(nsi); 539 // 540 // List<NewOrExistingSourceInfo> listnoesiTwo = new ArrayList<NewOrExistingSourceInfo>(); 541 // listnoesiTwo.add(noesi); 542 // 543 // mockery.checking(new Expectations() { 544 // { 545 // oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID)); 546 // will(returnValue(1)); 547 // } 548 // }); 549 // 550 // try { 551 // Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo); 552 // assertEquals(1, result.size());// a new identifier must be produced 553 // SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(TestBackendConstants._TEST_TEMP_SOURCE_ID)); 554 // assertFalse(null == sourceIdentifier.getUUID()); // check if a proper uuid has been assigned 555 // } catch (SQLException e) { 556 // System.out.print(e); 557 // } 558 // 559 // } 560 // 469 561 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcCachedRepresentationDaoTest.java
r3380 r3396 21 21 import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier; 22 22 import eu.dasish.annotation.schema.CachedRepresentationInfo; 23 import java.util.ArrayList;24 import java.util.List;25 23 import org.junit.Test; 26 24 import static org.junit.Assert.*; … … 38 36 @ContextConfiguration({"/spring-test-config/dataSource.xml", "/spring-test-config/mockery.xml", "/spring-test-config/mockAnnotationDao.xml", 39 37 "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml", 40 "/spring-test-config/mockSourceDao.xml", "/spring- config/cachedRepresentationDao.xml"})38 "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockVersionDao.xml", "/spring-config/cachedRepresentationDao.xml"}) 41 39 public class JdbcCachedRepresentationDaoTest extends JdbcResourceDaoTest{ 42 40 … … 57 55 @Test 58 56 public void testGetExternalId() { 59 // INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000051', 'text/html', 'latex', 'text', 'corpus1'); --160 57 System.out.println("getExternalId"); 61 58 Number internalID = 1; … … 64 61 assertEquals(expResult, result); 65 62 } 63 66 64 67 65 /** … … 73 71 System.out.println("getInternalId"); 74 72 CachedRepresentationIdentifier externalID = new CachedRepresentationIdentifier(TestBackendConstants._TEST_CACHED_REPRESENTATION_1_EXT_ID_); 75 Number expResult = 1;76 73 Number result = jdbcCachedRepresentationDao.getInternalID(externalID); 77 assertEquals( expResult, result);74 assertEquals(1, result.intValue()); 78 75 } 79 76 … … 84 81 @Test 85 82 public void testGetCachedRepresentationInfo() { 86 // INSERT INTO cached_representation_info (external_id, mime_type, tool, type_, where_is_the_file) VALUES ('00000000-0000-0000-0000-000000000051', 'text/html', 'latex', 'text', 'corpus1'); --187 83 System.out.println("getCachedRepresentationInfo"); 88 84 Number internalID = 1; … … 101 97 } 102 98 103 /** 104 * Test of retrieveCachedRepresentationList method, of class JdbcCachedRepresentationDao. 105 * public List<Number> retrieveCachedRepresentationList(Number versionID); 106 */ 107 @Test 108 public void testRetrieveCachedRepresentationList() { 109 110 System.out.println("retrieveCachedRepresentationList"); 111 Number versionID = 1; 112 113 List expResult = new ArrayList<Number>(); 114 expResult.add(1); 115 expResult.add(5); 116 117 List result = jdbcCachedRepresentationDao.retrieveCachedRepresentationList(versionID); 118 assertEquals(expResult, result); 119 } 120 99 121 100 /** 122 101 * Test of deleteCachedRepresentationInfo method, of class JdbcCachedRepresentationDao. … … 161 140 162 141 163 164 165 142 /** 143 * Test of addVersion method, of class JdbcVersionDao. 144 */ 145 @Test 146 public void testAddCachedForVersion() { 147 System.out.println("test addCachedForVersion"); 148 149 final CachedRepresentationInfo cached = new CachedRepresentationInfo(); 150 cached.setMimeType("text/plain"); 151 cached.setTool("vi"); 152 cached.setType("text"); 153 cached.setRef(null); 154 155 Number[] result = jdbcCachedRepresentationDao.addCachedForVersion(6, cached); 156 assertEquals(8, result[0].intValue()); 157 assertEquals(1, result[1].intValue()); 158 } 159 160 /** 161 * 162 */ 163 @Test 164 public void tesDeleteCachedForVersion() { 165 System.out.println("test delete CachedRepresentationForVersion"); 166 System.out.println("deleteVersion"); 167 168 int[] result = jdbcCachedRepresentationDao.deleteCachedForVersion(6, 5); 169 assertEquals(1, result[0]); //versions-cached 170 assertEquals(0, result[1]);//cached 5 is in use 171 172 int[] resultTwo = jdbcCachedRepresentationDao.deleteCachedForVersion(6, 4); // no such pair 173 assertEquals(0, resultTwo[0]); 174 assertEquals(0, resultTwo[1]); 175 176 177 } 166 178 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcSourceDaoTest.java
r3380 r3396 22 22 import eu.dasish.annotation.backend.identifiers.SourceIdentifier; 23 23 import eu.dasish.annotation.backend.identifiers.VersionIdentifier; 24 import eu.dasish.annotation.schema.NewOrExistingSourceInfo;25 import eu.dasish.annotation.schema.NewOrExistingSourceInfos;26 import eu.dasish.annotation.schema.NewSourceInfo;27 24 import eu.dasish.annotation.schema.Source; 28 25 import eu.dasish.annotation.schema.SourceInfo; … … 30 27 import java.util.ArrayList; 31 28 import java.util.List; 32 import java.util.Map;33 29 import org.jmock.Expectations; 34 30 import org.jmock.Mockery; 35 31 import org.junit.Test; 36 32 import static org.junit.Assert.*; 33 import org.junit.Ignore; 37 34 import org.junit.runner.RunWith; 38 35 import org.springframework.beans.factory.annotation.Autowired; … … 81 78 } 82 79 83 84 85 80 /** 86 81 * Test of getSource method, of class JdbcSourceDao. … … 104 99 assertEquals(TestBackendConstants._TEST_SOURCE_1_LINK, result.getLink()); 105 100 assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, result.getVersion()); 106 //TODO: time stamp is not check: do not know with what to compare :\ 107 } 108 109 /** 110 * Test of deleteSourceVersionRows method, of class JdbcSourceDao. 111 */ 112 @Test 113 public void testDeleteSourceVersionRows() { 114 System.out.println("DeleteSourceVersionRows"); 115 Number internalID = 4; 116 int result = jdbcSourceDao.deleteSourceVersionRows(internalID); 117 assertEquals(1, result); 118 119 Number internalIDNoExist = 6; 120 int resultTwo = jdbcSourceDao.deleteSourceVersionRows(internalIDNoExist); 121 assertEquals(0, resultTwo); 101 //TODO: time stamp is not checked: do not know with what to compare 122 102 } 123 103 … … 128 108 public void testDeleteSource() { 129 109 System.out.println("deleteSource"); 130 110 131 111 // test 1 132 Number internalID = 1;133 int result = jdbcSourceDao.deleteSource(internalID);134 assertEquals(0, result ); // the source is in use, should not be deleted112 int[] result = jdbcSourceDao.deleteSource(1); //the source is in use, should not be deleted 113 assertEquals(0, result[0]); // 114 assertEquals(0, result[1]); 135 115 136 116 // test 2 137 final List<Number> versions = new ArrayList<Number>();138 version s.add(5);139 mockery.checking(new Expectations() {140 {141 oneOf(versionDao).retrieveVersionList(5);142 will(returnValue(versions));143 144 oneOf(versionDao).deleteVersion(5);145 will(returnValue(1)); // no other sources refer to this version # 5146 }147 }); 148 149 int resultTwo = jdbcSourceDao.deleteSource(5);150 assertEquals(1, resultTwo ); // the source will be deleted because it is not referred by any annotation117 final int[] versionDeleted = new int[3]; 118 versionDeleted[0] = 0; // versions_cahced_representations 119 versionDeleted[1] = 1; // version deleted 120 versionDeleted[2] = 0; // deleted cached representations; version 7 does not have them 121 mockery.checking(new Expectations() { 122 { 123 oneOf(versionDao).deleteVersion(7); 124 will(returnValue(versionDeleted)); // no other sources refer to this version # 5 125 } 126 }); 127 128 int[] resultTwo = jdbcSourceDao.deleteSource(5);// the source will be deleted because it is not referred by any annotation 129 assertEquals(1, resultTwo[0]); // row (5,7) in "sorces_versions" is deleted 130 assertEquals(1, resultTwo[1]); //source 5 is deleted from "source" table 151 131 } 152 132 … … 155 135 */ 156 136 @Test 157 public void testAddSource() {137 public void testAddSource() throws SQLException { 158 138 System.out.println("addSource"); 159 139 160 String link = "http://www.sagradafamilia.cat/"; 161 162 // existing version140 String link = "http://www.sagradafamilia.cat/"; 141 142 // test 1: existing version 163 143 Source freshSource = new Source(); 164 144 freshSource.setLink(link); … … 166 146 freshSource.setURI(null); 167 147 freshSource.setTimeSatmp(null); 168 148 169 149 mockery.checking(new Expectations() { 170 150 { … … 173 153 } 174 154 }); 175 176 try { 177 Number result = jdbcSourceDao.addSource(freshSource); 178 assertEquals(6, result); 179 Map<String, Object> addedSource = jdbcSourceDao.getRawSource(result); 180 assertEquals(link, addedSource.get("link_uri")); 181 assertEquals(1, addedSource.get("version_id")); 182 assertFalse(null==addedSource.get("external_id")); 183 } catch (SQLException e) { 184 System.out.println(e); 185 } 155 156 Number result = jdbcSourceDao.addSource(freshSource); 157 assertEquals(6, result); 186 158 187 ////////// test 2 non-existing source 159 mockery.checking(new Expectations() { 160 { 161 oneOf(versionDao).getExternalID(1); // used in getSource 162 will(returnValue(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID))); 163 164 165 } 166 }); 167 Source addedSource = jdbcSourceDao.getSource(result); 168 assertEquals(link, addedSource.getLink()); 169 assertEquals(TestBackendConstants._TEST_VERSION_1_EXT_ID, addedSource.getVersion()); 170 assertFalse(null == addedSource.getURI()); 171 172 ////////// test 2 non-existing version 188 173 freshSource.setVersion(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID); 189 174 mockery.checking(new Expectations() { 190 175 { 191 176 oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_NONEXIST_EXT_ID)); … … 193 178 } 194 179 }); 195 196 try { 197 Number result = jdbcSourceDao.addSource(freshSource); 198 assertEquals(-1, result); 199 } catch (SQLException e) { 200 System.out.println(e); 201 } 202 180 181 182 Number resultTwo = jdbcSourceDao.addSource(freshSource); 183 assertEquals(-1, resultTwo); // addversion (preferably with cached representation 184 203 185 } 204 186 … … 235 217 236 218 /** 237 * Test of contructNewOrExistingSourceInfo method, of class JdbcSourceDao.238 */239 @Test240 public void testContructNewOrExistingSourceInfo() {241 System.out.println("contructNewOrExistingSourceInfo");242 243 List<SourceInfo> sourceInfoList = new ArrayList<SourceInfo>();244 245 SourceInfo sourceInfoOne = new SourceInfo();246 sourceInfoOne.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);247 sourceInfoOne.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);248 sourceInfoOne.setRef(TestBackendConstants._TEST_VERSION_1_EXT_ID);249 250 SourceInfo sourceInfoTwo = new SourceInfo();251 sourceInfoTwo.setLink(TestBackendConstants._TEST_SOURCE_2_LINK);252 sourceInfoTwo.setRef(TestBackendConstants._TEST_SOURCE_2_EXT_ID);253 sourceInfoTwo.setRef(TestBackendConstants._TEST_VERSION_3_EXT_ID);254 255 sourceInfoList.add(sourceInfoOne);256 sourceInfoList.add(sourceInfoTwo);257 258 NewOrExistingSourceInfos result = jdbcSourceDao.contructNewOrExistingSourceInfo(sourceInfoList);259 assertEquals(2, result.getTarget().size());260 assertEquals(sourceInfoOne, result.getTarget().get(0).getSource());261 assertEquals(sourceInfoTwo, result.getTarget().get(1).getSource());262 263 }264 265 /**266 * Test of addTargetSources method, of class JdbcSourceDao. public267 * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>268 * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>269 * sources)270 */271 @Test272 public void testAddTargetSourcesOnExistingSource() {273 System.out.println("addTargetSources : adding the old source");274 275 NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();276 SourceInfo si = new SourceInfo();277 si.setLink(TestBackendConstants._TEST_SOURCE_1_LINK);278 si.setRef(TestBackendConstants._TEST_SOURCE_1_EXT_ID);279 si.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);280 noesi.setSource(si);281 282 List<NewOrExistingSourceInfo> listnoesi = new ArrayList<NewOrExistingSourceInfo>();283 listnoesi.add(noesi);284 285 try {286 Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesi);287 assertEquals(0, result.size()); // no new peristsent source IDs are produced288 } catch (SQLException e) {289 System.out.println(e);290 }291 }292 293 /**294 * Test of addTargetSources method, of class JdbcSourceDao. public295 * Map<NewOrExistingSourceInfo, NewOrExistingSourceInfo>296 * addTargetSources(Number annotationID, List<NewOrExistingSourceInfo>297 * sources)298 */299 @Test300 public void testAddTargetSourcesOnNewSource() {301 System.out.println("addTargetSources : adding the new source");302 303 NewOrExistingSourceInfo noesi = new NewOrExistingSourceInfo();304 NewSourceInfo nsi = new NewSourceInfo();305 nsi.setLink(TestBackendConstants._TEST_NEW_SOURCE_LINK);306 nsi.setId(TestBackendConstants._TEST_TEMP_SOURCE_ID);307 nsi.setVersion(TestBackendConstants._TEST_VERSION_1_EXT_ID);308 noesi.setNewSource(nsi);309 310 List<NewOrExistingSourceInfo> listnoesiTwo = new ArrayList<NewOrExistingSourceInfo>();311 listnoesiTwo.add(noesi);312 313 mockery.checking(new Expectations() {314 {315 oneOf(versionDao).getInternalID(new VersionIdentifier(TestBackendConstants._TEST_VERSION_1_EXT_ID));316 will(returnValue(1));317 }318 });319 320 try {321 Map<String, String> result = jdbcSourceDao.addTargetSources(5, listnoesiTwo);322 assertEquals(1, result.size());// a new identifier must be produced323 SourceIdentifier sourceIdentifier = new SourceIdentifier(result.get(TestBackendConstants._TEST_TEMP_SOURCE_ID));324 assertFalse(null == sourceIdentifier.getUUID()); // check if a proper uuid has been assigned325 } catch (SQLException e) {326 System.out.print(e);327 }328 329 }330 331 /**332 219 * test public List<Number> getSourcesForLink(String link) 333 * 334 **/ 335 @Test 336 public void tesGetSourcesForLink(){ 220 * 221 * 222 */ 223 @Test 224 public void tesGetSourcesForLink() { 337 225 System.out.println(" test getSourcesForLink"); 338 226 339 227 String substring = "http://nl.wikipedia.org"; 340 List<Number> result 228 List<Number> result = jdbcSourceDao.getSourcesForLink(substring); 341 229 assertEquals(2, result.size()); 342 230 assertEquals(1, result.get(0)); 343 assertEquals(2, result.get(1)); 344 } 345 231 assertEquals(2, result.get(1)); 232 } 233 234 /* Test of retrieveVersionList method, of class JdbcSourceDao. 235 */ 236 @Test 237 public void testRetrieveVersionList() { 238 System.out.println("retrieveVersionList"); 239 Number sourceID = 1; 240 List<Number> result = jdbcSourceDao.retrieveVersionList(sourceID); 241 assertEquals(1, result.get(0)); 242 assertEquals(2, result.get(1)); 243 } 346 244 } -
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/dao/impl/JdbcVersionDaoTest.java
r3380 r3396 20 20 import eu.dasish.annotation.backend.TestBackendConstants; 21 21 import eu.dasish.annotation.backend.dao.CachedRepresentationDao; 22 import eu.dasish.annotation.backend.identifiers.CachedRepresentationIdentifier; 22 23 import eu.dasish.annotation.backend.identifiers.VersionIdentifier; 24 import eu.dasish.annotation.schema.CachedRepresentationInfo; 23 25 import eu.dasish.annotation.schema.Version; 24 26 import java.util.ArrayList; … … 28 30 import org.junit.Test; 29 31 import static org.junit.Assert.*; 32 import org.junit.Ignore; 30 33 import org.junit.runner.RunWith; 31 34 import org.springframework.beans.factory.annotation.Autowired; … … 41 44 "/spring-test-config/mockUserDao.xml", "/spring-test-config/mockPermissionsDao.xml", "/spring-test-config/mockNotebookDao.xml", 42 45 "/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockCachedRepresentationDao.xml", "/spring-config/versionDao.xml"}) 46 public class JdbcVersionDaoTest extends JdbcResourceDaoTest { 43 47 44 public class JdbcVersionDaoTest extends JdbcResourceDaoTest{45 46 48 @Autowired 47 49 JdbcVersionDao jdbcVersionDao; 48 49 50 @Autowired 50 private CachedRepresentationDao cachedRepresentationDao; 51 51 private CachedRepresentationDao cachedRepresentationDao; 52 52 @Autowired 53 53 private Mockery mockery; 54 55 54 56 55 /** 57 56 * Test of getExternalId method, of class JdbcVersionDao. … … 91 90 92 91 /** 93 * Test of retrieveVersionList method, of class JdbcVersionDao. 94 */ 95 @Test 96 public void testRetrieveVersionList() { 97 System.out.println("retrieveVersionList"); 98 Number sourceID = 1; 99 // INSERT INTO sources_versions (source_id, version_id) VALUES (1, 1); 100 // INSERT INTO sources_versions (source_id, version_id) VALUES (1, 2); 101 List<Number> result = jdbcVersionDao.retrieveVersionList(sourceID); 102 assertEquals(1, result.get(0)); 103 assertEquals(2, result.get(1)); 104 } 105 106 /** 107 * Test of deleteVersionCachedRepresentationRows method, of class JdbcVersionDao. 108 */ 109 @Test 110 public void testDeleteVersionCachedRepresentationRows() { 111 System.out.println("deleteVersion"); 112 Number internalID = 6; // there is no sources (in target_source and sources_versions - sibling table) connected to this version in the test table 113 int result = jdbcVersionDao.deleteVersionCachedRepresentationRow(internalID); 114 assertEquals(1, result); 115 } 116 117 /** 92 * 93 * 94 * /** 118 95 * Test of deleteVersion method, of class JdbcVersionDao. 119 96 */ … … 121 98 public void testDeleteVersion() { 122 99 System.out.println("deleteVersion"); 123 final Number internalID = 6; // there is no sources (in target_source and sources_versions - sibling table) connected to this version in the test table124 final Number cachedID =5;125 final List<Number> versions = new ArrayList<Number>();126 versions.add(cachedID);127 128 //jdbcCachedRepresentationDao.retrieveCachedRepresentationList(internalID);129 //jdbcCachedRepresentationDao.deleteCachedRepresentationInfo(cachedID);130 131 100 mockery.checking(new Expectations() { 132 { 133 oneOf(cachedRepresentationDao).retrieveCachedRepresentationList(internalID); 134 will(returnValue(versions)); 135 136 oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(cachedID); 101 { 102 oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5); 137 103 will(returnValue(0)); 138 104 139 105 } 140 106 }); 141 142 int result = jdbcVersionDao.deleteVersion(internalID); 143 assertEquals(1, result); 144 145 // try to delete one more time 146 mockery.checking(new Expectations() { 147 { 148 oneOf(cachedRepresentationDao).retrieveCachedRepresentationList(internalID); 149 will(returnValue(new ArrayList<Number>())); 150 151 } 152 }); 153 int resultTwo = jdbcVersionDao.deleteVersion(internalID); 154 assertEquals(0, resultTwo); 155 156 // the version in use, shoul not be deleted 157 final Number internalIDNotToDelete = 4; 158 int resultThree = jdbcVersionDao.deleteVersion(internalIDNotToDelete); 159 assertEquals(0, resultThree); 107 int[] result = jdbcVersionDao.deleteVersion(6); 108 assertEquals(1, result[0]); //versions-cached 109 assertEquals(1, result[1]); // version 110 assertEquals(0, result[2]);//cached 5 is in use 111 112 113 int[] resultTwo = jdbcVersionDao.deleteVersion(5); // version is in use by the source 4 114 assertEquals(0, resultTwo[0]); 115 assertEquals(0, resultTwo[1]); 116 assertEquals(0, resultTwo[2]); 117 160 118 } 161 119 … … 166 124 public void testAddVersion() { 167 125 System.out.println("addVersion"); 168 169 Version freshVersion = new Version(); 170 126 127 Version freshVersion = new Version(); 128 171 129 Number result = jdbcVersionDao.addVersion(freshVersion); 172 130 assertEquals(8, result); 173 131 Version addedVersion = jdbcVersionDao.getVersion(result); 174 assertFalse(null==addedVersion.getVersion()); 175 132 assertFalse(null == addedVersion.getVersion()); 176 133 } 134 135 136 137 177 138 178 179 139 /** 180 * test 181 * public int deleteCachedRepresentationForSource(Number sourceID, Number cachedRepresentationID) 182 * 183 **/ 184 185 140 * Test of retrieveCachedRepresentationList method, of class JdbcVersionDao. 141 * public List<Number> retrieveCachedRepresentationList(Number versionID); 142 */ 186 143 @Test 187 public void tesDeleteCachedRepresentationForSource() { 188 System.out.println("test delete CachedRepresentationForSource"); 189 190 /// TEST 1 ///// 191 mockery.checking(new Expectations() { 192 { 193 oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(5); 194 will(returnValue(0)); 195 196 } 197 }); 198 int[] result = jdbcVersionDao.deleteCachedRepresentationForSource(1, 5); // source 1 has versions {1,2}, versions 1 and 2 have cached representations {1, 5} and {3} respectively 199 assertEquals(1, result[0]); 200 assertEquals(0, result[1]); //cahced representation 5 is also connected version 6, therefore cannot be removed 201 202 203 // TEST 2 //////// 204 mockery.checking(new Expectations() { 205 { 206 oneOf(cachedRepresentationDao).deleteCachedRepresentationInfo(4); 207 will(returnValue(1)); 208 209 } 210 }); 211 int[] result_2 = jdbcVersionDao.deleteCachedRepresentationForSource(3, 4); //source 1 --> version 4 --> cached 4 212 assertEquals(1, result_2[0]); 213 assertEquals(1, result_2[1]); 144 public void testRetrieveCachedRepresentationList() { 145 146 System.out.println("retrieveCachedRepresentationList"); 147 Number versionID = 1; 148 149 List expResult = new ArrayList<Number>(); 150 expResult.add(1); 151 expResult.add(5); 152 153 List result = jdbcVersionDao.retrieveCachedRepresentationList(versionID); 154 assertEquals(expResult, result); 214 155 } 215 156 }
Note: See TracChangeset
for help on using the changeset viewer.