Package io.micronaut.testresources.kafka
Class KafkaTestResourceProvider
java.lang.Object
io.micronaut.testresources.testcontainers.AbstractTestContainersProvider<org.testcontainers.containers.KafkaContainer>
io.micronaut.testresources.kafka.KafkaTestResourceProvider
- All Implemented Interfaces:
io.micronaut.core.order.Ordered
,TestResourcesResolver
,ToggableTestResourcesResolver
public class KafkaTestResourceProvider
extends AbstractTestContainersProvider<org.testcontainers.containers.KafkaContainer>
A test resource provider which will spawn a Kafka test container.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
Leverage confluent-local image as it is optimized for local development and the image enables KRaft mode with no configuration setup.static final String
static final String
static final String
Fields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Fields inherited from interface io.micronaut.testresources.core.TestResourcesResolver
TEST_RESOURCES_PROPERTY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected org.testcontainers.containers.KafkaContainer
createContainer
(org.testcontainers.utility.DockerImageName imageName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Creates the test container.protected String
Returns the default image name.Returns a display name for a test resources resolver, used for debugging purposes.getResolvableProperties
(Map<String, Collection<String>> propertyEntries, Map<String, Object> testResourcesConfig) Returns the list of properties that this resolver is able to support.protected String
Returns the name of the resource resolver, for example "kafka" or "mysql".resolveProperty
(String propertyName, org.testcontainers.containers.KafkaContainer container) protected boolean
shouldAnswer
(String propertyName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Determines if this resolver can resolve the requested property.Methods inherited from class io.micronaut.testresources.testcontainers.AbstractTestContainersProvider
configureContainer, getName, getOrder, resolve, resolveWithoutContainer, stringOrNull
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.testresources.core.TestResourcesResolver
getId, getRequiredProperties, getRequiredPropertyEntries
Methods inherited from interface io.micronaut.testresources.core.ToggableTestResourcesResolver
isEnabled
-
Field Details
-
KAFKA_BOOTSTRAP_SERVERS
- See Also:
-
DEFAULT_IMAGE
- See Also:
-
DEFAULT_KRAFT_IMAGE
Leverage confluent-local image as it is optimized for local development and the image enables KRaft mode with no configuration setup. See: Confluent Kafka Images- See Also:
-
DISPLAY_NAME
- See Also:
-
SIMPLE_NAME
- See Also:
-
SUPPORTED_PROPERTIES_LIST
-
-
Constructor Details
-
KafkaTestResourceProvider
public KafkaTestResourceProvider()
-
-
Method Details
-
getResolvableProperties
public List<String> getResolvableProperties(Map<String, Collection<String>> propertyEntries, Map<String, Object> testResourcesConfig) Description copied from interface:TestResourcesResolver
Returns the list of properties that this resolver is able to support. The property entries map is a map which keys are the property entries retrieved from callingTestResourcesResolver.getRequiredPropertyEntries()
and values are those property entries resolved.- Parameters:
propertyEntries
- the property entriestestResourcesConfig
- the test resources configuration- Returns:
- the list of properties
-
getDisplayName
Description copied from interface:TestResourcesResolver
Returns a display name for a test resources resolver, used for debugging purposes.- Returns:
- the display name
-
getSimpleName
Description copied from class:AbstractTestContainersProvider
Returns the name of the resource resolver, for example "kafka" or "mysql".- Specified by:
getSimpleName
in classAbstractTestContainersProvider<org.testcontainers.containers.KafkaContainer>
- Returns:
- the name of the resolver
-
getDefaultImageName
Description copied from class:AbstractTestContainersProvider
Returns the default image name.- Specified by:
getDefaultImageName
in classAbstractTestContainersProvider<org.testcontainers.containers.KafkaContainer>
- Returns:
- the default image name.
-
createContainer
protected org.testcontainers.containers.KafkaContainer createContainer(org.testcontainers.utility.DockerImageName imageName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Description copied from class:AbstractTestContainersProvider
Creates the test container.- Specified by:
createContainer
in classAbstractTestContainersProvider<org.testcontainers.containers.KafkaContainer>
- Parameters:
imageName
- the docker image namerequestedProperties
- the resolved propertiestestResourcesConfig
- the test resources configuration- Returns:
- a container
-
resolveProperty
protected Optional<String> resolveProperty(String propertyName, org.testcontainers.containers.KafkaContainer container) - Specified by:
resolveProperty
in classAbstractTestContainersProvider<org.testcontainers.containers.KafkaContainer>
-
shouldAnswer
protected boolean shouldAnswer(String propertyName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfig) Description copied from class:AbstractTestContainersProvider
Determines if this resolver can resolve the requested property. It is used in order to make sure that a "Postgres" resolver wouldn't provide a value if the requested container type is for MySQL, for example.- Overrides:
shouldAnswer
in classAbstractTestContainersProvider<org.testcontainers.containers.KafkaContainer>
- Parameters:
propertyName
- the property to resolverequestedProperties
- the resolved propertiestestResourcesConfig
- the test resources configuration- Returns:
- if this resolver should answer
-