mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-16 09:29:49 +00:00

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@163 0924bc21-9374-b0fa-ee44-9ff1593b38f0
223 lines
9.1 KiB
Java
223 lines
9.1 KiB
Java
/*
|
|
* Copyright 2010 the original author or authors.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package de.schildbach.pte;
|
|
|
|
import static junit.framework.Assert.assertNotNull;
|
|
import static junit.framework.Assert.assertTrue;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import org.junit.Test;
|
|
|
|
/**
|
|
* @author Andreas Schildbach
|
|
*/
|
|
public class BahnProviderTest
|
|
{
|
|
@Test
|
|
public void connectionUebergang()
|
|
{
|
|
assertFineConnectionDetails("" //
|
|
+ "<span class=\"bold\">Berlin Hbf</span><br />\n" //
|
|
+ "Übergang\n" //
|
|
+ "<br />\n" //
|
|
+ "<span class=\"bold\">Berlin-Lichtenberg</span><br />");
|
|
}
|
|
|
|
@Test
|
|
public void departureWithPlatform()
|
|
{
|
|
final Matcher m = assertFineDepartures("" //
|
|
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/731061/244203/590672/51649/80/si=8100352&bt=dep&ti=10:42&pt=10:42&p=1111111111&date=01.09.10&max=10&rt=1&&\">\n" //
|
|
+ "<span class=\"bold\">S 1</span>\n" //
|
|
+ "</a>\n" //
|
|
+ ">>\n" //
|
|
+ "Gänserndorf\n" //
|
|
+ "<br />\n" //
|
|
+ "<span class=\"bold\">10:42</span>Gl. 1");
|
|
|
|
assertNotNull(m.group(7)); // position
|
|
}
|
|
|
|
@Test
|
|
public void departureWithOnTime()
|
|
{
|
|
final Matcher m = assertFineDepartures("" //
|
|
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/438441/245165/958/145668/80/si=8011160&bt=dep&ti=21:47&pt=21:47&p=1111101&date=05.09.10&max=10&rt=1&&\">\n" //
|
|
+ "<span class=\"bold\">RE 38148</span>\n" //
|
|
+ "</a>\n" //
|
|
+ ">>\n" //
|
|
+ "Rathenow\n" //
|
|
+ "<br />\n" //
|
|
+ "<span class=\"bold\">21:58</span> <span class=\"green bold\">pünktl.</span>, Gl. 13");
|
|
|
|
assertNotNull(m.group(4)); // onTime
|
|
assertNotNull(m.group(7)); // position
|
|
}
|
|
|
|
@Test
|
|
public void departureWithMessage()
|
|
{
|
|
final Matcher m = assertFineDepartures("" //
|
|
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/551037/330609/12448/177455/80/si=405341&bt=dep&ti=07:08&pt=07:08&p=1111111111&date=06.09.10&max=10&rt=1&&\">\n" //
|
|
+ "<span class=\"bold\">ICE 824</span>\n" //
|
|
+ "</a>\n" //
|
|
+ ">>\n" //
|
|
+ "Dortmund Hbf\n" //
|
|
+ "<br />\n" //
|
|
+ "<span class=\"bold\">07:02</span> <span class=\"red\">ca. +5</span>, <span class=\"red\">Fährt heute nur bis Düsseldorf Hbf</span>, Gl. 10");
|
|
|
|
assertNotNull(m.group(5)); // delay
|
|
assertNotNull(m.group(6)); // message
|
|
assertNotNull(m.group(7)); // position
|
|
}
|
|
|
|
@Test
|
|
public void departureUpdatedPosition()
|
|
{
|
|
final Matcher m = assertFineDepartures("" //
|
|
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/492282/296365/292060/18065/80/si=8000320&bt=dep&ti=17:08&pt=17:08&p=1111111111&date=07.09.10&max=10&rt=1&&\">\n" //
|
|
+ "<span class=\"bold\">RB 30240</span>\n" //
|
|
+ "</a>\n" //
|
|
+ ">>\n" //
|
|
+ "Holzkirchen\n" //
|
|
+ "<br />\n" //
|
|
+ "<span class=\"bold\">17:10</span> <span class=\"green bold\">pünktl.</span>, <span class=\"red\">heute Gl. 7 </span>");
|
|
|
|
assertNotNull(m.group(4)); // onTime
|
|
assertNotNull(m.group(7)); // position
|
|
}
|
|
|
|
@Test
|
|
public void departureMessageAndUpdatedPosition()
|
|
{
|
|
final Matcher m = assertFineDepartures("" //
|
|
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/220206/221797/157782/5489/80/si=727269&bt=dep&ti=19:56&pt=19:56&p=1111111111&date=06.09.10&max=10&rt=1&&\">\n" //
|
|
+ "<span class=\"bold\">CNL 450</span>\n" //
|
|
+ "</a>\n" //
|
|
+ ">>\n" //
|
|
+ "Paris Est\n" //
|
|
+ "<br />\n" //
|
|
+ "<span class=\"bold\">19:57</span> <span class=\"green bold\">pünktl.</span>, <span class=\"red\">Änderung im Zuglauf!</span>, <span class=\"red\">heute Gl. 7 </span>");
|
|
|
|
assertNotNull(m.group(4)); // onTime
|
|
assertNotNull(m.group(6)); // message
|
|
assertNotNull(m.group(7)); // position
|
|
}
|
|
|
|
@Test
|
|
public void departureWithWeirdMessage()
|
|
{
|
|
final Matcher m = assertFineDepartures("" //
|
|
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/760983/402261/557174/24926/80/si=808093&bt=dep&ti=02:41&pt=02:41&p=1111111111&date=06.09.10&max=10&rt=1&&\">\n" //
|
|
+ "<span class=\"bold\">ICE 609</span>\n" //
|
|
+ "</a>\n" //
|
|
+ ">>\n" //
|
|
+ "Basel SBB\n" //
|
|
+ "<br />\n" //
|
|
+ "<span class=\"bold\">04:52</span> k.A., Gl. 3");
|
|
|
|
assertNotNull(m.group(7)); // position
|
|
}
|
|
|
|
@Test
|
|
public void departureWithErsatzzugMessage()
|
|
{
|
|
final Matcher m = assertFineDepartures("" //
|
|
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/606621/948269/912326/253956/80/si=591375&bt=dep&ti=14:28&pt=14:28&p=1111111111&date=10.09.10&max=10&rt=1&&\">\n" //
|
|
+ "<span class=\"bold\">RB 93328</span>\n" //
|
|
+ "</a>\n" //
|
|
+ ">>\n" //
|
|
+ "München Hbf Gl.27-36\n" //
|
|
+ "<br />\n" //
|
|
+ "<span class=\"bold\">14:49</span> <span class=\"green bold\">pünktl.</span>, Gl. 1,<br/><span class=\"red\">Ersatzzug für<a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/611619/369020/735680/163967/80?ld=96159&rt=1&use_realtime_filter=1&date=10.09.10&time=14:49&station_evaId=8000220&station_type=dep&\">RB 5416</a></span>");
|
|
|
|
assertNotNull(m.group(4)); // onTime
|
|
assertNotNull(m.group(7)); // position
|
|
}
|
|
|
|
@Test
|
|
public void departureWithMessageAndErsatzzugMessage()
|
|
{
|
|
final Matcher m = assertFineDepartures("" //
|
|
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/208035/206616/13568/62563/80/si=624141&bt=dep&ti=09:34&pt=09:34&p=1111111111&date=08.09.10&max=10&rt=1&&\">\n" //
|
|
+ "<span class=\"bold\">S 1</span>\n" //
|
|
+ "</a>\n" //
|
|
+ ">>\n" //
|
|
+ "München Ost\n" //
|
|
+ "<br />\n" //
|
|
+ "<span class=\"bold\">10:27</span>, <span class=\"red\">Zug fällt aus</span>,<br/><a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/144627/793698/280606/92094/80?ld=96159&rt=1&use_realtime_filter=1&date=08.09.10&time=10:27&station_evaId=8001647&station_type=dep&\"><span class=\"red\">Ersatzzug S </a></span>");
|
|
|
|
assertNotNull(m.group(6)); // message
|
|
}
|
|
|
|
@Test
|
|
public void departureWithPositionAndMessages()
|
|
{
|
|
final Matcher m = assertFineDepartures("" //
|
|
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/32967/150423/39690/8856/80/si=676819&bt=dep&ti=00:57&pt=00:57&p=1111111111&date=09.09.10&max=10&rt=1&&\">\n" //
|
|
+ "<span class=\"bold\">RB 34075</span>\n" //
|
|
+ "</a>\n" //
|
|
+ ">>\n" //
|
|
+ "Nürnberg Hbf\n" //
|
|
+ "<br />\n" //
|
|
+ "<span class=\"bold\">00:18</span>, <span class=\"red\">Zug fällt aus</span>, Gl. 4,<br/><a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/843399/1026627/462944/49661/80?ld=96159&rt=1&use_realtime_filter=1&date=09.09.10&time=00:18&station_evaId=8001844&station_type=dep&\"><span class=\"red\">Ersatzzug RB 30535</a></span>");
|
|
|
|
assertNotNull(m.group(6)); // message
|
|
assertNotNull(m.group(7)); // position
|
|
}
|
|
|
|
@Test
|
|
public void departureWithMultipleMessages()
|
|
{
|
|
final Matcher m = assertFineDepartures(""//
|
|
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/66819/191058/790068/372764/80/si=445675&bt=dep&ti=10:44&pt=10:44&p=1111111111&date=15.09.10&max=10&rt=1&&\">\n" //
|
|
+ "<span class=\"bold\">S 11</span>\n" //
|
|
+ "</a>\n" //
|
|
+ ">>\n" //
|
|
+ "Bergisch Gladbach\n" //
|
|
+ "<br />\n" //
|
|
+ "<span class=\"bold\">10:59</span> <span class=\"green bold\">pünktl.</span>, <span class=\"red\">Änderung im Zuglauf!</span>, <span class=\"red\">Fährt heute nur bis Köln-Dellbrück</span>, Gl. 1");
|
|
|
|
assertNotNull(m.group(4)); // onTime
|
|
assertNotNull(m.group(6)); // message
|
|
assertNotNull(m.group(7)); // position
|
|
}
|
|
|
|
private void assertFineConnectionDetails(String s)
|
|
{
|
|
Matcher m = BahnProvider.P_CONNECTION_DETAILS_FINE.matcher(s);
|
|
assertTrue(m.matches());
|
|
|
|
// ParserUtils.printGroups(m);
|
|
}
|
|
|
|
private Matcher assertFineDepartures(String s)
|
|
{
|
|
Matcher m = BahnProvider.P_DEPARTURES_FINE.matcher(s);
|
|
assertTrue(m.matches());
|
|
|
|
// ParserUtils.printGroups(m);
|
|
|
|
assertNotNull(m.group(1)); // line
|
|
assertNotNull(m.group(2)); // destination
|
|
assertNotNull(m.group(3)); // time
|
|
|
|
return m;
|
|
}
|
|
}
|