Class ContainerConnectionDetailsFactory<C extends org.testcontainers.containers.Container<?>,D extends ConnectionDetails>
java.lang.Object
org.springframework.boot.testcontainers.service.connection.ContainerConnectionDetailsFactory<C,D>
- Type Parameters:
D
- the connection details typeC
- the container type
- All Implemented Interfaces:
ConnectionDetailsFactory<ContainerConnectionSource<C>,
D>
public abstract class ContainerConnectionDetailsFactory<C extends org.testcontainers.containers.Container<?>,D extends ConnectionDetails>
extends Object
implements ConnectionDetailsFactory<ContainerConnectionSource<C>,D>
Base class for
ConnectionDetailsFactory
implementations that provide
ConnectionDetails
from a ContainerConnectionSource
.- Since:
- 3.1.0
- Author:
- Moritz Halbritter, Andy Wilkinson, Phillip Webb
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
ContainerConnectionDetailsFactory.ContainerConnectionDetails<C extends org.testcontainers.containers.Container<?>>
Base class forConnectionDetails
results that are backed by aContainerConnectionSource
. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
Constant passed to the constructor when any connection name is accepted. -
Constructor Summary
ModifierConstructorDescriptionprotected
Create a newContainerConnectionDetailsFactory
instance that acceptsany connection name
.protected
ContainerConnectionDetailsFactory
(String connectionName, String... requiredClassNames) Create a newContainerConnectionDetailsFactory
instance with the given connection name restriction.protected
ContainerConnectionDetailsFactory
(List<String> connectionNames, String... requiredClassNames) Create a newContainerConnectionDetailsFactory
instance with the given supported connection names. -
Method Summary
Modifier and TypeMethodDescriptionfinal D
Get theConnectionDetails
from the givensource
.protected abstract D
protected boolean
sourceAccepts
(ContainerConnectionSource<C> source, Class<?> requiredContainerType, Class<?> requiredConnectionDetailsType) Return if the given source accepts the connection.
-
Field Details
-
ANY_CONNECTION_NAME
Constant passed to the constructor when any connection name is accepted.
-
-
Constructor Details
-
ContainerConnectionDetailsFactory
protected ContainerConnectionDetailsFactory()Create a newContainerConnectionDetailsFactory
instance that acceptsany connection name
. -
ContainerConnectionDetailsFactory
Create a newContainerConnectionDetailsFactory
instance with the given connection name restriction.- Parameters:
connectionName
- the required connection name orANY_CONNECTION_NAME
requiredClassNames
- the names of classes that must be present
-
ContainerConnectionDetailsFactory
protected ContainerConnectionDetailsFactory(List<String> connectionNames, String... requiredClassNames) Create a newContainerConnectionDetailsFactory
instance with the given supported connection names.- Parameters:
connectionNames
- the supported connection namesrequiredClassNames
- the names of classes that must be present- Since:
- 3.4.0
-
-
Method Details
-
getConnectionDetails
Description copied from interface:ConnectionDetailsFactory
- Specified by:
getConnectionDetails
in interfaceConnectionDetailsFactory<C extends org.testcontainers.containers.Container<?>,
D extends ConnectionDetails> - Parameters:
source
- the source- Returns:
- the connection details or
null
-
sourceAccepts
protected boolean sourceAccepts(ContainerConnectionSource<C> source, Class<?> requiredContainerType, Class<?> requiredConnectionDetailsType) Return if the given source accepts the connection. By default this method checks each connection name.- Parameters:
source
- the container connection sourcerequiredContainerType
- the required container typerequiredConnectionDetailsType
- the required connection details type- Returns:
- if the source accepts the connection
- Since:
- 3.4.0
-
getContainerConnectionDetails
Get theConnectionDetails
from the givenContainerConnectionSource
source
. May returnnull
if no connection can be created. Result types should consider extendingContainerConnectionDetailsFactory.ContainerConnectionDetails
.- Parameters:
source
- the source- Returns:
- the service connection or
null
.
-