@PostMapping("")
    @RequiresPermissions("system:plugin:add")
    public ShenyuAdminResult createPlugin(@Valid @ModelAttribute final PluginDTO pluginDTO) {
        return ShenyuAdminResult.success(pluginService.createOrUpdate(pluginDTO));
    }
@Test
    public void testCreatePlugin() throws Exception {
        MockMultipartFile file = new MockMultipartFile("file", "test.jar", MediaType.TEXT_PLAIN_VALUE, "This is a test file.".getBytes());
        PluginDTO pluginDTO = new PluginDTO();
        pluginDTO.setName("test1");
        pluginDTO.setEnabled(true);
        pluginDTO.setRole("1");
        pluginDTO.setSort(100);
        pluginDTO.setFile(Base64.getEncoder().encodeToString(file.getBytes()));
        when(SpringBeanUtils.getInstance().getBean(PluginMapper.class)).thenReturn(pluginMapper);
        when(pluginMapper.existed(pluginDTO.getId())).thenReturn(false);
        given(this.pluginService.createOrUpdate(pluginDTO)).willReturn(ShenyuResultMessage.CREATE_SUCCESS);

        this.mockMvc.perform(MockMvcRequestBuilders.multipart("/plugin")
                        .param("name", pluginDTO.getName())
                        .param("enabled", String.valueOf(pluginDTO.getEnabled()))
                        .param("role", pluginDTO.getRole())
                        .param("sort", String.valueOf(pluginDTO.getSort()))
                        .param("file", pluginDTO.getFile()))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.message", is(ShenyuResultMessage.CREATE_SUCCESS)))
                .andReturn();
        // update success
        pluginDTO.setId("123");
        when(pluginMapper.existed(pluginDTO.getId())).thenReturn(true);
        given(this.pluginService.createOrUpdate(pluginDTO)).willReturn(ShenyuResultMessage.UPDATE_SUCCESS);
        this.mockMvc.perform(MockMvcRequestBuilders.multipart("/plugin")
                        .param("file", pluginDTO.getFile())
                        .param("id", pluginDTO.getId())
                        .param("name", pluginDTO.getName())
                        .param("enabled", String.valueOf(pluginDTO.getEnabled()))
                        .param("role", pluginDTO.getRole())
                        .param("sort", String.valueOf(pluginDTO.getSort())))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.message", is(ShenyuResultMessage.UPDATE_SUCCESS)))
                .andReturn();

        // update fail
        when(pluginMapper.existed(pluginDTO.getId())).thenReturn(false);
        this.mockMvc.perform(MockMvcRequestBuilders.multipart("/plugin")
                        .file(file)
                        .param("id", pluginDTO.getId())
                        .param("name", pluginDTO.getName())
                        .param("enabled", String.valueOf(pluginDTO.getEnabled()))
                        .param("role", pluginDTO.getRole())
                        .param("sort", String.valueOf(pluginDTO.getSort())))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.message", Matchers.containsString("Request error! invalid argument")))
                .andReturn();
    }