Download src/test/java/com/anthony/failsafeapi/controller/AuditControllerTest.java from tonyy1/tickets: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/spaces/tonyy1/tickets/resolve/main/src/test/java/com/anthony/failsafeapi/controller/AuditControllerTest.java
- Command line
-
hf download hf://spaces/tonyy1/tickets/src/test/java/com/anthony/failsafeapi/controller/AuditControllerTest.java
-
curl -L -o AuditControllerTest.java https://huggingface.co/spaces/tonyy1/tickets/resolve/main/src/test/java/com/anthony/failsafeapi/controller/AuditControllerTest.java
2.46 kB
| package com.anthony.failsafeapi.controller; | |
| import com.anthony.failsafeapi.model.AuditSummary; | |
| import com.anthony.failsafeapi.service.AuditService; | |
| import org.junit.jupiter.api.DisplayName; | |
| import org.junit.jupiter.api.Test; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | |
| import org.springframework.test.context.bean.override.mockito.MockitoBean; | |
| import org.springframework.test.web.servlet.MockMvc; | |
| import java.math.BigDecimal; | |
| import static org.mockito.Mockito.when; | |
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | |
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | |
| class AuditControllerTest { | |
| private MockMvc mockMvc; | |
| private AuditService auditService; | |
| void shouldReturnAuditSummary() throws Exception { | |
| AuditSummary summary = new AuditSummary( | |
| 1500L, new BigDecimal("0.00123"), 10L, 2L, 350L, 800L, "CLOSED" | |
| ); | |
| when(auditService.getCostSummary()).thenReturn(summary); | |
| mockMvc.perform(get("/api/v1/audit/costs")) | |
| .andExpect(status().isOk()) | |
| .andExpect(jsonPath("$.totalTokensConsumed").value(1500)) | |
| .andExpect(jsonPath("$.successfulCalls").value(10)) | |
| .andExpect(jsonPath("$.fallbackCalls").value(2)) | |
| .andExpect(jsonPath("$.avgLatencyMs").value(350)) | |
| .andExpect(jsonPath("$.maxLatencyMs").value(800)) | |
| .andExpect(jsonPath("$.circuitBreakerState").value("CLOSED")); | |
| } | |
| void shouldReturnZeroSummaryWhenEmpty() throws Exception { | |
| AuditSummary emptySummary = new AuditSummary( | |
| 0L, BigDecimal.ZERO, 0L, 0L, 0L, 0L, "UNKNOWN" | |
| ); | |
| when(auditService.getCostSummary()).thenReturn(emptySummary); | |
| mockMvc.perform(get("/api/v1/audit/costs")) | |
| .andExpect(status().isOk()) | |
| .andExpect(jsonPath("$.totalTokensConsumed").value(0)) | |
| .andExpect(jsonPath("$.circuitBreakerState").value("UNKNOWN")); | |
| } | |
| } | |