| | 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()); |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |
---|
| | |