Interface TrafficParrotServices
To get it, give the extension a public constructor with one parameter, of type TrafficParrotServices;
Traffic Parrot calls it instead of the no-argument constructor, so an extension without one is created as before,
as is one whose constructor takes anything more. Keep it, or a service from it, in a field: it stays valid for the
extension's lifetime, is safe to use from any thread, and each service reads its configuration on each use, so an
edit takes effect without a restart. Ask a service for something, such as a DataSource, when the extension
runs, not in its constructor: Traffic Parrot also creates extensions to list them in its web interface. In the
extension's own unit tests, pass withDatabaseConnections(com.trafficparrot.sdk.database.DatabaseConnections) or any implementation that overrides the services the extension uses.
Declare the SDK dependency with provided scope: a constructor taking a TrafficParrotServices from a
relocated copy of the SDK bundled in the extension jar is refused.
An HTTP response transformer serving a scenario that has its own port gets that scenario's services. Every other extension gets the services of the scenario selected in Traffic Parrot.
Every service is a default method, and services added in later versions will be too, so an implementation written for a test keeps compiling. Inside Traffic Parrot no service method returns null.
-
Method Summary
Modifier and TypeMethodDescriptiondefault DatabaseConnectionsThe database connections configured indatabase-connections.json.static TrafficParrotServiceswithDatabaseConnections(DatabaseConnections databaseConnections) Services with these database connections, for an extension's unit test:new MyExtension(TrafficParrotServices.withDatabaseConnections(connectionId -> inMemoryDataSource)).
-
Method Details
-
databaseConnections
The database connections configured indatabase-connections.json.- Throws:
UnsupportedOperationException- if this implementation does not provide them, as a test's may not
-
withDatabaseConnections
Services with these database connections, for an extension's unit test:new MyExtension(TrafficParrotServices.withDatabaseConnections(connectionId -> inMemoryDataSource)).
-