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.common.domain.Result;
import com.rocketmq.studio.common.domain.enums.InstanceType;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -28,7 +29,6 @@
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/instances")
Expand All @@ -55,8 +55,8 @@ public Result<InstanceVO> updateInstance(@RequestBody InstanceVO instance) {
}

@PostMapping("/delete")
public Result<Void> deleteInstance(@RequestBody Map<String, String> body) {
instanceService.deleteInstance(body.get("id"));
public Result<Void> deleteInstance(@Valid @RequestBody InstanceDeleteRequestDTO request) {
instanceService.deleteInstance(request.getId());
return Result.ok();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.rocketmq.studio.instance;

import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class InstanceDeleteRequestDTO {
@NotBlank(message = "id is required")
private String id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doNothing;
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 @@ -175,6 +176,30 @@ void deleteInstanceShouldReturnSuccess() throws Exception {
verify(instanceService).deleteInstance("inst-1");
}

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

verifyNoInteractions(instanceService);
}

@Test
void deleteInstanceShouldRejectMissingId() throws Exception {
mockMvc.perform(post("/api/instances/delete")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(Map.of())))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.code").value(400))
.andExpect(jsonPath("$.message").value("id is required"));

verifyNoInteractions(instanceService);
}

private InstanceVO buildInstance(String id, String name, InstanceType type, String endpoint) {
InstanceVO instance = InstanceVO.builder()
.name(name)
Expand Down
Loading