Skip to content

KafkaAutoConfigurationIntegrationTests to JUnit5 #17034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

import org.apache.kafka.clients.admin.NewTopic;
import org.apache.kafka.clients.producer.Producer;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
Expand All @@ -35,7 +36,7 @@
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.kafka.test.rule.EmbeddedKafkaRule;
import org.springframework.kafka.test.EmbeddedKafkaBroker;
import org.springframework.messaging.handler.annotation.Header;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -52,19 +53,28 @@ public class KafkaAutoConfigurationIntegrationTests {

private static final String ADMIN_CREATED_TOPIC = "adminCreatedTopic";

@ClassRule
public static final EmbeddedKafkaRule embeddedKafka = new EmbeddedKafkaRule(1, true,
TEST_TOPIC);
public static final EmbeddedKafkaBroker embeddedKafka = new EmbeddedKafkaBroker(1,
true, TEST_TOPIC);

private AnnotationConfigApplicationContext context;

@BeforeAll
public static void setUp() {
embeddedKafka.afterPropertiesSet();
}

@AfterEach
public void close() {
if (this.context != null) {
this.context.close();
}
}

@AfterAll
public static void tearDown() {
embeddedKafka.destroy();
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testEndToEnd() throws Exception {
Expand Down Expand Up @@ -110,7 +120,7 @@ private AnnotationConfigApplicationContext doLoad(Class<?>[] configs,
}

private String getEmbeddedKafkaBrokersAsString() {
return embeddedKafka.getEmbeddedKafka().getBrokersAsString();
return embeddedKafka.getBrokersAsString();
}

@Configuration(proxyBeanMethods = false)
Expand Down