Skip to content

Commit

Permalink
Add longName to Route
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Oct 31, 2023
1 parent 09e0c16 commit ba60a8b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/opentripplanner/client/model/Route.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
package org.opentripplanner.client.model;

public record Route(String shortName, TransitMode mode) {}
import java.util.Optional;

public record Route(Optional<String> shortName, Optional<String> longName, TransitMode mode) {

/**
* Either the short name (if it has one) or the long name.
*
* <p>Either is optional but one must exist.
*/
public String name() {
return shortName.or(() -> longName).orElseThrow();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.ZoneId;

public class ObjectMappers {
public static ObjectMapper withTimezone(ZoneId timezone) {
var mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
SimpleModule module = new SimpleModule();
module.addDeserializer(OffsetDateTime.class, new OffsetDateTimeSerializer(timezone));
module.addDeserializer(Duration.class, new DurationSerializer());
mapper.registerModule(module);
return mapper;
return new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(module)
.registerModule(new Jdk8Module());
}
}
1 change: 1 addition & 0 deletions src/main/resources/queries/routes.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
query {
routes {
longName
shortName
mode
agency {
Expand Down
13 changes: 6 additions & 7 deletions src/test/java/org/opentripplanner/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void bikeRoute() throws IOException {
}

@Test
public void rentalStations() throws IOException, InterruptedException {
public void rentalStations() throws IOException {

var result = client.vehicleRentalStations();

Expand All @@ -97,12 +97,11 @@ public void rentalStations() throws IOException, InterruptedException {

@Test
public void routes() throws IOException {

var result = client.routes();

LOG.info("Received {} routes", result.size());

assertFalse(result.isEmpty());
var routes = client.routes();
LOG.info("Received {} routes", routes.size());

assertFalse(routes.isEmpty());
routes.forEach(r -> assertFalse(r.name().isEmpty(), "Route %s has no name.".formatted(r)));
}

@Test
Expand Down

0 comments on commit ba60a8b

Please sign in to comment.