store.setType((imageMosaicFormat.getName()));
// Addition to the catalog
getCatalog().add(store);
builder.setStore(store);
// Input reader used for reading the mosaic folder
GridCoverage2DReader reader = null;
// Reader used for checking if the mosaic has been configured correctly
StructuredGridCoverage2DReader reader2 = null;
try {
// Selection of the reader to use for the mosaic
reader = (GridCoverage2DReader) imageMosaicFormat.getReader(DataUtilities
.fileToURL(mosaic));
// configure the coverage
configureCoverageInfo(builder, store, reader);
// check the coverage is actually there
CoverageStoreInfo storeInfo = getCatalog().getCoverageStoreByName("watertemp4");
assertNotNull(storeInfo);
CoverageInfo ci = getCatalog().getCoverageByName("mosaic");
assertNotNull(ci);
assertEquals(storeInfo, ci.getStore());
// Harvesting of the Mosaic
URL zipHarvest = getClass().getResource("test-data/harvesting.zip");
// Extract a Byte array from the zip file
InputStream is = null;
byte[] bytes;
try {
is = zipHarvest.openStream();
bytes = IOUtils.toByteArray(is);
} finally {
IOUtils.closeQuietly(is);
}
// Create the POST request
MockHttpServletRequest request = createRequest("/rest/workspaces/gs/coveragestores/watertemp4/file.imagemosaic");
request.setMethod("POST");
request.setContentType("application/zip");
request.setBodyContent(bytes);
request.setHeader("Content-type", "application/zip");
// Get The response
MockHttpServletResponse response = dispatch(request);
// Get the Mosaic Reader
reader2 = (StructuredGridCoverage2DReader) storeInfo.getGridCoverageReader(null,
GeoTools.getDefaultHints());
// Test if all the TIME DOMAINS are present
String[] metadataNames = reader2.getMetadataNames();
assertNotNull(metadataNames);
assertEquals("true", reader2.getMetadataValue("HAS_TIME_DOMAIN"));
assertEquals(
"2008-10-31T00:00:00.000Z,2008-11-01T00:00:00.000Z,2008-11-02T00:00:00.000Z",
reader2.getMetadataValue(metadataNames[0]));
// Removal of all the data associated to the mosaic
reader2.delete(true);
} finally {
// Reader disposal
if (reader != null) {
try {
reader.dispose();
} catch (Throwable t) {
// Does nothing
}
}
if (reader2 != null) {