-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AtlasDelta and AtlasDeltaGenerator Revamp (#195)
* Revamp AtlasDelta and AtlasDeltaGenerator. We now get GeoJSON deltas that include before and after entities. Also, the generator CLI is not working. * ./gradlew spotlessApply * rename base and alter to before and after * AtlasDelta integration testing. Also, fixed a typo bug! * spotless apply * explain parse geojson test * Improve log4j instructions * Account for PR comments. * fix abbrev * no more abbrev.
- Loading branch information
1 parent
4c554c1
commit 1686af6
Showing
9 changed files
with
285 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 96 additions & 0 deletions
96
.../java/org/openstreetmap/atlas/geography/atlas/delta/AtlasDeltaGeoJsonIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package org.openstreetmap.atlas.geography.atlas.delta; | ||
|
||
import org.hamcrest.CoreMatchers; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openstreetmap.atlas.geography.atlas.Atlas; | ||
import org.openstreetmap.atlas.geography.atlas.builder.text.TextAtlasBuilder; | ||
import org.openstreetmap.atlas.streaming.compression.Decompressor; | ||
import org.openstreetmap.atlas.streaming.resource.InputStreamResource; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
|
||
/** | ||
* @author hallahan | ||
*/ | ||
public class AtlasDeltaGeoJsonIntegrationTest | ||
{ | ||
private Atlas before; | ||
private Atlas after; | ||
private AtlasDelta delta; | ||
|
||
@Before | ||
public void readAtlases() | ||
{ | ||
before = new TextAtlasBuilder() | ||
.read(new InputStreamResource(() -> AtlasDeltaIntegrationTest.class | ||
.getResourceAsStream("DMA_9-168-233-base.txt.gz")) | ||
.withDecompressor(Decompressor.GZIP) | ||
.withName("DMA_9-168-233-base.txt.gz")); | ||
after = new TextAtlasBuilder() | ||
.read(new InputStreamResource(() -> AtlasDeltaIntegrationTest.class | ||
.getResourceAsStream("DMA_9-168-233-alter.txt.gz")) | ||
.withDecompressor(Decompressor.GZIP) | ||
.withName("DMA_9-168-233-alter.txt.gz")); | ||
delta = new AtlasDelta(before, after, false).generate(); | ||
} | ||
|
||
/** | ||
* This is a basic test that should start failing if you change what the delta GeoJSON looks | ||
* like. | ||
*/ | ||
@Test | ||
public void testGeoJson() | ||
{ | ||
final String geoJson = delta.toGeoJson(); | ||
Assert.assertEquals(22424431, geoJson.length()); | ||
} | ||
|
||
@Test | ||
public void testRelationsGeoJson() | ||
{ | ||
final String relationsGeoJson = delta.toRelationsGeoJson(); | ||
Assert.assertEquals(454484, relationsGeoJson.length()); | ||
} | ||
|
||
/** | ||
* Tries parsing the GeoJSON string. We then check a few things about it, such as if it has the | ||
* applicable diff properties. Also, we count the number of features. | ||
*/ | ||
@Test | ||
public void parseGeoJson() | ||
{ | ||
final String geoJsonStr = delta.toGeoJson(); | ||
|
||
final JsonObject geoJson = new JsonParser().parse(geoJsonStr).getAsJsonObject(); | ||
final JsonArray features = geoJson.getAsJsonArray("features"); | ||
|
||
int idx = 0; | ||
for (; idx < features.size(); ++idx) | ||
{ | ||
final JsonObject feature = features.get(idx).getAsJsonObject(); | ||
final JsonObject properties = feature.getAsJsonObject("properties"); | ||
|
||
final JsonElement diffVal = properties.get("diff"); | ||
Assert.assertNotNull(diffVal); | ||
final JsonElement diffReasonVal = properties.get("diff:reason"); | ||
Assert.assertNotNull(diffReasonVal); | ||
final JsonElement diffTypeVal = properties.get("diff:type"); | ||
Assert.assertNotNull(diffTypeVal); | ||
|
||
// a diff property should be before or after. | ||
Assert.assertThat(diffVal.getAsString(), | ||
CoreMatchers.anyOf(CoreMatchers.is("BEFORE"), CoreMatchers.is("AFTER"))); | ||
|
||
// Make sure we have a reason and a type. | ||
Assert.assertTrue(diffReasonVal.getAsString().length() > 0); | ||
Assert.assertTrue(diffTypeVal.getAsString().length() > 0); | ||
} | ||
|
||
Assert.assertEquals(47646, idx); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.