Search in sources :

Example 1 with JsonPostDTO

use of com.nixmash.blog.mvc.dto.JsonPostDTO in project nixmash-blog by mintster.

the class AdminPostsControllerTests method saveAndContinueWithBadData_PostUnchanged.

@Test
public void saveAndContinueWithBadData_PostUnchanged() throws Exception {
    Post post = postService.getPostById(8L);
    String originalTitle = post.getPostTitle();
    JsonPostDTO jsonPostDTO = MvcTestUtil.createJsonPostDTO(post);
    jsonPostDTO.setPostTitle("saveAndContinueWithBadData_PostUnchanged");
    jsonPostDTO.setPostContent(StringUtils.EMPTY);
    logger.info(this.json.write(jsonPostDTO).getJson());
    mvc.perform(post("/admin/posts/archive").content(json.write(jsonPostDTO).getJson()).contentType(APPLICATION_JSON_UTF8).with(csrf())).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON_UTF8)).andExpect(content().string(containsString("ERROR")));
    post = postService.getPostById(8L);
    assertEquals(post.getPostTitle(), originalTitle);
}
Also used : Post(com.nixmash.blog.jpa.model.Post) JsonPostDTO(com.nixmash.blog.mvc.dto.JsonPostDTO) Test(org.junit.Test)

Example 2 with JsonPostDTO

use of com.nixmash.blog.mvc.dto.JsonPostDTO in project nixmash-blog by mintster.

the class AdminPostsControllerTests method saveAndContinueWithValidData_UpdatesPost.

@Test
public void saveAndContinueWithValidData_UpdatesPost() throws Exception {
    String newTitle = "saveAndContinueWithValidData_UpdatesPost";
    Post post = postService.getPostById(8L);
    JsonPostDTO jsonPostDTO = MvcTestUtil.createJsonPostDTO(post);
    jsonPostDTO.setPostTitle(newTitle);
    mvc.perform(post("/admin/posts/archive").content(json.write(jsonPostDTO).getJson()).contentType(APPLICATION_JSON_UTF8).with(csrf())).andExpect(content().string(containsString("SUCCESS")));
    post = postService.getPostById(8L);
    assertEquals(post.getPostTitle(), newTitle);
    File azFile = new File(azTestFileName);
    String contents = FileUtils.readFileToString(azFile);
    assertFalse(contents.contains(newTitle));
}
Also used : Post(com.nixmash.blog.jpa.model.Post) JsonPostDTO(com.nixmash.blog.mvc.dto.JsonPostDTO) File(java.io.File) Test(org.junit.Test)

Aggregations

Post (com.nixmash.blog.jpa.model.Post)2 JsonPostDTO (com.nixmash.blog.mvc.dto.JsonPostDTO)2 Test (org.junit.Test)2 File (java.io.File)1