if ( ODMG.getODMGImplementation().currentTransaction() != null ) {
fail( "Still in transaction" );
}
assertNotNull( "photos1 = null", photos1 );
assertEquals( "Only 1 photo per picture should be found", 1, photos1.length );
PhotoInfo p1 = photos1[0];
assertEquals( "2 instances should be found in photo 1", 2, p1.getNumInstances() );
PhotoInfo[] photos2 = PhotoInfo.retrieveByOrigHash( hash2 );
if ( ODMG.getODMGImplementation().currentTransaction() != null ) {
fail( "Still in transaction" );
}
assertEquals( "1 photo per picture should be found", 1, photos2.length );
PhotoInfo p2 = photos2[0];
assertEquals( "3 instances should be found in photo 2", 3, p2.getNumInstances() );
// Check that both instances of p2 can be found
boolean found[] = {false, false};
File files[] = {photo2inst1, photo2inst2};
for ( n = 0; n < p2.getNumInstances(); n++ ) {
ImageInstance i = p2.getInstance( n );
for ( int m = 0; m < found.length; m++ ) {
if ( files[m].equals( i.getImageFile() ) ) {
found[m] = true;
}
}
}
for ( n = 0; n < found.length; n++ ) {
assertTrue( "Photo " + n + " not found", found[n] );
}
if ( ODMG.getODMGImplementation().currentTransaction() != null ) {
fail( "Still in transaction" );
}
// Check that the folders have the correct photos
PhotoInfo[] photosInTopFolder = { p1, p2 };
assertFolderHasPhotos( topFolder, photosInTopFolder );
PhotoFolder subFolder = topFolder.getSubfolder( 0 );
assertEquals( "Subfolder name not correct", "test", subFolder.getName() );
PhotoInfo[] photosInSubFolder = { p2 };
assertFolderHasPhotos( subFolder, photosInSubFolder );
// Check that the listener was called correctly
assertEquals( "Wrong photo count in listener", 2, l.photoCount );
assertEquals( "Wrong photo count in indexer statistics", 2, indexer.getNewPhotoCount() );
assertEquals( "Wrong instance count in listener", 3, l.instanceCount );
assertEquals( "Wrong instance count in indexer statistics", 3, indexer.getNewInstanceCount() );
assertEquals( "Indexing complete 100%", 100, indexer.getPercentComplete() );
assertNotNull( "StartTime still null", indexer.getStartTime() );
if ( ODMG.getODMGImplementation().currentTransaction() != null ) {
fail( "Still in transaction" );
}
// Next, let's make some modifications to the external volume
try {
// New file
File testfile3 = new File( "testfiles", "test3.jpg" );
File f3 = new File( extVolDir, "test3.jpg");
FileUtils.copyFile( testfile3, f3 );
// Replace the test1 file with test3
File f1 = new File ( extVolDir, "test1.jpg" );
FileUtils.copyFile( testfile3, f1 );
// Remove 1 copy of test2
File f2 = new File( extVolDir, "test2.jpg" );
f2.delete();
} catch (IOException ex) {
fail( "IOException while altering external volume: " + ex.getMessage() );
}
indexer = new ExtVolIndexer( v );
indexer.setTopFolder( topFolder );
l = new TestListener();
indexer.addIndexerListener( l );
assertEquals( "Indexing not started -> completeness must be 0",
0, indexer.getPercentComplete() );
assertNull( "StartTime must be null before starting", indexer.getStartTime() );
indexer.run();
// Check that the folders have the correct photos
PhotoInfo[] photos3 = PhotoInfo.retrieveByOrigHash( hash3 );
assertEquals( "1 photo per picture should be found", 1, photos3.length );
PhotoInfo p3 = photos3[0];
PhotoInfo photosInTopFolder2[] = { p3 };
assertFolderHasPhotos( topFolder, photosInTopFolder2 );
assertEquals( "More than 1 subfolder in topFolder", 1, topFolder.getSubfolderCount() );
subFolder = topFolder.getSubfolder( 0 );
assertEquals( "Subfolder name not correct", "test", subFolder.getName() );
PhotoInfo[] photosInSubFolder2 = { p2 };