Add test case for first challenge
package com.example.secrettextprinter;
+import org.hamcrest.CoreMatchers;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.context.WebApplicationContext;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ExtendWith({SpringExtension.class})
+@ActiveProfiles("test")
+@AutoConfigureWebTestClient
class SecretLeakageControllerTest {
+ @Autowired
+ private WebApplicationContext webApplicationContext;
+ private MockMvc mockMvc;
+ @Value("${password}")
+ private String hardcodedPassword;
+ @BeforeEach
+ public void setup() {
+ this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
+ }
+
+ @Test
+ void spoil1() throws Exception {
+ this.mockMvc.perform(MockMvcRequestBuilders.get("/spoil-1"))
+ .andDo(print())
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.content().string(CoreMatchers.containsString(hardcodedPassword)));
+ }
+
+ @Test
+ void solveChallenge1() throws Exception {
+ this.mockMvc.perform(MockMvcRequestBuilders.post("/challenge/1").param("solution", hardcodedPassword))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andExpect(MockMvcResultMatchers.content().string(CoreMatchers.containsString("You&#39;re answer is correct!")));
+ }
+
}
