Skip to content
Snippets Groups Projects

Remove dependency nshm-fault-sections

Merged Clayton, Brandon Scott requested to merge (removed):faults into master
4 files
+ 53
62
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -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());
}
}
}
}
Loading