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 @@ -19,6 +19,7 @@
import com.rocketmq.studio.cluster.config.UpdateConfigDTO;

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 @@ -48,7 +49,7 @@ public Result<ClusterVO> getCluster(@PathVariable String id) {
}

@PostMapping("/config/update")
public Result<ClusterVO> updateClusterConfig(@RequestBody UpdateConfigDTO command) {
public Result<ClusterVO> updateClusterConfig(@Valid @RequestBody UpdateConfigDTO command) {
return Result.ok(clusterService.updateClusterConfig(command));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.rocketmq.studio.cluster.config;

import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -26,7 +27,9 @@
@NoArgsConstructor
@AllArgsConstructor
public class UpdateConfigDTO {
@NotBlank(message = "id is required")
private String id;

private String flushDiskType;
private Boolean autoCreateTopicEnable;
private Boolean autoCreateSubscriptionGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Collections;

import static org.mockito.ArgumentMatchers.any;
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 @@ -135,6 +136,40 @@ void updateConfigShouldReturnUpdatedCluster() throws Exception {
.andExpect(jsonPath("$.data.config.readQueueNums").value(16));
}

@Test
void updateConfigShouldRejectMissingId() throws Exception {
UpdateConfigDTO command = UpdateConfigDTO.builder()
.flushDiskType("SYNC_FLUSH")
.writeQueueNums(16)
.build();

mockMvc.perform(post("/api/clusters/config/update")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(command)))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value(400))
.andExpect(jsonPath("$.message").value("id is required"));

verifyNoInteractions(clusterService);
}

@Test
void updateConfigShouldRejectBlankId() throws Exception {
UpdateConfigDTO command = UpdateConfigDTO.builder()
.id(" ")
.flushDiskType("SYNC_FLUSH")
.build();

mockMvc.perform(post("/api/clusters/config/update")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(command)))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value(400))
.andExpect(jsonPath("$.message").value("id is required"));

verifyNoInteractions(clusterService);
}

@Test
void restartBrokerShouldReturnSuccess() throws Exception {
when(clusterService.restartBroker("cluster-1", "broker-0")).thenReturn(true);
Expand Down
Loading