use of org.geotoolkit.storage.StorageCountListener in project geotoolkit by Geomatys.
the class AggregatedCoverageResourceTest method testModifyAggregation.
/**
* Test aggregating coverages one at the time.
*/
@Test
public void testModifyAggregation() throws DataStoreException, TransformException {
// event counters
StorageCountListener listener = new StorageCountListener();
final CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
final GeneralEnvelope expected = new GeneralEnvelope(crs);
final SampleDimension sd = new SampleDimension.Builder().setName("data").build();
final List<SampleDimension> bands = Arrays.asList(sd);
final GridGeometry grid1 = new GridGeometry(new GridExtent(3, 1), CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 0.5, 0.5), crs);
final GridGeometry grid2 = new GridGeometry(new GridExtent(3, 1), CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 1.5, 0.5), crs);
final GridGeometry grid3 = new GridGeometry(new GridExtent(3, 1), CELL_CENTER, new AffineTransform2D(1, 0, 0, 1, 2.5, 0.5), crs);
final GridCoverage coverage1 = new BufferedGridCoverage(grid1, bands, DataBuffer.TYPE_DOUBLE);
final GridCoverage coverage2 = new BufferedGridCoverage(grid2, bands, DataBuffer.TYPE_DOUBLE);
final GridCoverage coverage3 = new BufferedGridCoverage(grid3, bands, DataBuffer.TYPE_DOUBLE);
final GridCoverageResource resource1 = new InMemoryGridCoverageResource(coverage1);
final GridCoverageResource resource2 = new InMemoryGridCoverageResource(coverage2);
final GridCoverageResource resource3 = new InMemoryGridCoverageResource(coverage3);
final AggregatedCoverageResource agg = new AggregatedCoverageResource();
agg.addListener(StoreEvent.class, listener);
Assert.assertNull(agg.getEnvelope().orElse(null));
agg.add(resource1);
assertEquals(1, listener.count(ContentEvent.class));
assertEquals(1, listener.count(ModelEvent.class));
assertEquals(1, listener.count(AggregationEvent.class));
Envelope envelope = agg.getEnvelope().orElse(null);
expected.setRange(0, 0, 3);
expected.setRange(1, 0, 1);
assertEquals(expected, new GeneralEnvelope(envelope));
agg.add(resource2);
assertEquals(2, listener.count(ContentEvent.class));
assertEquals(2, listener.count(ModelEvent.class));
assertEquals(2, listener.count(AggregationEvent.class));
envelope = agg.getEnvelope().orElse(null);
expected.setRange(0, 0, 4);
expected.setRange(1, 0, 1);
assertEquals(expected, new GeneralEnvelope(envelope));
agg.add(resource3);
assertEquals(3, listener.count(ContentEvent.class));
assertEquals(3, listener.count(ModelEvent.class));
assertEquals(3, listener.count(AggregationEvent.class));
envelope = agg.getEnvelope().orElse(null);
expected.setRange(0, 0, 5);
expected.setRange(1, 0, 1);
assertEquals(expected, new GeneralEnvelope(envelope));
agg.remove(resource1);
agg.remove(resource2);
assertEquals(5, listener.count(ContentEvent.class));
assertEquals(5, listener.count(ModelEvent.class));
assertEquals(5, listener.count(AggregationEvent.class));
envelope = agg.getEnvelope().orElse(null);
expected.setRange(0, 2, 5);
expected.setRange(1, 0, 1);
assertEquals(expected, new GeneralEnvelope(envelope));
}
Aggregations