package btools.routingapp;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.FileWriter;
public class CoordinateReaderTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test
public void readNogoRoute() throws Exception {
File importFolder = temporaryFolder.newFolder("brouter", "import", "tracks");
File tempFile = new File(importFolder, "nogo_test.gpx");
try (FileWriter writer = new FileWriter(tempFile)) {
writer.write("\n" +
"\n" +
" Nogo Route\n" +
" \n" +
" \n" +
"\n" +
" Nogo Oststadt\n" +
" Red\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
"\n" +
"");
}
CoordinateReader coordinateReader = CoordinateReader.obtainValidReader(temporaryFolder.getRoot().getAbsolutePath(), false);
assertThat(coordinateReader.nogopoints, hasSize(1));
// Name should return "Nogo Oststadt", "Nogo Route" or "nogo_test.gpx"
assertThat(coordinateReader.nogopoints.get(0).name, equalTo("nogo_test"));
assertThat(coordinateReader.nogopoints.get(0).radius, closeTo(810.0, 5.0));
}
@Test
public void readWaypoints() throws Exception {
File importFolder = temporaryFolder.newFolder("brouter", "import");
File tempFile = new File(importFolder, "favourites.gpx");
try (FileWriter writer = new FileWriter(tempFile)) {
// https://en.wikipedia.org/wiki/GPS_Exchange_Format#Sample_GPX_document
writer.write("\n" +
"\n" +
"3.4from\n" +
"3.4to\n" +
"3.4via1\n" +
"3.4nogo100 Test\n" +
"");
}
CoordinateReader coordinateReader = CoordinateReader.obtainValidReader(temporaryFolder.getRoot().getAbsolutePath(), false);
assertThat(coordinateReader, notNullValue());
// from, to, viaX are parsed into waypoints
assertThat(coordinateReader.waypoints, hasSize(3));
assertThat(coordinateReader.nogopoints, hasSize(1));
coordinateReader.readAllPoints();
assertThat(coordinateReader.allpoints, hasSize(4));
}
}