2b170b74e0917e8e44ad98cc86e1d48b05c4dfde
[JavaForFun] /
1 package de.example.spring.kafka;
2
3 import static org.hamcrest.CoreMatchers.is;
4 import static org.junit.Assert.assertThat;
5
6 import javax.inject.Inject;
7
8 import org.junit.Test;
9 import org.junit.runner.RunWith;
10 import org.springframework.boot.test.context.SpringBootTest;
11 import org.springframework.cloud.stream.messaging.Source;
12 import org.springframework.cloud.stream.test.binder.MessageCollector;
13 import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration;
14 import org.springframework.messaging.Message;
15 import org.springframework.test.annotation.DirtiesContext;
16 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
17
18 @RunWith(SpringJUnit4ClassRunner.class)
19 @SpringBootTest(classes = { Sender.class, TestSupportBinderAutoConfiguration.class })
20 @DirtiesContext
21 public class SenderIntegrationTest {
22
23         @Inject
24         Source source;
25         
26         @Inject
27         Sender sender;
28         
29         @Inject
30         private MessageCollector messageCollector;
31         
32         @Test
33         public void sendSomeProduct() {
34                 Product product = new Product("hello", "this is some description");
35                 
36                 sender.sendMessage("hello");
37                 
38                 Message<Product> received = (Message<Product>) messageCollector.forChannel(source.output()).poll();
39                 
40             assertThat(received.getPayload().getDescription(), is(product.getDescription()));
41         }
42
43 }