use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class AdminPostsControllerTests method newPostRecordContainsUpdatedCategory.
// endregion
// region Post Categories
@Test
public void newPostRecordContainsUpdatedCategory() throws Exception {
mvc.perform(solrCategoryRequest("solrCategory"));
Post post = postService.getPost("my-title-solrcategory");
assertEquals(post.getCategory().getCategoryValue().toLowerCase(), "solr");
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class AdminPostsControllerTests method updatePostWithValidData_RedirectsToPermalinkPage.
@Test
public void updatePostWithValidData_RedirectsToPermalinkPage() throws Exception {
String newTitle = "New Title for updatePostWithValidData_RedirectsToPermalinkPage Test";
Post post = postService.getPostById(1L);
RequestBuilder request = post("/admin/posts/update").param("postId", "1").param("displayType", String.valueOf(post.getDisplayType())).param("postContent", post.getPostContent()).param("twitterCardType", post.getPostMeta().getTwitterCardType().name()).param("postTitle", newTitle).param("tags", "updatePostWithValidData1, updatePostWithValidData2").with(csrf());
mvc.perform(request).andExpect(model().hasNoErrors()).andExpect(MockMvcResultMatchers.flash().attributeExists("feedbackMessage")).andExpect(redirectedUrl("/admin/posts"));
Post updatedPost = postService.getPostById(1L);
assert (updatedPost.getPostTitle().equals(newTitle));
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class AdminPostsControllerTests method newPostWithTwitterCardTypeNoneIsSaved.
@Test
public void newPostWithTwitterCardTypeNoneIsSaved() throws Exception {
mvc.perform(addTwitterCardPostRequest("notwitter", TwitterCardType.NONE, PostDisplayType.POST));
Post post = postService.getPost("my-title-notwitter");
assertEquals(post.getPostMeta().getTwitterCardType(), TwitterCardType.NONE);
PostMeta postMeta = postService.getPostMetaById(post.getPostId());
assertNotNull(postMeta);
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class AdminPostsController method isDuplicatePost.
private Boolean isDuplicatePost(PostDTO postDTO, Post sessionPost) {
Boolean isDuplicate = false;
if (StringUtils.isNotEmpty(postDTO.getPostTitle())) {
String slug = PostUtils.createSlug(postDTO.getPostTitle());
Post found = null;
try {
found = postService.getPost(slug);
} catch (PostNotFoundException e) {
// can be null for this check of a pre-existing post
}
if (sessionPost != null) {
if (found != null && !(found.getPostId().equals(sessionPost.getPostId()))) {
isDuplicate = true;
}
} else {
if (found != null)
isDuplicate = true;
}
}
return isDuplicate;
}
use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.
the class AdminPostsController method updatePost.
// endregion
// region Update Posts GET POST
@RequestMapping(value = "/update/{postId}", method = GET)
public String updatePost(@PathVariable("postId") Long postId, Model model, HttpServletRequest request) throws PostNotFoundException {
Post post = postService.getPostById(postId);
String postType = StringUtils.capitalize(post.getPostType().name().toLowerCase());
String pageTitle = webUI.getMessage(MESSAGE_ADMIN_UPDATE_POSTLINK_TITLE, postType);
String pageHeading = webUI.getMessage(MESSAGE_ADMIN_UPDATE_POSTLINK_HEADING, postType);
PostDTO postDTO = getUpdatedPostDTO(post);
if (post.getPostType() == PostType.LINK) {
postDTO.setHasImages(post.getPostImage() != null);
postDTO.setPostImage(post.getPostImage());
if (postDTO.getHasImages()) {
model.addAttribute("hasLinkImage", true);
}
}
model.addAttribute("postName", post.getPostName());
model.addAttribute("postDTO", postDTO);
model.addAttribute("pageTitle", pageTitle);
model.addAttribute("pageHeading", pageHeading);
model.addAttribute("categories", postService.getAdminSelectionCategories());
model.addAllAttributes(getPostLinkAttributes(request, post.getPostType()));
return ADMIN_POSTLINK_UPDATE_VIEW;
}
Aggregations