DatabaseController { @RequestMapping(value = "/syncdb") public ServiceResult<String> syncdb(@Validated(AddDataBase.class) @RequestBody DataBaseInfo dataBaseInfo, @CurrentUser LoginUser user, Errors errors) throws Exception { DasGroup dasGroup = groupDao.getGroupByName(dataBaseInfo.getGroup_name()); if (dasGroup == null) { return ServiceResult.fail("请先同步组！" + dataBaseInfo.getGroup_name()); } dataBaseInfo.setDal_group_id(dasGroup.getId()); return addDataBase(dataBaseInfo, user, errors); }  @RequestMapping(value = "/list", method = RequestMethod.POST) ServiceResult<ListResult<DataBaseView>> list(@RequestBody Paging<DataBaseInfo> paging, @CurrentUser LoginUser loginUser); @RequestMapping(value = "/page/list", method = RequestMethod.POST) ServiceResult<ListResult<DataBaseView>> getDBListByGroupId(@RequestBody Paging<DataBaseInfo> paging, @CurrentUser LoginUser loginUser); @RequestMapping(value = "/connectionTest", method = RequestMethod.POST) ServiceResult connectionTest(@RequestBody ConnectionRequest connectionRequest); @RequestMapping(value = "/getTableAttributes") ServiceResult getTableAttributes(@RequestParam(value = "id", defaultValue = "0") Long id, @RequestParam(value = "name", defaultValue = "") String name); @RequestMapping(value = "/isExist", method = RequestMethod.POST) ServiceResult isExist(@RequestBody List<String> db_names); @RequestMapping(value = "/dbs") ServiceResult<List<DataBaseInfo>> getUsers(@RequestParam(value = "name", defaultValue = "") String name, @RequestParam(value = "groupId", defaultValue = "") Long groupId); @RequestMapping(value = "/add", method = RequestMethod.POST) ServiceResult<String> add(@RequestBody DataBaseInfo dataBaseInfo, @CurrentUser LoginUser user, Errors errors); @RequestMapping(value = "/addDbs", method = RequestMethod.POST) ServiceResult<String> addDbs(@RequestBody List<DataBaseInfo> list, @CurrentUser LoginUser user, Errors errors); @RequestMapping(value = "/update", method = RequestMethod.PUT) ServiceResult<String> update(@Validated(UpdateDataBase.class) @RequestBody DataBaseInfo dataBaseInfo, @CurrentUser LoginUser user, Errors errors); @RequestMapping(value = "/delete", method = RequestMethod.DELETE) ServiceResult<String> delete(@Validated(DeleteDataBase.class) @RequestBody DataBaseInfo dataBaseInfo, @CurrentUser LoginUser user, Errors errors); @RequestMapping(value = "/catalogs") ServiceResult<List<String>> getDBCatalogs(@RequestParam("dbset_id") Long dbsetId); @RequestMapping(value = "/catalogsByDbId") ServiceResult<List<String>> getDBCatalogsByDbId(@RequestParam("dbId") Long dbId); @RequestMapping(value = "/sqlValidate", method = RequestMethod.POST) ServiceResult validateSQL(@RequestBody SqlValidateRequest sqlValidateRequest); @RequestMapping(value = "/sync") ServiceResult<String> sync(@RequestParam("id") Long id, @CurrentUser LoginUser user); @RequestMapping(value = "/getdbnames") ServiceResult<String> getdbnames(@RequestParam("appid") String appid); @RequestMapping(value = "/check") ConfigCkeckResult check(@RequestParam("id") Long id, @CurrentUser LoginUser user); @RequestMapping(value = "/syncdb") ServiceResult<String> syncdb(@Validated(AddDataBase.class) @RequestBody DataBaseInfo dataBaseInfo, @CurrentUser LoginUser user, Errors errors); @RequestMapping("/buttons") ServiceResult getDataBaseButton(@CurrentUser LoginUser user);  }
@Test public void syncdb() throws Exception { String requestJson = JSONObject.toJSONString(DataBaseInfo.builder().id(1L).dbname("name").build()); mockMvc.perform(MockMvcRequestBuilders.post("/db/syncdb") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(requestJson) .accept(MediaType.APPLICATION_JSON_UTF8)) .andExpect(MockMvcResultMatchers.status().isOk()) .andDo(MockMvcResultHandlers.print()); }