21
21
22
22
import org .apache .kafka .clients .admin .NewTopic ;
23
23
import org .apache .kafka .clients .producer .Producer ;
24
- import org .junit .ClassRule ;
25
- import org .junit .Test ;
24
+ import org .junit .jupiter .api .AfterAll ;
26
25
import org .junit .jupiter .api .AfterEach ;
26
+ import org .junit .jupiter .api .BeforeAll ;
27
+ import org .junit .jupiter .api .Test ;
27
28
28
29
import org .springframework .boot .test .util .TestPropertyValues ;
29
30
import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
35
36
import org .springframework .kafka .core .DefaultKafkaProducerFactory ;
36
37
import org .springframework .kafka .core .KafkaTemplate ;
37
38
import org .springframework .kafka .support .KafkaHeaders ;
38
- import org .springframework .kafka .test .rule . EmbeddedKafkaRule ;
39
+ import org .springframework .kafka .test .EmbeddedKafkaBroker ;
39
40
import org .springframework .messaging .handler .annotation .Header ;
40
41
41
42
import static org .assertj .core .api .Assertions .assertThat ;
@@ -52,19 +53,28 @@ public class KafkaAutoConfigurationIntegrationTests {
52
53
53
54
private static final String ADMIN_CREATED_TOPIC = "adminCreatedTopic" ;
54
55
55
- @ ClassRule
56
- public static final EmbeddedKafkaRule embeddedKafka = new EmbeddedKafkaRule (1 , true ,
57
- TEST_TOPIC );
56
+ public static final EmbeddedKafkaBroker embeddedKafka = new EmbeddedKafkaBroker (1 ,
57
+ true , TEST_TOPIC );
58
58
59
59
private AnnotationConfigApplicationContext context ;
60
60
61
+ @ BeforeAll
62
+ public static void setUp () {
63
+ embeddedKafka .afterPropertiesSet ();
64
+ }
65
+
61
66
@ AfterEach
62
67
public void close () {
63
68
if (this .context != null ) {
64
69
this .context .close ();
65
70
}
66
71
}
67
72
73
+ @ AfterAll
74
+ public static void tearDown () {
75
+ embeddedKafka .destroy ();
76
+ }
77
+
68
78
@ SuppressWarnings ({ "unchecked" , "rawtypes" })
69
79
@ Test
70
80
public void testEndToEnd () throws Exception {
@@ -110,7 +120,7 @@ private AnnotationConfigApplicationContext doLoad(Class<?>[] configs,
110
120
}
111
121
112
122
private String getEmbeddedKafkaBrokersAsString () {
113
- return embeddedKafka .getEmbeddedKafka (). getBrokersAsString ();
123
+ return embeddedKafka .getBrokersAsString ();
114
124
}
115
125
116
126
@ Configuration (proxyBeanMethods = false )
0 commit comments