Search in sources :

Example 6 with Post

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");
}
Also used : Post(com.nixmash.blog.jpa.model.Post) Test(org.junit.Test)

Example 7 with Post

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));
}
Also used : RequestBuilder(org.springframework.test.web.servlet.RequestBuilder) Post(com.nixmash.blog.jpa.model.Post) Test(org.junit.Test)

Example 8 with Post

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);
}
Also used : PostMeta(com.nixmash.blog.jpa.model.PostMeta) Post(com.nixmash.blog.jpa.model.Post) Test(org.junit.Test)

Example 9 with Post

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;
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostNotFoundException(com.nixmash.blog.jpa.exceptions.PostNotFoundException)

Example 10 with Post

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;
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostDTO(com.nixmash.blog.jpa.dto.PostDTO)

Aggregations

Post (com.nixmash.blog.jpa.model.Post)68 Test (org.junit.Test)48 PostUtils.postDtoToPost (com.nixmash.blog.jpa.utils.PostUtils.postDtoToPost)15 PostDTO (com.nixmash.blog.jpa.dto.PostDTO)14 PostMeta (com.nixmash.blog.jpa.model.PostMeta)8 PostDoc (com.nixmash.blog.solr.model.PostDoc)8 Matchers.containsString (org.hamcrest.Matchers.containsString)5 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)5 ArrayList (java.util.ArrayList)4 Query (org.springframework.data.solr.core.query.Query)4 SimpleQuery (org.springframework.data.solr.core.query.SimpleQuery)4 SimpleStringCriteria (org.springframework.data.solr.core.query.SimpleStringCriteria)4 ZonedDateTime (java.time.ZonedDateTime)3 Date (java.util.Date)3 Before (org.junit.Before)3 TagDTO (com.nixmash.blog.jpa.dto.TagDTO)2 PostNotFoundException (com.nixmash.blog.jpa.exceptions.PostNotFoundException)2 SiteImage (com.nixmash.blog.jpa.model.SiteImage)2 JsonPostDTO (com.nixmash.blog.mvc.dto.JsonPostDTO)2 File (java.io.File)2