io.kroxylicious.testing.kafka.junit5ext.Name Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testing-junit5-extension Show documentation
Show all versions of testing-junit5-extension Show documentation
Provides a JUnit5 extension for providing KafkaCluster implementations to tests and running tests over multiple cluster configurations.
/*
* Copyright Kroxylicious Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.kroxylicious.testing.kafka.junit5ext;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import io.kroxylicious.testing.kafka.api.KafkaCluster;
/**
* Disambiguating annotation for declarations of type {@link KafkaCluster},
* {@link org.apache.kafka.clients.producer.Producer} etc.
* when there are multiple {@code KafkaClusters} in scope.
*
* For example, consider the following declaration:
*
* {@code
* KafkaCluster clusterA;
* KafkaCluster clusterB;
* @Test
* public void myTest(Producer producer)
* }*
*
* {@link KafkaClusterExtension} will fail parameter resolution with
* {@link AmbiguousKafkaClusterException} in this case
* because it's not clear whether {@code producer} should be configured for
* {@code clusterA} or {@code clusterB}.
*
* You can disambiguate the code using {@code @Name}, like this:
* {@code
* @Name("A") KafkaCluster clusterA;
* @Name("B") KafkaCluster clusterB;
* @Test
* public void myTest(@Name("A") Producer producer)
* }*
* Where the {@code @Name} on the declaration of {@code producer}
* associates it with {@code clusterA}.
*
*
*/
@Target({ ElementType.PARAMETER, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
public @interface Name {
/**
* Value of the name.
*
* @return the value
*/
String value();
}