test: busstop
1 parent 16c2ae7 commit 47b2bca85417e3a0627420af44c9020f94c501f3
@yuu yuu authored on 23 Nov 2018
Showing 6 changed files
View
2
■■■
test/data/pbfDate.json 0 → 100755
{"date": "2016-12-25"}
View
2
■■■
test/osm/jp/coverage/DbTest.java
}
}
}
catch (SQLException e) {
e.printStackTrace();
fail(e.toString());
}
}
View
14
test/osm/jp/coverage/PostgresqlTest.java
package osm.jp.coverage;
 
import java.io.File;
import java.sql.Connection;
import jp.co.areaweb.tools.database.DatabaseTool;
import static org.hamcrest.CoreMatchers.is;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
}
/**
* postgresql `postgis.properties`
* postgresql - PostGIS : gisdb
*/
@Test
public void connectTest_postgis() {
connect("postgis");
}
 
/**
* postgresql `database.properties`
* HSQLDB.database
*/
@Test
public void connectTest_database() {
connect("database");
}
 
/**
* postgresql `osmdb.properties`
* postgresql - PostGIS : postgis
* ```
* docker run --name=postgis -d
* -e POSTGRES_USER=alex
* -e POSTGRES_PASS=password
View
12
test/osm/jp/coverage/busstop/BusstopTest.java
String name = rset1.getString("name");
if ((name != null) && !name.trim().isEmpty()) {
score = 50;
}
String gmlid = null;
int area = 0;
int fixed1 = 0;
String gmlid;
int area;
int fixed1;
 
// 指定の緯度経度を中心とする半径200x2m四方の矩形領域
assertTrue(lat > 20.0D);
assertTrue(lat < 50.0D);
*
* @throws Exception
*/
@Test
public void t40_main_output() throws Exception {
public void test40_main_output() throws Exception {
int cnt = 0;
String databaseName = "database";
String tableName = "busstop";
 
fail(e.toString());
}
 
try {
String[] args = new String[]{"-OUTPUT", "GML_BUSSTOP/P11-10.removed.json.txt"};
String[] args = new String[]{"-OUTPUT", "P11-10.removed.json.txt"};
DbBusstop.main(args);
}
catch(Exception e) {
fail(e.toString());
}
 
File file = new File("GML_BUSSTOP", "P11-10.removed.json.txt");
File file = new File("P11-10.removed.json.txt");
assertThat(file.exists(), is(true));
try (Connection hsqldb = DatabaseTool.openDb(databaseName)) {
int cnt1 = DbTest.getRecordCount(hsqldb, tableName, "REMOVED=TRUE");
View
123
test/osm/jp/coverage/busstop/CoverageTest.java
package osm.jp.coverage.busstop;
 
import hayashi.tools.files.DeleteDir;
import hayashi.yuu.tools.json.JsonTool;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.sql.SQLException;
import javax.json.JsonArray;
import javax.json.JsonNumber;
import javax.json.JsonObject;
import javax.json.JsonValue;
import javax.json.JsonValue.ValueType;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import jp.co.areaweb.tools.csv.CsvFile;
import jp.co.areaweb.tools.csv.CsvRecord;
import static org.hamcrest.CoreMatchers.is;
import org.junit.AfterClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.xml.sax.SAXException;
import tools.Compless;
import tools.Copy;
 
public class CoverageTest {
@BeforeClass
public static void setUpClass() throws Exception {
String gmlFolderName = "GML_BUSSTOP";
File gmlDir = new File(gmlFolderName);
if (!gmlDir.exists()) {
File tgzFile = new File("data", "GML_BUSSTOP.tar.gz");
Compless.uncomplessTarGz(new File("."), tgzFile);
}
Copy.copyFile(new File("data", "pbfDate.json"), new File(gmlDir, "pbfDate.json"));
}
 
@AfterClass
public static void tearDownClass() throws Exception {
DeleteDir.delete(new File("GML_BUSSTOP"));
}
@Test
@SuppressWarnings("UseSpecificCatch")
public void testBusstopCoverage_main() {
System.out.println("testBusstopCoverage_main");
try {
String[] args = new String[]{"outputfile.csv"};
String[] args = new String[]{};
Coverage.main(args);
}
catch (IOException | ClassNotFoundException | SQLException | ParserConfigurationException | TransformerException | SAXException e) {
e.printStackTrace();
fail();
fail(e.toString());
}
File outDir = new File("GML_BUSSTOP");
File out1 = new File(outDir, "coverage.busstop.csv");
assertNotNull(out1);
assertTrue(out1.exists());
assertTrue(out1.isFile());
try {
CsvFile csv = new CsvFile(out1);
csv.setCharsetName("utf-8");
csv.load();
assertThat(csv.size(), is(49));
int num = -1;
for (CsvRecord line : csv) {
if (num == -1) {
assertThat(line.get(0), is("コード"));
assertThat(line.get(1), is("都道府県"));
assertThat(line.get(2), is("母数"));
assertThat(line.get(3), is("入力数"));
assertThat(line.get(4), is("率(%)"));
}
else {
assertThat(line.get(0), is(String.valueOf(num)));
String vStr = line.get(4);
double v = Double.valueOf(vStr);
assertTrue(v > 0.0D);
assertTrue(v <= 100.0D);
}
num++;
}
}
catch (Exception e) {
fail(e.toString());
}
File out2 = new File(outDir, "coverage.busstop.json");
assertNotNull(out2);
assertTrue(out2.exists());
assertTrue(out2.isFile());
try {
LineNumberReader reader = new LineNumberReader(
new InputStreamReader(new FileInputStream(out2), "utf-8")
);
String content = "";
String str;
while ((str = reader.readLine()) != null) {
content += str;
}
JsonObject json = JsonTool.parse(content);
String vstr = json.getString("timestamp");
assertNotNull(vstr);
assertThat(vstr.length() > 0, is(true));
vstr = json.getString("sourcedata");
assertNotNull(vstr);
assertThat(vstr, is("国土数値情報 バス停留所データ 平成22年"));
JsonArray arry = json.getJsonArray("coverage");
assertNotNull(arry);
assertThat(arry.size(), is(48));
int i = 0;
for (JsonValue v : arry) {
assertThat(v.getValueType(), is(ValueType.OBJECT));
JsonObject obj = (JsonObject)v;
int code = obj.getInt("code");
assertThat(code, is(i));
JsonNumber par = obj.getJsonNumber("par");
assertNotNull(par);
double pard = par.doubleValue();
assertTrue(pard > 0.0D);
assertTrue(pard <= 100.0D);
i++;
}
}
catch (Exception e) {
fail(e.toString());
}
}
 
}
View
4
test/osm/jp/coverage/busstop/ToPostgisTest.java
String[] argv = new String[0];
ToPostgis.main(argv);
}
catch (Exception e) {
e.printStackTrace();
fail();
fail(e.getMessage());
}
}
 
}