// the datastore.properties file is also mandatory...
File dsp =TestData.file(this,"datastore.properties");
FileUtils.copyFileToDirectory(dsp, mosaic);
// have the reader harvest it
ImageMosaicFormat format = new ImageMosaicFormat();
ImageMosaicReader reader = format.getReader(mosaic);
SimpleFeatureIterator it = null;
assertNotNull(reader);
try {
String[] names = reader.getGridCoverageNames();
assertEquals(1, names.length);
assertEquals("O3", names[0]);
// check we have the two granules we expect
GranuleSource source = reader.getGranules("O3", true);
FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Query q = new Query(Query.ALL);
q.setSortBy(new SortBy[] {ff.sort("time", SortOrder.ASCENDING)});
SimpleFeatureCollection granules = source.getGranules(q);
assertEquals(2, granules.size());
it = granules.features();
assertTrue(it.hasNext());
SimpleFeature f = it.next();
assertEquals("polyphemus_20130301_test.nc", f.getAttribute("location"));
assertEquals(0, f.getAttribute("imageindex"));
assertEquals("2013-03-01T00:00:00.000Z", ConvertersHack.convert(f.getAttribute("time"), String.class));
assertTrue(it.hasNext());
f = it.next();
assertEquals("polyphemus_20130301_test.nc", f.getAttribute("location"));
assertEquals(1, f.getAttribute("imageindex"));
assertEquals("2013-03-01T01:00:00.000Z", ConvertersHack.convert(f.getAttribute("time"), String.class));
it.close();
// close the reader and re-open it
reader.dispose();
reader = format.getReader(mosaic);
source = reader.getGranules("O3", true);
// wait a bit, we have to make sure the old indexes are recognized as old
Thread.sleep(1000);