71fbfeca7b6e929ed1fde2189325bc07ce050c47
[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.messaging.Message;
14 import org.springframework.test.annotation.DirtiesContext;
15 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
16
17 @RunWith(SpringJUnit4ClassRunner.class)
18 @SpringBootTest(classes = { Sender.class })
19 @DirtiesContext
20 public class SenderShould {
21
22         @Inject
23         Source source;
24         
25         @Inject
26         Sender sender;
27         
28         @Inject
29         private MessageCollector messageCollector;
30         
31         @Test
32         public void sendSomeProduct() {
33                 Product product = new Product("hello", "this is some description");
34                 
35                 sender.sendMessage("hello");
36                 
37                 Message<Product> received = (Message<Product>) messageCollector.forChannel(source.output()).poll();
38                 
39             assertThat(received.getPayload().getDescription(), is(product.getDescription()));
40         }
41
42 }