Skip to content
Snippets Groups Projects
Commit 8cea2934 authored by Clayton, Brandon Scott's avatar Clayton, Brandon Scott
Browse files

Merge branch 'faults' into 'master'

Remove dependency nshm-fault-sections

Closes #56

See merge request !101
parents 8b888ecf 8a6a8da0
No related branches found
No related tags found
1 merge request!101Remove dependency nshm-fault-sections
Pipeline #14114 passed
...@@ -71,9 +71,6 @@ test { ...@@ -71,9 +71,6 @@ test {
includeTestsMatching "gov.usgs.earthquake.nshmp.internal.*" includeTestsMatching "gov.usgs.earthquake.nshmp.internal.*"
includeTestsMatching "gov.usgs.earthquake.nshmp.mfd.*" includeTestsMatching "gov.usgs.earthquake.nshmp.mfd.*"
includeTestsMatching "gov.usgs.earthquake.nshmp.tree.*" includeTestsMatching "gov.usgs.earthquake.nshmp.tree.*"
// TODO: Remove when updated
excludeTestsMatching "gov.usgs.earthquake.nshmp.internal.NshmFaultSectionTests"
} }
} }
......
/* rootProject.name = 'nshmp-lib'
plugins {
id "com.alexvasilkov.git-dependencies" version "2.0.1"
}
rootProject.name = 'nshmp-lib'
git {
fetch ("git@code.usgs.gov:ghsc/nshmp/nshm-fault-sections.git", {
tag "v0.1"
})
}
*/
...@@ -6,19 +6,14 @@ import static org.junit.jupiter.api.Assertions.assertThrows; ...@@ -6,19 +6,14 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.nio.file.FileVisitResult; import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource; import com.google.common.io.Resources;
import gov.usgs.earthquake.nshmp.geo.Location; import gov.usgs.earthquake.nshmp.geo.Location;
import gov.usgs.earthquake.nshmp.geo.LocationList; import gov.usgs.earthquake.nshmp.geo.LocationList;
...@@ -42,9 +37,7 @@ public class NshmFaultSectionTests { ...@@ -42,9 +37,7 @@ public class NshmFaultSectionTests {
private static List<LocationList> TRACES = new ArrayList<>(); private static List<LocationList> TRACES = new ArrayList<>();
private static final double UPPER_DEPTH = 0.0; private static final double UPPER_DEPTH = 0.0;
private static String GEOJSON_SUFFIX = ".geojson"; private static final String TEST_FILE = "internal/fault-section.geojson";
private static String ZONE = "zone.geojson";
private static NshmFaultSection FAULT_SECTION; private static NshmFaultSection FAULT_SECTION;
static { static {
...@@ -69,26 +62,21 @@ public class NshmFaultSectionTests { ...@@ -69,26 +62,21 @@ public class NshmFaultSectionTests {
.toFaultSection(); .toFaultSection();
} }
@ParameterizedTest(name = "{index} ==> Path: {0}") @Test
@MethodSource("faultSections") public final void geoJsonUrlTests() throws IOException {
public final void fromGeoJsonTests(Path path) throws IOException { var url = Resources.getResource(TEST_FILE);
Feature feature = GeoJson.from(url).toFeature();
NshmFaultSection actual = NshmFaultSection.fromGeoJson(url);
geoJsonTests(feature, actual);
}
@Test
public final void geoJsonPathTests() throws IOException, URISyntaxException {
var url = Resources.getResource(TEST_FILE);
var path = Paths.get(url.toURI());
Feature feature = GeoJson.from(path).toFeature(); Feature feature = GeoJson.from(path).toFeature();
Properties properties = feature.properties();
NshmFaultSection actual = NshmFaultSection.fromGeoJson(path); NshmFaultSection actual = NshmFaultSection.fromGeoJson(path);
Feature actualFeature = actual.toFeature(); geoJsonTests(feature, actual);
checkFeature(feature, actualFeature);
for (PropertyKey key : PropertyKey.values()) {
if (properties.containsKey(key.toString())) {
checkField(key, properties, actual);
}
}
if (properties.map().containsKey(ALT_ID_NAME) && actual.altId().isPresent()) {
assertEquals(ALT_ID_NAME, actual.altIdName().get());
assertEquals(properties.get(ALT_ID_NAME), actual.altId().get());
}
} }
@Test @Test
...@@ -478,29 +466,21 @@ public class NshmFaultSectionTests { ...@@ -478,29 +466,21 @@ public class NshmFaultSectionTests {
} }
} }
private static Stream<Path> faultSections() throws IOException { public void geoJsonTests(Feature feature, NshmFaultSection actual) throws IOException {
Path path = Paths.get("libs/nshm-fault-sections"); Properties properties = feature.properties();
FaultFinder finder = new FaultFinder(); Feature actualFeature = actual.toFeature();
Files.walkFileTree(path, finder);
return finder.paths.stream();
}
private static class FaultFinder extends SimpleFileVisitor<Path> {
List<Path> paths;
FaultFinder() {
paths = new ArrayList<>();
}
@Override checkFeature(feature, actualFeature);
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
Path fileName = path.getFileName();
if (path.toString().contains(GEOJSON_SUFFIX) && !fileName.toString().contentEquals(ZONE)) { for (PropertyKey key : PropertyKey.values()) {
paths.add(path); if (properties.containsKey(key.toString())) {
checkField(key, properties, actual);
} }
}
return FileVisitResult.CONTINUE; if (properties.map().containsKey(ALT_ID_NAME) && actual.altId().isPresent()) {
assertEquals(ALT_ID_NAME, actual.altIdName().get());
assertEquals(properties.get(ALT_ID_NAME), actual.altId().get());
} }
} }
......
{
"type": "Feature",
"id": 706,
"geometry": {
"type": "LineString",
"coordinates": [
[-118.89012, 34.80760],
[-119.03009, 34.82896],
[-119.21000, 34.86390],
[-119.36286, 34.91571],
[-119.40290, 34.94410]
]
},
"properties": {
"name": "San Andreas (Big Bend)",
"state": "CA",
"upperDepth": 0.0,
"lowerDepth": 15.0,
"dip": 90.0,
"rake": 180.0,
"rate": 34.0,
"rateType": "SLIP_RATE"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment