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
13 changes: 7 additions & 6 deletions server/src/main/java/com/rocketmq/studio/ops/OpsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.rocketmq.studio.ops;

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.PostMapping;
Expand All @@ -38,26 +39,26 @@ public Result<OpsHomeVO> homePage() {
}

@PostMapping("/updateNameSvrAddr")
public Result<Void> updateNameSvrAddr(@RequestBody OpsNameServerDTO request) {
public Result<Void> updateNameSvrAddr(@Valid @RequestBody OpsNameServerDTO request) {
opsService.updateNameServer(request.getNamesrvAddr());
return Result.ok();
}

@PostMapping("/addNameSvrAddr")
public Result<Void> addNameSvrAddr(@RequestBody OpsNameServerDTO request) {
public Result<Void> addNameSvrAddr(@Valid @RequestBody OpsNameServerDTO request) {
opsService.addNameServer(request.getNamesrvAddr());
return Result.ok();
}

@PostMapping("/updateIsVIPChannel")
public Result<Void> updateIsVIPChannel(@RequestBody OpsVipChannelDTO request) {
opsService.updateVipChannel(request.isUseVIPChannel());
public Result<Void> updateIsVIPChannel(@Valid @RequestBody OpsVipChannelDTO request) {
opsService.updateVipChannel(request.getUseVIPChannel());
return Result.ok();
}

@PostMapping("/updateUseTLS")
public Result<Void> updateUseTLS(@RequestBody OpsTlsDTO request) {
opsService.updateUseTLS(request.isUseTLS());
public Result<Void> updateUseTLS(@Valid @RequestBody OpsTlsDTO request) {
opsService.updateUseTLS(request.getUseTLS());
return Result.ok();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

package com.rocketmq.studio.ops;

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

@Data
public class OpsNameServerDTO {
@NotBlank(message = "namesrvAddr is required")
private String namesrvAddr;
}
4 changes: 3 additions & 1 deletion server/src/main/java/com/rocketmq/studio/ops/OpsTlsDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

package com.rocketmq.studio.ops;

import jakarta.validation.constraints.NotNull;
import lombok.Data;

@Data
public class OpsTlsDTO {
private boolean useTLS;
@NotNull(message = "useTLS is required")
private Boolean useTLS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

package com.rocketmq.studio.ops;

import jakarta.validation.constraints.NotNull;
import lombok.Data;

@Data
public class OpsVipChannelDTO {
private boolean useVIPChannel;
@NotNull(message = "useVIPChannel is required")
private Boolean useVIPChannel;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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 @@ -80,6 +81,18 @@ void updateNameSvrAddrShouldDelegateToService() throws Exception {
verify(opsService).updateNameServer(eq("10.0.0.1:9876"));
}

@Test
void updateNameSvrAddrShouldRejectMissingAddress() throws Exception {
mockMvc.perform(post("/api/ops/updateNameSvrAddr")
.contentType(MediaType.APPLICATION_JSON)
.content("{}"))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value(400))
.andExpect(jsonPath("$.message").value("namesrvAddr is required"));

verifyNoInteractions(opsService);
}

@Test
void addNameSvrAddrShouldDelegateToService() throws Exception {
mockMvc.perform(post("/api/ops/addNameSvrAddr")
Expand All @@ -90,6 +103,18 @@ void addNameSvrAddrShouldDelegateToService() throws Exception {
verify(opsService).addNameServer(eq("10.0.0.2:9876"));
}

@Test
void addNameSvrAddrShouldRejectBlankAddress() throws Exception {
mockMvc.perform(post("/api/ops/addNameSvrAddr")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(Map.of("namesrvAddr", " "))))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value(400))
.andExpect(jsonPath("$.message").value("namesrvAddr is required"));

verifyNoInteractions(opsService);
}

@Test
void updateVipChannelShouldDelegateToService() throws Exception {
mockMvc.perform(post("/api/ops/updateIsVIPChannel")
Expand All @@ -100,6 +125,18 @@ void updateVipChannelShouldDelegateToService() throws Exception {
verify(opsService).updateVipChannel(false);
}

@Test
void updateVipChannelShouldRejectMissingFlag() throws Exception {
mockMvc.perform(post("/api/ops/updateIsVIPChannel")
.contentType(MediaType.APPLICATION_JSON)
.content("{}"))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value(400))
.andExpect(jsonPath("$.message").value("useVIPChannel is required"));

verifyNoInteractions(opsService);
}

@Test
void updateUseTlsShouldDelegateToService() throws Exception {
mockMvc.perform(post("/api/ops/updateUseTLS")
Expand All @@ -109,4 +146,16 @@ void updateUseTlsShouldDelegateToService() throws Exception {

verify(opsService).updateUseTLS(true);
}

@Test
void updateUseTlsShouldRejectMissingFlag() throws Exception {
mockMvc.perform(post("/api/ops/updateUseTLS")
.contentType(MediaType.APPLICATION_JSON)
.content("{}"))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value(400))
.andExpect(jsonPath("$.message").value("useTLS is required"));

verifyNoInteractions(opsService);
}
}
Loading