WIP
authorKai Moritz <kai@juplo.de>
Sun, 5 May 2024 11:52:36 +0000 (13:52 +0200)
committerKai Moritz <kai@juplo.de>
Sun, 5 May 2024 11:52:36 +0000 (13:52 +0200)
src/test/java/de/juplo/kafka/wordcount/recorder/ApplicationTests.java

index 42729d1..6bb8845 100644 (file)
@@ -6,17 +6,20 @@ import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.TestConfiguration;
-import org.springframework.boot.test.web.client.TestRestTemplate;
 import org.springframework.context.annotation.Bean;
 import org.springframework.http.MediaType;
 import org.springframework.kafka.annotation.KafkaListener;
 import org.springframework.kafka.test.context.EmbeddedKafka;
+import org.springframework.test.web.servlet.MockMvc;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 
 import static de.juplo.kafka.wordcount.recorder.ApplicationTests.PARTITIONS;
 import static de.juplo.kafka.wordcount.recorder.ApplicationTests.TOPIC_OUT;
-import static org.assertj.core.api.Assertions.assertThat;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
 
 @SpringBootTest(
@@ -28,11 +31,14 @@ import static org.assertj.core.api.Assertions.assertThat;
 @Slf4j
 class ApplicationTests
 {
-       public final static String TOPIC_OUT = "out";
+       static final String TOPIC_OUT = "out";
        static final int PARTITIONS = 2;
+       static final String USER = "päter";
+       static final String SENTENCE = "Hall° Wält?¢*&%€!";
+
 
        @Autowired
-       private TestRestTemplate restTemplate;
+       private MockMvc mockMvc;
 
        @Test
        void contextLoads()
@@ -42,13 +48,14 @@ class ApplicationTests
        @Test
        void userEventsAreSent()
        {
-               assertThat(restTemplate.postForObject("peter", "Hällö Wählt?*$@¢!", RecordingResult.class)).contains("Hello, World");
-               client
-                               .post()
-                               .uri("peter")
-                               .contentType(MediaType.TEXT_PLAIN)
-                               .bodyValue("Hallö Wält*&%€!")
-                               .
+               mockMvc
+                               .perform(post(USER)
+                                               .contentType(MediaType.TEXT_PLAIN)
+                                               .content(SENTENCE))
+                               .andDo(print())
+                               .andExpect(status().isOk())
+                               .andExpect(jsonPath("$.username").value(USER))
+                               .andExpect(jsonPath("$.sentence").value(SENTENCE));
        }
 
        static class Consumer