Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.rocketmq.studio.instance.topic;

import com.rocketmq.studio.common.domain.Result;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -49,7 +50,7 @@ public Result<LiteTopicSessionVO> getSession(@PathVariable String sessionId) {
}

@PostMapping("/extendTTL")
public Result<Void> extendTTL(@RequestBody LiteTopicTTLUpdateDTO request) {
public Result<Void> extendTTL(@Valid @RequestBody LiteTopicTTLUpdateDTO request) {
liteTopicService.extendTTL(request.getTopicPattern(), request.getNewTTL());
return Result.ok();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

package com.rocketmq.studio.instance.topic;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;
import lombok.Data;

@Data
public class LiteTopicTTLUpdateDTO {
@NotBlank(message = "topicPattern is required")
private String topicPattern;
@Positive(message = "newTTL must be positive")
private Long newTTL;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
Expand Down Expand Up @@ -124,4 +125,35 @@ void extendTTLShouldDelegateToService() throws Exception {

verify(liteTopicService).extendTTL(eq("chat/{sessionId}"), eq(7_200_000L));
}

@Test
void extendTTLShouldRejectMissingTopicPattern() throws Exception {
LiteTopicTTLUpdateDTO request = new LiteTopicTTLUpdateDTO();
request.setNewTTL(7_200_000L);

mockMvc.perform(post("/api/liteTopic/extendTTL")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value(400))
.andExpect(jsonPath("$.message").value("topicPattern is required"));

verifyNoInteractions(liteTopicService);
}

@Test
void extendTTLShouldRejectNonPositiveTTL() throws Exception {
LiteTopicTTLUpdateDTO request = new LiteTopicTTLUpdateDTO();
request.setTopicPattern("chat/{sessionId}");
request.setNewTTL(0L);

mockMvc.perform(post("/api/liteTopic/extendTTL")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value(400))
.andExpect(jsonPath("$.message").value("newTTL must be positive"));

verifyNoInteractions(liteTopicService);
}
}
Loading