@Test public void create() { ArticleReq articleReq = new ArticleReq(); articleReq.setTitle("test-" + UUID.randomUUID().toString()); articleReq.setMdContent("# test title"); articleReq.setCategory("随笔"); articleReq.setTags("test,SpringMvc"); articleReq.setOpen(true); articleReq.setType(true); articleReq.setUrl("http: JSONObject jsonObject = JSONObject.fromObject(articleReq); try { mockMvc.perform(post("/admin/article/create") .content(jsonObject.toString()) .contentType("application/json")) .andExpect(status().isOk()) .andDo(result -> { assertEquals(HAVE_NOT_LOG_IN.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code) ); }); String token = userLogin(); mockMvc.perform(post("/admin/article/create") .content(jsonObject.toString()) .contentType("application/json") .header("Authorization", token)) .andExpect(status().isOk()) .andDo(result -> { assertEquals(PERMISSION_ERROR.getCode(), JSONObject.fromObject(result.getResponse().getContentAsString()).getInt(Code) ); }); token = adminLogin(); mockMvc.perform(post("/admin/article/create") .content(jsonObject.toString()) .contentType("application/json") .header("Authorization", token)) .andExpect(status().isOk()) .andDo(result -> { JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString()); assertEquals(SUCCESS.getCode(), object.getInt(Code)); ArticleModel articleModel = (ArticleModel) JSONObject.toBean(object.getJSONObject(Result), ArticleModel.class); assertNotNull(articleModel.getId()); assertNotNull(articleModel.getTitle()); assertNotNull(articleModel.getSummary()); assertNotNull(articleModel.getOriginal()); assertNotNull(articleModel.getTags()); assertNotNull(articleModel.getCategory()); assertNotNull(articleModel.getPublishDateFormat()); assertNotNull(articleModel.getMdContent()); assertNotNull(articleModel.getNextArticleId()); assertNotNull(articleModel.getNextArticleTitle()); assertNotNull(articleModel.getPreArticleId()); assertNotNull(articleModel.getPreArticleTitle()); assertNotNull(articleModel.getOpen()); assertNotNull(articleModel.getReadingNumber()); assertNotNull(articleModel.getAuthorName()); assertNotNull(articleModel.getUrl()); }); } catch (Exception e) { e.printStackTrace(); } }
@PostMapping("/admin/article/create") public Response create(@RequestBody ArticleReq body) { ArticleModel articleModel = articleService.create(body); sitemapGenerateUtil.createSitemap(); return ResponseUtil.success(articleModel); }
ArticleController { @PostMapping("/admin/article/create") public Response create(@RequestBody ArticleReq body) { ArticleModel articleModel = articleService.create(body); sitemapGenerateUtil.createSitemap(); return ResponseUtil.success(articleModel); } }
ArticleController { @PostMapping("/admin/article/create") public Response create(@RequestBody ArticleReq body) { ArticleModel articleModel = articleService.create(body); sitemapGenerateUtil.createSitemap(); return ResponseUtil.success(articleModel); }  }
ArticleController { @PostMapping("/admin/article/create") public Response create(@RequestBody ArticleReq body) { ArticleModel articleModel = articleService.create(body); sitemapGenerateUtil.createSitemap(); return ResponseUtil.success(articleModel); }  @PostMapping("/admin/article/create") Response create(@RequestBody ArticleReq body); @DeleteMapping("/admin/article/del") Response delete(@RequestParam("articleID") long articleId); @PutMapping("/admin/article/update") Response update(@RequestBody ArticleReq body); @GetMapping("/article/articleID/{articleID}") Response retrieveOneById(@PathVariable("articleID") long articleId,
                                    @RequestParam(value = "update", defaultValue = "false") boolean is4update,
                                    HttpServletRequest request); @GetMapping("/articles") Response articles(@RequestParam(name = "page", defaultValue = "1") int page,
                             @RequestParam(name = "count", defaultValue = "5") int count); @GetMapping("/admin/articles") Response adminArticles(@RequestParam(name = "page", defaultValue = "1") int page,
                                  @RequestParam(name = "count", defaultValue = "10") int count); @GetMapping("/articles/category/{name}") Response findByCategory(@PathVariable("name") String name,
                                   @RequestParam(name = "page", defaultValue = "1") int page,
                                   @RequestParam(name = "count", defaultValue = "10") int count); @GetMapping("/articles/tag/{name}") Response findByTag(@PathVariable("name") String name,
                              @RequestParam(name = "page", defaultValue = "1") int page,
                              @RequestParam(name = "count", defaultValue = "10") int count); @GetMapping("/createSitemap") Response createSitemap(); }
ArticleController { @PostMapping("/admin/article/create") public Response create(@RequestBody ArticleReq body) { ArticleModel articleModel = articleService.create(body); sitemapGenerateUtil.createSitemap(); return ResponseUtil.success(articleModel); }  @PostMapping("/admin/article/create") Response create(@RequestBody ArticleReq body); @DeleteMapping("/admin/article/del") Response delete(@RequestParam("articleID") long articleId); @PutMapping("/admin/article/update") Response update(@RequestBody ArticleReq body); @GetMapping("/article/articleID/{articleID}") Response retrieveOneById(@PathVariable("articleID") long articleId,
                                    @RequestParam(value = "update", defaultValue = "false") boolean is4update,
                                    HttpServletRequest request); @GetMapping("/articles") Response articles(@RequestParam(name = "page", defaultValue = "1") int page,
                             @RequestParam(name = "count", defaultValue = "5") int count); @GetMapping("/admin/articles") Response adminArticles(@RequestParam(name = "page", defaultValue = "1") int page,
                                  @RequestParam(name = "count", defaultValue = "10") int count); @GetMapping("/articles/category/{name}") Response findByCategory(@PathVariable("name") String name,
                                   @RequestParam(name = "page", defaultValue = "1") int page,
                                   @RequestParam(name = "count", defaultValue = "10") int count); @GetMapping("/articles/tag/{name}") Response findByTag(@PathVariable("name") String name,
                              @RequestParam(name = "page", defaultValue = "1") int page,
                              @RequestParam(name = "count", defaultValue = "10") int count); @GetMapping("/createSitemap") Response createSitemap();  }