}
// 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 };
assertFolderHasPhotos( subFolder, photosInSubFolder2 );
Collection p2folders = p2.getFolders();
assertFalse( "p2 must not be in topFolder", p2folders.contains( topFolder ) );
}