//package com.bonus.sharedstation.app.controller;
//
//import com.alibaba.nacos.common.http.param.MediaType;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.bonus.common.core.web.domain.AjaxResult;
//import com.bonus.sharedstation.InitHeader;
//import com.bonus.sharedstation.app.domain.CarServiceDTO;
//import com.bonus.sharedstation.app.dto.CarServiceDTO;
//import com.bonus.sharedstation.app.service.ICarServiceService;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import org.junit.jupiter.api.BeforeEach;
//import org.junit.jupiter.api.Test;
//import org.junit.jupiter.api.extension.ExtendWith;
//import org.mockito.ArgumentCaptor;
//import org.mockito.Captor;
//import org.mockito.junit.jupiter.MockitoExtension;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.boot.test.mock.mockito.MockBean;
//import org.springframework.http.HttpHeaders;
//import org.springframework.test.context.junit.jupiter.SpringExtension;
//import org.springframework.test.web.servlet.MockMvc;
//import org.springframework.test.web.servlet.MvcResult;
//import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
//import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
//
//import javax.annotation.Resource;
//
//import static org.junit.jupiter.api.Assertions.assertEquals;
//import static org.mockito.ArgumentMatchers.any;
//import static org.mockito.Mockito.*;
//
//@SpringBootTest
//@AutoConfigureMockMvc
//@ExtendWith({SpringExtension.class, MockitoExtension.class})
//class DemoCarServiceAppControllerTest {
//
//    @MockBean
//    @Resource
//    private ICarServiceService carServiceService;
//
//    @Autowired
//    private MockMvc mockMvc;
//
//    @Captor
//    private ArgumentCaptor<CarServiceDTO> carServiceCaptor; // 捕获 CarServiceDTO 参数
//
//    @Captor
//    private ArgumentCaptor<CarServiceDTO> carServiceDTOCaptor; // 捕获 CarServiceDTO 参数
//
//    private HttpHeaders httpHeaders;
//
//    private final String BASE_URL = "/information/carservice/app";
//
//    @BeforeEach
//    public void init() {
//        InitHeader initHeader = new InitHeader();
//        httpHeaders = new HttpHeaders();
//        httpHeaders.addAll(initHeader.getHeader());
//    }
//
//    @Test
//    void add() throws Exception {
//        CarServiceDTO carService = new CarServiceDTO();
//        carService.setServiceType("车辆年检");
//        carService.setServiceDescription("2025年车辆年检，无任何问题");
//        carService.setProviderName("合肥车检中心");
//        carService.setProviderDescription("合肥指定车检中心，安全良心放心");
//        carService.setContactPhone("0557-8888888");
//        carService.setWechatQrcodeUrl("https://mp-0ff94970-f63b-4d95-afbe-cab23f55e253.cdn.bspapp.com/wechart.png");
//        carService.setLogAddress("http://220.248.250.227:49967/admin-api/system/file/0/get/c247724a9b50fb042ca3fb1c2f0fed5b35363c83609960f0c9dd7e7dc8e370a5.png");
//        carService.setColor("#fff");
//
//        ObjectMapper objectMapper = new ObjectMapper();
//        String json = objectMapper.writeValueAsString(carService);
//
//        // 模拟服务层的行为
//        when(carServiceService.insert(any(CarServiceDTO.class))).thenReturn(AjaxResult.success());
//
//        MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post(BASE_URL + "/add")
//                        .headers(httpHeaders)
//                        .contentType(MediaType.APPLICATION_JSON)
//                        .content(json))
//                .andExpect(MockMvcResultMatchers.status().isOk())
//                .andReturn();
//
//        // 验证服务层方法是否被调用
//        verify(carServiceService).insert(carServiceCaptor.capture());
//        CarServiceDTO capturedCarService = carServiceCaptor.getValue();
//        assertEquals("车辆年检", capturedCarService.getServiceType());
//        assertEquals("0557-8888888", capturedCarService.getContactPhone());
//
//        String content = mvcResult.getResponse().getContentAsString();
//        System.out.println(content);
//    }
//
//    @Test
//    void deleteById() throws Exception {
//        CarServiceDTO carService = new CarServiceDTO();
//        carService.setId(8);
//
//        ObjectMapper objectMapper = new ObjectMapper();
//        String json = objectMapper.writeValueAsString(carService);
//
//        // 模拟服务层的行为
//        when(carServiceService.delete(any(CarServiceDTO.class))).thenReturn(AjaxResult.success());
//
//        MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post(BASE_URL + "/delete")
//                        .headers(httpHeaders)
//                        .content(json)
//                        .contentType(MediaType.APPLICATION_JSON))
//                .andExpect(MockMvcResultMatchers.status().isOk())
//                .andReturn();
//
//        // 验证服务层方法是否被调用
//        verify(carServiceService).delete(carServiceCaptor.capture());
//        CarServiceDTO capturedCarService = carServiceCaptor.getValue();
//        assertEquals(8, capturedCarService.getId());
//
//        String content = mvcResult.getResponse().getContentAsString();
//        System.out.println(content);
//    }
//
//    @Test
//    void update() throws Exception {
//        CarServiceDTO carService = new CarServiceDTO();
//        carService.setId(8);
//        carService.setServiceType("车辆年检1");
//        carService.setServiceDescription("2025年车辆年检，无任何问题");
//        carService.setProviderName("合肥车检中心");
//        carService.setProviderDescription("合肥指定车检中心，安全良心放心");
//        carService.setContactPhone("0557-8888888");
//        carService.setWechatQrcodeUrl("https://mp-0ff94970-f63b-4d95-afbe-cab23f55e253.cdn.bspapp.com/wechart.png");
//        carService.setLogAddress("http://220.248.250.227:49967/admin-api/system/file/0/get/c247724a9b50fb042ca3fb1c2f0fed5b35363c83609960f0c9dd7e7dc8e370a5.png");
//        carService.setColor("#fff");
//
//        ObjectMapper objectMapper = new ObjectMapper();
//        String json = objectMapper.writeValueAsString(carService);
//
//        // 模拟服务层的行为
//        when(carServiceService.updateInfoById(any(CarServiceDTO.class))).thenReturn(AjaxResult.success());
//
//        MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post(BASE_URL + "/update")
//                        .headers(httpHeaders)
//                        .contentType(MediaType.APPLICATION_JSON)
//                        .content(json))
//                .andExpect(MockMvcResultMatchers.status().isOk())
//                .andReturn();
//
//        // 验证服务层方法是否被调用
//        verify(carServiceService).updateInfoById(carServiceCaptor.capture());
//        CarServiceDTO capturedCarService = carServiceCaptor.getValue();
//        assertEquals("车辆年检1", capturedCarService.getServiceType());
//        assertEquals(8, capturedCarService.getId());
//
//        String content = mvcResult.getResponse().getContentAsString();
//        System.out.println(content);
//    }
//
//    @Test
//    void getList() throws Exception {
//        CarServiceDTO dto = new CarServiceDTO();
//        dto.setCurrentPage(1);
//        dto.setLimit(10);
//        dto.setServiceType("");
//        dto.setIsDeleted("0");
//
//        ObjectMapper objectMapper = new ObjectMapper();
//        String json = objectMapper.writeValueAsString(dto);
//
//        Page<CarServiceDTO> page = new Page<>();
//        // 模拟服务层的行为
//        when(carServiceService.getListPageApp(any(CarServiceDTO.class))).thenReturn(AjaxResult.success(page));
//
//        MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post(BASE_URL + "/getList")
//                        .headers(httpHeaders)
//                        .contentType(MediaType.APPLICATION_JSON)
//                        .content(json))
//                .andExpect(MockMvcResultMatchers.status().isOk())
//                .andReturn();
//
//        // 验证服务层方法是否被调用
//        verify(carServiceService).getListPageApp(carServiceDTOCaptor.capture());
//        CarServiceDTO capturedDto = carServiceDTOCaptor.getValue();
//        assertEquals(1, capturedDto.getCurrentPage());
//        assertEquals(10, capturedDto.getLimit());
//
//        String content = mvcResult.getResponse().getContentAsString();
//        System.out.println(content);
//    }
//
//    @Test
//    void selectInfoById() throws Exception {
//        CarServiceDTO carService = new CarServiceDTO();
//        carService.setId(8);
//
//        ObjectMapper objectMapper = new ObjectMapper();
//        String json = objectMapper.writeValueAsString(carService);
//
//        // 模拟服务层的行为
//        when(carServiceService.selectInfoById(any(CarServiceDTO.class))).thenReturn(AjaxResult.success(carService));
//
//        MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post(BASE_URL + "/selectById")
//                        .headers(httpHeaders)
//                        .content(json)
//                        .contentType(MediaType.APPLICATION_JSON))
//                .andExpect(MockMvcResultMatchers.status().isOk())
//                .andReturn();
//
//        // 验证服务层方法是否被调用
//        verify(carServiceService).selectInfoById(carServiceCaptor.capture());
//        CarServiceDTO capturedCarService = carServiceCaptor.getValue();
//        assertEquals(8, capturedCarService.getId());
//
//        String content = mvcResult.getResponse().getContentAsString();
//        System.out.println(content);
//    }
//}