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
2 changes: 2 additions & 0 deletions application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@
<sources>
<source>src/test/java</source>
<source>src/ext-test/java</source>
<source>src/test-fixtures/java</source>
</sources>
</configuration>
</execution>
Expand Down Expand Up @@ -505,6 +506,7 @@
<inputGlob>src/main/java/**/*.java</inputGlob>
<inputGlob>src/ext/java/**/*.java</inputGlob>
<inputGlob>src/test/java/**/*.java</inputGlob>
<inputGlob>src/test-fixtures/java/**/*.java</inputGlob>
<inputGlob>src/ext-test/java/**/*.java</inputGlob>
<inputGlob>src/**/*.json</inputGlob>
<inputGlob>src/test/resources/org/opentripplanner/apis/**/*.graphql</inputGlob>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import org.opentripplanner.ConstantsForTests;
import org.opentripplanner.datastore.api.CompositeDataSource;
import org.opentripplanner.datastore.api.DataSource;
import org.opentripplanner.datastore.api.DataSourceTestFactory;
import org.opentripplanner.datastore.api.FileType;
import org.opentripplanner.datastore.configure.DataStoreModule;
import org.opentripplanner.datastore.file.FileDataSource;
import org.opentripplanner.ext.emission.internal.csvdata.EmissionDataReader;
import org.opentripplanner.test.support.ResourceLoader;
Expand Down Expand Up @@ -33,7 +33,7 @@ default DataSource gtfsWithEmissionFile() {
}

default DataSource emissionOnRoutes() {
return DataStoreModule.dataSource(
return DataSourceTestFactory.dataSource(
"em-on-routes.txt",
FileType.EMISSION,
"""
Expand All @@ -45,7 +45,7 @@ default DataSource emissionOnRoutes() {
}

default DataSource emissionOnTripHops() {
return DataStoreModule.dataSource(
return DataSourceTestFactory.dataSource(
"em-on-trip-hops.txt",
FileType.EMISSION,
"""
Expand All @@ -70,11 +70,11 @@ default DataSource emissionMissingFile() {
}

default CompositeDataSource gtfsDirectoryDataSourceWithoutEmissions() {
return DataStoreModule.compositeSource(ConstantsForTests.SIMPLE_GTFS, FileType.GTFS);
return DataSourceTestFactory.compositeSource(ConstantsForTests.SIMPLE_GTFS, FileType.GTFS);
}

default CompositeDataSource gtfsZipDataSourceWithoutEmissions() {
return DataStoreModule.compositeSource(ConstantsForTests.CALTRAIN_GTFS, FileType.GTFS);
return DataSourceTestFactory.compositeSource(ConstantsForTests.CALTRAIN_GTFS, FileType.GTFS);
}

private ResourceLoader resource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.graph_builder.module.DirectTransferGenerator;
import org.opentripplanner.graph_builder.module.TestStreetLinkerModule;
import org.opentripplanner.gtfs.graphbuilder.GtfsBundle;
import org.opentripplanner.gtfs.graphbuilder.GtfsBundleTestFactory;
import org.opentripplanner.gtfs.graphbuilder.GtfsModule;
import org.opentripplanner.model.GenericLocation;
import org.opentripplanner.model.calendar.ServiceDateInterval;
Expand Down Expand Up @@ -191,7 +191,7 @@ private static void addGtfsToGraph(
List<File> gtfsFiles
) {
// GTFS
var gtfsBundles = gtfsFiles.stream().map(GtfsBundle::forTest).toList();
var gtfsBundles = gtfsFiles.stream().map(GtfsBundleTestFactory::forTest).toList();
GtfsModule gtfsModule = GtfsModule.forTest(
gtfsBundles,
timetableRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.opentripplanner.TestOtpModel;
import org.opentripplanner.framework.application.OTPFeature;
import org.opentripplanner.gtfs.graphbuilder.GtfsBundle;
import org.opentripplanner.gtfs.graphbuilder.GtfsBundleTestFactory;
import org.opentripplanner.gtfs.graphbuilder.GtfsModule;
import org.opentripplanner.model.calendar.ServiceDateInterval;
import org.opentripplanner.routing.graph.Graph;
Expand Down Expand Up @@ -44,7 +45,7 @@ private static TestOtpModel buildFlexGraph(File file) {
var deduplicator = new Deduplicator();
var graph = new Graph(deduplicator);
var timetableRepository = new TimetableRepository(new SiteRepository(), deduplicator);
GtfsBundle gtfsBundle = GtfsBundle.forTest(file);
GtfsBundle gtfsBundle = GtfsBundleTestFactory.forTest(file);
GtfsModule module = GtfsModule.forTest(
List.of(gtfsBundle),
timetableRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@
import dagger.Provides;
import jakarta.inject.Singleton;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
import org.opentripplanner.datastore.OtpDataStore;
import org.opentripplanner.datastore.api.CompositeDataSource;
import org.opentripplanner.datastore.api.DataSource;
import org.opentripplanner.datastore.api.FileType;
import org.opentripplanner.datastore.api.GoogleStorageDSRepository;
import org.opentripplanner.datastore.api.OtpBaseDirectory;
import org.opentripplanner.datastore.api.OtpDataStoreConfig;
import org.opentripplanner.datastore.base.ByteArrayDataSource;
import org.opentripplanner.datastore.base.DataSourceRepository;
import org.opentripplanner.datastore.base.ListCompositeDataSource;
import org.opentripplanner.datastore.file.FileDataSourceRepository;
import org.opentripplanner.datastore.https.HttpsDataSourceRepository;

Expand Down Expand Up @@ -48,36 +43,6 @@ public static CompositeDataSource compositeSource(File file, FileType type) {
return FileDataSourceRepository.compositeSource(file, type);
}

/**
* For test only.
* <p>
* Use this to get a composite data source. Pass in all child data sources.
*/
public static CompositeDataSource compositeSource(
String name,
FileType type,
DataSource... children
) {
return new ListCompositeDataSource(name, type, Arrays.asList(children));
}

/**
* For test only.
* <p>
* Use this to create a read-only data source backed by the given {@code content} string.
*/
public static DataSource dataSource(String name, FileType type, String content) {
var buf = content.getBytes(StandardCharsets.UTF_8);
return new ByteArrayDataSource(
name,
name,
type,
buf.length,
System.currentTimeMillis(),
false
).withBytes(buf);
}

/**
* Connect to data source and prepare to retrieve data.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package org.opentripplanner.gtfs.graphbuilder;

import java.io.File;
import java.io.InputStream;
import javax.annotation.Nullable;
import org.onebusaway.csv_entities.CsvInputSource;
import org.opentripplanner.datastore.api.CompositeDataSource;
import org.opentripplanner.datastore.api.FileType;
import org.opentripplanner.datastore.configure.DataStoreModule;
import org.opentripplanner.gtfs.config.GtfsDefaultParameters;
import org.opentripplanner.gtfs.config.GtfsFeedParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -34,21 +30,6 @@ public GtfsBundle(CompositeDataSource dataSource, GtfsFeedParameters parameters)
this.feedId = parameters.feedId();
}

/** Used by unit tests */
public static GtfsBundle forTest(File gtfsFile, @Nullable String feedId) {
var dataSource = DataStoreModule.compositeSource(gtfsFile, FileType.GTFS);
var parameters = GtfsDefaultParameters.DEFAULT.withFeedInfo()
.withSource(dataSource.uri())
.withFeedId(feedId)
.build();
return new GtfsBundle(dataSource, parameters);
}

/** Used by unit tests */
public static GtfsBundle forTest(File gtfsFile) {
return forTest(gtfsFile, null);
}

/**
* So that we can load multiple gtfs feeds into the same database.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.opentripplanner.datastore.api;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.opentripplanner.datastore.OtpDataStore;
import org.opentripplanner.datastore.base.ByteArrayDataSource;
import org.opentripplanner.datastore.file.FileDataSourceRepository;

public class DataSourceTestFactory {

/**
* Use this to get a composite data source, bypassing the {@link OtpDataStore}.
*/
public static CompositeDataSource compositeSource(File file, FileType type) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to deprecate this to simplify tests, the next method is much easier to use.

return FileDataSourceRepository.compositeSource(file, type);
}

/**
* Use this to create a read-only data source backed by the given {@code content} string.
*/
public static DataSource dataSource(String name, FileType type, String content) {
var buf = content.getBytes(StandardCharsets.UTF_8);
return new ByteArrayDataSource(
name,
name,
type,
buf.length,
System.currentTimeMillis(),
false
).withBytes(buf);
}

/**
* For test only.
* <p>
* Use this to get a composite data source. Pass in all child data sources.
*/
public static CompositeDataSource compositeSource(
String name,
FileType type,
DataSource... children
) {
return new ListCompositeDataSource(name, type, Arrays.asList(children));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ListCompositeDataSource can also be moved here because it is not used in production - and I do not see that it would be relevant for production. If so, we could move it back. Not needed for me to approve PR.

}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package org.opentripplanner.datastore.base;
package org.opentripplanner.datastore.api;

import java.net.URI;
import java.util.Collection;
import java.util.List;
import org.opentripplanner.datastore.api.CompositeDataSource;
import org.opentripplanner.datastore.api.DataSource;
import org.opentripplanner.datastore.api.FileType;

/**
* This is a simple {@link CompositeDataSource} using a list of children. It is usefull
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.opentripplanner.gtfs.graphbuilder;

import java.io.File;
import javax.annotation.Nullable;
import org.opentripplanner.datastore.api.DataSourceTestFactory;
import org.opentripplanner.datastore.api.FileType;
import org.opentripplanner.gtfs.config.GtfsDefaultParameters;

public class GtfsBundleTestFactory {

public static GtfsBundle forTest(File gtfsFile, @Nullable String feedId) {
var dataSource = DataSourceTestFactory.compositeSource(gtfsFile, FileType.GTFS);
var parameters = GtfsDefaultParameters.DEFAULT.withFeedInfo()
.withSource(dataSource.uri())
.withFeedId(feedId)
.build();
return new GtfsBundle(dataSource, parameters);
}

public static GtfsBundle forTest(File gtfsFile) {
return forTest(gtfsFile, null);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package org.opentripplanner.graph_builder.module.linking;
package org.opentripplanner.routing.linking;

import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.linking.VertexLinker;
import org.opentripplanner.routing.linking.VisibilityMode;
import org.opentripplanner.street.model.StreetConstants;

public class TestVertexLinker {
public class VertexLinkerTestFactory {

public static VertexLinker of(Graph graph) {
return new VertexLinker(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
import org.opentripplanner.graph_builder.module.DirectTransferGenerator;
import org.opentripplanner.graph_builder.module.TestStreetLinkerModule;
import org.opentripplanner.graph_builder.module.TurnRestrictionModule;
import org.opentripplanner.graph_builder.module.linking.TestVertexLinker;
import org.opentripplanner.graph_builder.module.ned.ElevationModule;
import org.opentripplanner.graph_builder.module.ned.GeotiffGridCoverageFactoryImpl;
import org.opentripplanner.graph_builder.module.osm.OsmModule;
import org.opentripplanner.gtfs.graphbuilder.GtfsBundle;
import org.opentripplanner.gtfs.graphbuilder.GtfsBundleTestFactory;
import org.opentripplanner.gtfs.graphbuilder.GtfsModule;
import org.opentripplanner.model.calendar.ServiceDateInterval;
import org.opentripplanner.model.impl.OtpTransitServiceBuilder;
Expand All @@ -34,6 +33,7 @@
import org.opentripplanner.routing.fares.FareServiceFactory;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.linking.VertexLinker;
import org.opentripplanner.routing.linking.VertexLinkerTestFactory;
import org.opentripplanner.service.osminfo.internal.DefaultOsmInfoGraphBuildRepository;
import org.opentripplanner.service.vehicleparking.internal.DefaultVehicleParkingRepository;
import org.opentripplanner.service.vehiclerental.model.RentalVehicleType;
Expand Down Expand Up @@ -326,7 +326,7 @@ public static void addGtfsToGraph(
FareServiceFactory fareServiceFactory,
@Nullable String feedId
) {
var bundle = GtfsBundle.forTest(file, feedId);
var bundle = GtfsBundleTestFactory.forTest(file, feedId);

var module = new GtfsModule(
List.of(bundle),
Expand All @@ -347,7 +347,7 @@ public static void addGtfsToGraph(

private static void addPortlandVehicleRentals(Graph graph) {
try {
VertexLinker linker = TestVertexLinker.of(graph);
VertexLinker linker = VertexLinkerTestFactory.of(graph);
CsvReader reader = new CsvReader(PORTLAND_BIKE_SHARE_CSV, ',', StandardCharsets.UTF_8);
reader.readHeaders();
while (reader.readRecord()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.opentripplanner.api.common.LocationStringParser;
import org.opentripplanner.ext.fares.impl.gtfs.DefaultFareService;
import org.opentripplanner.gtfs.graphbuilder.GtfsBundle;
import org.opentripplanner.gtfs.graphbuilder.GtfsBundleTestFactory;
import org.opentripplanner.gtfs.graphbuilder.GtfsModule;
import org.opentripplanner.model.TimetableSnapshot;
import org.opentripplanner.model.calendar.ServiceDateInterval;
Expand Down Expand Up @@ -194,7 +195,7 @@ protected void setUp() throws Exception {
File gtfs = new File("src/test/resources/" + getFeedName());
File gtfsRealTime = new File("src/test/resources/" + getFeedName() + ".pb");

GtfsBundle gtfsBundle = GtfsBundle.forTest(gtfs, FEED_ID);
GtfsBundle gtfsBundle = GtfsBundleTestFactory.forTest(gtfs, FEED_ID);
List<GtfsBundle> gtfsBundleList = List.of(gtfsBundle);

alertsUpdateHandler = new AlertsUpdateHandler(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import org.opentripplanner.ext.emission.internal.DefaultEmissionRepository;
import org.opentripplanner.ext.emission.internal.DefaultEmissionService;
import org.opentripplanner.ext.emission.internal.itinerary.EmissionItineraryDecorator;
import org.opentripplanner.graph_builder.module.linking.TestVertexLinker;
import org.opentripplanner.raptor.configure.RaptorConfig;
import org.opentripplanner.routing.algorithm.filterchain.framework.spi.ItineraryDecorator;
import org.opentripplanner.routing.algorithm.raptoradapter.transit.TripSchedule;
import org.opentripplanner.routing.api.request.RouteRequest;
import org.opentripplanner.routing.fares.FareService;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.linking.VertexLinker;
import org.opentripplanner.routing.linking.VertexLinkerTestFactory;
import org.opentripplanner.routing.via.ViaCoordinateTransferFactory;
import org.opentripplanner.routing.via.service.DefaultViaCoordinateTransferFactory;
import org.opentripplanner.service.realtimevehicles.RealtimeVehicleService;
Expand Down Expand Up @@ -127,7 +127,7 @@ public static OtpServerRequestContext createServerContext(
}

private static VertexLinker createVertexLinker(Graph graph) {
return TestVertexLinker.of(graph);
return VertexLinkerTestFactory.of(graph);
}

/** Static factory method to create a service for test purposes. */
Expand Down Expand Up @@ -169,7 +169,7 @@ public static ViaCoordinateTransferFactory createViaTransferResolver(
) {
return new DefaultViaCoordinateTransferFactory(
graph,
TestVertexLinker.of(graph),
VertexLinkerTestFactory.of(graph),
transitService,
Duration.ofMinutes(30)
);
Expand Down
Loading
Loading