From d32131cfa7f73ad17b938306271f3beeaf0a3239 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 5 Dec 2017 12:31:07 -0200 Subject: [PATCH] =?UTF-8?q?Navitia:=20New=20Brazil=20provider,=20covering?= =?UTF-8?q?=20S=C3=A3o=20Paulo,=20Rio=20de=20Janeiro,=20Belo=20Horizonte?= =?UTF-8?q?=20and=20Porto=20Allegre.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/de/schildbach/pte/BrazilProvider.java | 67 +++++++++++++++ src/de/schildbach/pte/NetworkId.java | 3 + .../pte/live/BrazilProviderLiveTest.java | 86 +++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 src/de/schildbach/pte/BrazilProvider.java create mode 100644 test/de/schildbach/pte/live/BrazilProviderLiveTest.java diff --git a/src/de/schildbach/pte/BrazilProvider.java b/src/de/schildbach/pte/BrazilProvider.java new file mode 100644 index 00000000..af249fdc --- /dev/null +++ b/src/de/schildbach/pte/BrazilProvider.java @@ -0,0 +1,67 @@ +/* + * Copyright 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 . + */ + +package de.schildbach.pte; + +import de.schildbach.pte.dto.Product; +import de.schildbach.pte.dto.Style; +import de.schildbach.pte.dto.Style.Shape; + +/** + * @author Torsten Grote + */ +public class BrazilProvider extends AbstractNavitiaProvider { + private static final String API_REGION = "br"; + + public BrazilProvider(final String authorization) { + super(NetworkId.BRAZIL, authorization); + setTimeZone("America/Sao_Paulo"); + } + + @Override + public String region() { + return API_REGION; + } + + @Override + protected Style getLineStyle(final String network, final Product product, final String code, final String color) { + final Style defaultStyle = Standard.STYLES.get(product); + int bc = defaultStyle.backgroundColor; + int fc = defaultStyle.foregroundColor; + if (color != null) { + bc = Style.parseColor(color); + fc = computeForegroundColor(color); + } + + switch (product) { + case SUBURBAN_TRAIN: { + return new Style(Shape.CIRCLE, bc, fc); + } + case SUBWAY: { + return new Style(Shape.CIRCLE, bc, fc); + } + case TRAM: { + return new Style(Shape.RECT, bc, fc); + } + case BUS: { + return new Style(Shape.RECT, bc, fc); + } + default: + return new Style(bc, fc); + } + } +} diff --git a/src/de/schildbach/pte/NetworkId.java b/src/de/schildbach/pte/NetworkId.java index 2dbedd35..866c40a8 100644 --- a/src/de/schildbach/pte/NetworkId.java +++ b/src/de/schildbach/pte/NetworkId.java @@ -92,4 +92,7 @@ public enum NetworkId { // Nicaragua NICARAGUA, + + // Brazil + BRAZIL, } diff --git a/test/de/schildbach/pte/live/BrazilProviderLiveTest.java b/test/de/schildbach/pte/live/BrazilProviderLiveTest.java new file mode 100644 index 00000000..1bf6b258 --- /dev/null +++ b/test/de/schildbach/pte/live/BrazilProviderLiveTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 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 . + */ + +package de.schildbach.pte.live; + +import de.schildbach.pte.BrazilProvider; +import de.schildbach.pte.dto.Point; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * @author Torsten Grote + */ +public class BrazilProviderLiveTest extends AbstractNavitiaProviderLiveTest { + public BrazilProviderLiveTest() { + super(new BrazilProvider(secretProperty("navitia.authorization"))); + } + + @Test + public void nearbyStationsAddress() throws Exception { + // Sao Paulo + nearbyStationsAddress(-23547900, -46635200); + } + + @Test + public void nearbyStationsAddress2() throws Exception { + // Rio de Janeiro + nearbyStationsAddress(-22905300, -43179500); + } + + @Test + public void nearbyStationsStation() throws Exception { + nearbyStationsStation("stop_point:OIO:SP:18255914"); + } + + @Test + public void nearbyStationsInvalidStation() throws Exception { + nearbyStationsInvalidStation("stop_point:OIO:SPX:18255914"); + } + + @Test + public void queryDeparturesEquivsFalse() throws Exception { + queryDeparturesEquivsFalse("stop_point:OSA:SP:800016608"); + } + + @Test + public void queryDeparturesInvalidStation() throws Exception { + queryDeparturesInvalidStation("stop_point:OWX:SP:6911"); + } + + @Test + public void suggestLocations() throws Exception { + suggestLocationsFromName("Republica"); + } + + @Test + public void queryTripStations() throws Exception { + queryTrip("Benjamim Constant", "Avenida Paulista"); + } + + @Test + public void queryMoreTrips() throws Exception { + queryMoreTrips("Republica", "Avenida Paulista"); + } + + @Test + public void getArea() throws Exception { + final Point[] polygon = provider.getArea(); + assertTrue(polygon.length > 0); + } +}