5
5
import java .util .concurrent .TimeUnit ;
6
6
7
7
import org .junit .Before ;
8
- import org .junit .BeforeClass ;
9
8
import org .junit .ClassRule ;
10
9
import org .junit .Test ;
11
10
import org .junit .runner .RunWith ;
12
11
import org .springframework .beans .factory .annotation .Autowired ;
13
12
import org .springframework .boot .test .context .SpringBootTest ;
14
13
import org .springframework .kafka .config .KafkaListenerEndpointRegistry ;
15
14
import org .springframework .kafka .listener .MessageListenerContainer ;
16
- import org .springframework .kafka .support .KafkaHeaders ;
17
15
import org .springframework .kafka .test .rule .KafkaEmbedded ;
18
16
import org .springframework .kafka .test .utils .ContainerTestUtils ;
19
- import org .springframework .messaging .Message ;
20
- import org .springframework .messaging .support .MessageBuilder ;
21
17
import org .springframework .test .context .junit4 .SpringRunner ;
22
18
23
19
import com .codenotfound .kafka .consumer .Receiver ;
@@ -44,11 +40,6 @@ public class SpringKafkaApplicationTest {
44
40
@ ClassRule
45
41
public static KafkaEmbedded embeddedKafka = new KafkaEmbedded (1 , true , BAR_TOPIC , FOO_TOPIC );
46
42
47
- @ BeforeClass
48
- public static void setUpBeforeClass () throws Exception {
49
- System .setProperty ("kafka.bootstrap-servers" , embeddedKafka .getBrokersAsString ());
50
- }
51
-
52
43
@ Before
53
44
public void setUp () throws Exception {
54
45
// wait until the partitions are assigned
@@ -61,13 +52,8 @@ public void setUp() throws Exception {
61
52
62
53
@ Test
63
54
public void testReceive () throws Exception {
64
- Message <Bar > bar =
65
- MessageBuilder .withPayload (new Bar ("bar" )).setHeader (KafkaHeaders .TOPIC , BAR_TOPIC ).build ();
66
- sender .send (bar );
67
-
68
- Message <Foo > foo =
69
- MessageBuilder .withPayload (new Foo ("foo" )).setHeader (KafkaHeaders .TOPIC , FOO_TOPIC ).build ();
70
- sender .send (foo );
55
+ sender .send (BAR_TOPIC , new Bar ("bar" ));
56
+ sender .send (FOO_TOPIC , new Foo ("foo" ));
71
57
72
58
receiver .getLatch ().await (10000 , TimeUnit .MILLISECONDS );
73
59
assertThat (receiver .getLatch ().getCount ()).isEqualTo (0 );
0 commit comments