test(cache): 修复CacheConfigTest边界值测试
- 修改 shouldVerifyCacheManager_withMaximumIntegerTtl 为 shouldVerifyCacheManager_withMaximumAllowedTtl - 使用正确的最大TTL值(10080分钟,7天)而不是 Integer.MAX_VALUE - 新增 shouldThrowException_whenTtlExceedsMaximum 测试验证边界检查 - 所有1266个测试用例通过 - 覆盖率: 指令81.89%, 行88.48%, 分支51.55% docs: 添加项目状态报告 - 生成 PROJECT_STATUS_REPORT.md 详细记录项目当前状态 - 包含质量指标、已完成功能、待办事项和技术债务
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package com.mosquito.project.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.mosquito.project.dto.RegisterCallbackRequest;
|
||||
import com.mosquito.project.dto.CreateActivityRequest;
|
||||
import com.mosquito.project.service.ActivityService;
|
||||
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.web.server.LocalServerPort;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
@TestPropertySource(properties = {
|
||||
"spring.flyway.enabled=false",
|
||||
"app.rate-limit.per-minute=2",
|
||||
"spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration"
|
||||
})
|
||||
class CallbackControllerIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Autowired
|
||||
private ActivityService activityService;
|
||||
|
||||
private String anyValidApiKey() {
|
||||
CreateActivityRequest r = new CreateActivityRequest();
|
||||
r.setName("cb");
|
||||
r.setStartTime(java.time.ZonedDateTime.now());
|
||||
r.setEndTime(java.time.ZonedDateTime.now().plusDays(1));
|
||||
var act = activityService.createActivity(r);
|
||||
com.mosquito.project.dto.CreateApiKeyRequest k = new com.mosquito.project.dto.CreateApiKeyRequest();
|
||||
k.setActivityId(act.getId());
|
||||
k.setName("k");
|
||||
return activityService.generateApiKey(k);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldBeIdempotent_andRateLimited() throws Exception {
|
||||
String key = anyValidApiKey();
|
||||
RegisterCallbackRequest req = new RegisterCallbackRequest();
|
||||
req.setTrackingId("track-001");
|
||||
mockMvc.perform(post("/api/v1/callback/register")
|
||||
.header("X-API-Key", key)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(req)))
|
||||
.andExpect(status().isOk());
|
||||
// 2nd same tracking id should still be OK (idempotent)
|
||||
mockMvc.perform(post("/api/v1/callback/register")
|
||||
.header("X-API-Key", key)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(req)))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
// exceed rate limit (limit=2 per minute) with a different tracking id
|
||||
RegisterCallbackRequest req2 = new RegisterCallbackRequest();
|
||||
req2.setTrackingId("track-002");
|
||||
mockMvc.perform(post("/api/v1/callback/register")
|
||||
.header("X-API-Key", key)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(req2)))
|
||||
.andExpect(status().isTooManyRequests());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user