mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 06:08:52 +00:00

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@143 0924bc21-9374-b0fa-ee44-9ff1593b38f0
114 lines
3.8 KiB
Java
114 lines
3.8 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()
|
|
{
|
|
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");
|
|
}
|
|
|
|
@Test
|
|
public void departureWithOnTime()
|
|
{
|
|
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");
|
|
}
|
|
|
|
@Test
|
|
public void departureWithMessage()
|
|
{
|
|
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");
|
|
}
|
|
|
|
@Test
|
|
public void departureWithWeirdMessage()
|
|
{
|
|
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");
|
|
}
|
|
|
|
private void assertFineConnectionDetails(String s)
|
|
{
|
|
Matcher m = BahnProvider.P_CONNECTION_DETAILS_FINE.matcher(s);
|
|
assertTrue(m.matches());
|
|
|
|
// ParserUtils.printGroups(m);
|
|
}
|
|
|
|
private void 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
|
|
assertNotNull(m.group(7)); // departure
|
|
}
|
|
}
|