Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.opentripplanner.ext.vectortiles.layers.vehiclerental.mapper;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.opentripplanner.street.model.RentalFormFactor.BICYCLE;

import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.service.vehiclerental.model.RentalVehicleFuel;
import org.opentripplanner.service.vehiclerental.model.RentalVehicleTypeFactory;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalVehicle;
import org.opentripplanner.transit.model.basic.Ratio;
import org.opentripplanner.transit.model.framework.FeedScopedId;

class DigitransitRentalVehiclePropertyMapperTest {

private static final String NAME = "a rental";

@Test
void noFuel() {
var mapper = new DigitransitRentalVehiclePropertyMapper();
var vehicle = builder().build();

Map<String, Object> map = new HashMap<>();
mapper.map(vehicle).forEach(o -> map.put(o.key(), o.value()));

assertEquals("A:B", map.get("id"));
assertEquals("BICYCLE", map.get("formFactor"));
assertEquals("HUMAN", map.get("propulsionType"));
assertNull(map.get("fuelPercentage"));
assertEquals("A", map.get("network"));
assertEquals(true, map.get("pickupAllowed"));
assertNull(map.get("name"));
}

@Test
void fuelPercentage() {
var mapper = new DigitransitRentalVehiclePropertyMapper();
var vehicle = builder()
.withFuel(RentalVehicleFuel.of().withPercent(Ratio.of(0.3)).build())
.build();

Map<String, Object> map = new HashMap<>();
mapper.map(vehicle).forEach(o -> map.put(o.key(), o.value()));

assertEquals(0.3, map.get("fuelPercentage"));
}

private static VehicleRentalVehicle.Builder builder() {
return VehicleRentalVehicle.of()
.withId(new FeedScopedId("A", "B"))
.withLatitude(1)
.withLongitude(2)
.withName(I18NString.of(NAME))
.withVehicleType(RentalVehicleTypeFactory.vehicleType(BICYCLE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.opentripplanner.service.vehiclerental.model.RentalVehicleTypeFactory.vehicleType;
import static org.opentripplanner.street.model.RentalFormFactor.BICYCLE;
import static org.opentripplanner.street.model.RentalFormFactor.SCOOTER;

Expand All @@ -14,37 +15,15 @@
import org.opentripplanner.framework.i18n.TranslatedString;
import org.opentripplanner.service.vehiclerental.model.RentalVehicleType;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalStation;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalVehicle;
import org.opentripplanner.street.model.RentalFormFactor;
import org.opentripplanner.transit.model.framework.FeedScopedId;

public class VehicleRentalLayerTest {
class DigitransitVehicleRentalStationPropertyMapperTest {

public static final String NAME = "a rental";
private static final String NAME = "a rental";

@Test
public void floatingVehicle() {
var mapper = new DigitransitRentalVehiclePropertyMapper();
var vehicle = VehicleRentalVehicle.of()
.withId(new FeedScopedId("A", "B"))
.withLatitude(1)
.withLongitude(2)
.withName(new NonLocalizedString(NAME))
.withVehicleType(vehicleType(BICYCLE))
.build();

Map<String, Object> map = new HashMap<>();
mapper.map(vehicle).forEach(o -> map.put(o.key(), o.value()));

assertEquals("A:B", map.get("id"));
assertEquals("BICYCLE", map.get("formFactor"));
assertEquals("A", map.get("network"));
assertEquals(true, map.get("pickupAllowed"));
assertNull(map.get("name"));
}

@Test
public void station() {
void station() {
var mapper = new DigitransitVehicleRentalStationPropertyMapper(new Locale("en-US"));
var station = VehicleRentalStation.of()
.withId(new FeedScopedId("A", "B"))
Expand All @@ -64,7 +43,7 @@ public void station() {
}

@Test
public void stationWithTranslations() {
void stationWithTranslations() {
var mapper = new DigitransitVehicleRentalStationPropertyMapper(new Locale("de"));
var germanName = "nameDE";
var station = VehicleRentalStation.of()
Expand Down Expand Up @@ -92,7 +71,7 @@ public void stationWithTranslations() {
}

@Test
public void realtimeStation() {
void realtimeStation() {
var mapper = new DigitransitRealtimeVehicleRentalStationPropertyMapper(new Locale("en-US"));
var station = VehicleRentalStation.of()
.withId(new FeedScopedId("A", "B"))
Expand All @@ -117,14 +96,4 @@ public void realtimeStation() {
assertEquals(8, map.get("vehiclesAvailable"));
assertEquals(3, map.get("spacesAvailable"));
}

private static RentalVehicleType vehicleType(RentalFormFactor formFactor) {
return RentalVehicleType.of()
.withId(new FeedScopedId("1", formFactor.name()))
.withName(I18NString.of("bicycle"))
.withFormFactor(formFactor)
.withPropulsionType(RentalVehicleType.PropulsionType.HUMAN)
.withMaxRangeMeters(1000d)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opentripplanner.ext.vectortiles.layers.vehiclerental.mapper;

import static org.opentripplanner.ext.vectortiles.layers.vehiclerental.mapper.DigitransitVehicleRentalStationPropertyMapper.getFeedScopedIdAndNetwork;
import static org.opentripplanner.inspector.vector.KeyValue.kv;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -11,11 +12,15 @@
public class DigitransitRentalVehiclePropertyMapper extends PropertyMapper<VehicleRentalVehicle> {

@Override
protected Collection<KeyValue> map(VehicleRentalVehicle place) {
protected Collection<KeyValue> map(VehicleRentalVehicle vehicle) {
var items = new ArrayList<KeyValue>();
items.addAll(getFeedScopedIdAndNetwork(place));
items.add(new KeyValue("formFactor", place.vehicleType().formFactor().toString()));
items.add(new KeyValue("pickupAllowed", place.isAllowPickup()));
items.addAll(getFeedScopedIdAndNetwork(vehicle));
items.add(kv("formFactor", vehicle.vehicleType().formFactor()));
items.add(kv("propulsionType", vehicle.vehicleType().propulsionType()));
if (vehicle.fuel() != null && vehicle.fuel().percent() != null) {
items.add(kv("fuelPercentage", vehicle.fuel().percent().asDouble()));
}
items.add(kv("pickupAllowed", vehicle.isAllowPickup()));
return items;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static GraphQLObjectType create(
.name("currentRangeMeters")
.type(Scalars.GraphQLFloat)
.dataFetcher(environment ->
((VehicleRentalVehicle) environment.getSource()).getFuel().range()
((VehicleRentalVehicle) environment.getSource()).fuel().range()
)
.build()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ public VehicleRentalSystem vehicleRentalSystem() {
return system;
}

public RentalVehicleFuel getFuel() {
return fuel;
}

public OffsetDateTime availableUntil() {
return availableUntil;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.opentripplanner.service.vehiclerental.model;

import org.opentripplanner.framework.i18n.I18NString;
import org.opentripplanner.street.model.RentalFormFactor;
import org.opentripplanner.transit.model.framework.FeedScopedId;

public class RentalVehicleTypeFactory {

public static RentalVehicleType vehicleType(RentalFormFactor formFactor) {
return RentalVehicleType.of()
.withId(new FeedScopedId("1", formFactor.name()))
.withName(I18NString.of("bicycle"))
.withFormFactor(formFactor)
.withPropulsionType(RentalVehicleType.PropulsionType.HUMAN)
.withMaxRangeMeters(1000d)
.build();
}
}
Loading