@Test public void updateOne() throws Exception { Category category = categoryMapper.getLastestCategory(); String name = UUID.randomUUID().toString().substring(0, 4); mockMvc.perform(put("/admin/category/update?id=" + category.getId() + "&name=" + name)).andExpect(status().isOk()) .andDo(result -> { assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)); }); String token = userLogin(); mockMvc.perform(put("/admin/category/update?id=" + category.getId() + "&name=" + name) .header("Authorization", token)) .andExpect(status().isOk()) .andDo(result -> { assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code)); }); token = adminLogin(); mockMvc.perform(put("/admin/category/update?id=" + category.getId() + "&name=" + name) .header("Authorization", token)) .andExpect(status().isOk()) .andDo(result -> { JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString()); assertEquals(SUCCESS.getCode(), object.getInt(Code)); Category c = (Category) JSONObject.toBean(object.getJSONObject(Result), Category.class); assertEquals(name, c.getName()); assertNotNull(c.getArticles()); assertNotNull(c.getId()); }); }
@PutMapping("/admin/category/update") public Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name) { return ResponseUtil.success(categoryService.update(id, name)); }
CategoryController { @PutMapping("/admin/category/update") public Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name) { return ResponseUtil.success(categoryService.update(id, name)); } }
CategoryController { @PutMapping("/admin/category/update") public Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name) { return ResponseUtil.success(categoryService.update(id, name)); }  }
CategoryController { @PutMapping("/admin/category/update") public Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name) { return ResponseUtil.success(categoryService.update(id, name)); }  @PostMapping("/admin/category/create") Response addOne(@RequestParam("name") String name); @DeleteMapping("/admin/category/del") Response deleteOne(@RequestParam("id") long id); @PutMapping("/admin/category/update") Response updateOne(@RequestParam("id") Long id,
                              @RequestParam("name") String name); @GetMapping("/categories") Response getPage(); }
CategoryController { @PutMapping("/admin/category/update") public Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name) { return ResponseUtil.success(categoryService.update(id, name)); }  @PostMapping("/admin/category/create") Response addOne(@RequestParam("name") String name); @DeleteMapping("/admin/category/del") Response deleteOne(@RequestParam("id") long id); @PutMapping("/admin/category/update") Response updateOne(@RequestParam("id") Long id,
                              @RequestParam("name") String name); @GetMapping("/categories") Response getPage();  }