/
marie.sidorkina
/
eye_tracking_java
Обзор
Документация
Войти
/
marie.sidorkina
/
eye_tracking_java
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/test/java/com/example/mydemo1/ChunkControllerTest.java
73 строки
3 KB
Marie
add tests
14 янв 2026, 11:17
14 янв 2026, 11:17
c2fa01e
Код
Авторство
О чём код?
package com.example.mydemo1; import com.example.mydemo1.dto.GazeCreateRequest; import com.example.mydemo1.dto.ChunkCreateRequest; import com.example.mydemo1.dto.HintDto; import com.example.mydemo1.orchestrator.ChunkOrchestrator; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.http.MediaType; import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; import java.time.Instant; import java.util.List; import static org.mockito.ArgumentMatchers.any; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @WebMvcTest(controllers = com.example.mydemo1.controller.ChunkController.class) @AutoConfigureMockMvc(addFilters = false) class ChunkControllerTest { @Autowired private MockMvc mockMvc; @MockitoBean private ChunkOrchestrator chunkOrchestrator; @Autowired private ObjectMapper objectMapper; @Test @DisplayName("POST /api/chunks -> 201 and returns HintDto") void createChunk_returnsHintDto() throws Exception { ChunkCreateRequest req = new ChunkCreateRequest(); req.setSessionId(123L); req.setTimestamp(Instant.now()); req.setElementFrom("p.line1"); req.setElementTo("p.line2"); GazeCreateRequest g = new GazeCreateRequest(); g.setTimestamp(Instant.now()); g.setX(100.0); g.setY(200.0); req.setGazes(List.of(g)); HintDto hint = new HintDto(); hint.setId(11L); hint.setSessionId(123L); hint.setEvent("USER_REGRESSION_DETECTED"); hint.setAction("HIGHLIGHT_ELEMENT"); hint.setTargetElement("p.line1"); Mockito.when(chunkOrchestrator.processChunkAndReturnHint(any(ChunkCreateRequest.class))) .thenReturn(hint); mockMvc.perform(post("/api/chunks") .contentType(MediaType.APPLICATION_JSON) .content(objectMapper.writeValueAsString(req))) .andExpect(status().isCreated()) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(11)) .andExpect(jsonPath("$.sessionId").value(123)) .andExpect(jsonPath("$.event").value("USER_REGRESSION_DETECTED")) .andExpect(jsonPath("$.action").value("HIGHLIGHT_ELEMENT")) .andExpect(jsonPath("$.targetElement").value("p.line1")); } }