Search in sources :

Example 16 with Post

use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.

the class FmServiceTests method noneTwitterTypeTemplateIsNull.

@Test
public void noneTwitterTypeTemplateIsNull() throws PostNotFoundException {
    // H2 POST 9L is twitterCardType=NONE
    // postService.buildTwitterMetaTagsForDisplay(post) returns NULL PostMeta object
    Post post = postService.getPostById(9L);
    PostMeta postMeta = postService.buildTwitterMetaTagsForDisplay(post);
    assertNull(postMeta);
}
Also used : PostMeta(com.nixmash.blog.jpa.model.PostMeta) Post(com.nixmash.blog.jpa.model.Post) Test(org.junit.Test)

Example 17 with Post

use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.

the class FmServiceTests method twitterSummaryTemplate.

@Test
public void twitterSummaryTemplate() throws PostNotFoundException {
    Post post = postService.getPostById(1L);
    PostMeta postMeta = postService.buildTwitterMetaTagsForDisplay(post);
    String result = fmService.getTwitterTemplate(postMeta);
    assertThat(result, containsString("summary"));
}
Also used : PostMeta(com.nixmash.blog.jpa.model.PostMeta) Post(com.nixmash.blog.jpa.model.Post) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 18 with Post

use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.

the class PostServiceTests method unpublishedPost_ShouldNotBeReturned_InFindAll.

@Test
public void unpublishedPost_ShouldNotBeReturned_InFindAll() throws DuplicatePostNameException {
    PostDTO postDTO = PostTestUtils.createPostDTO(2);
    postDTO.setIsPublished(false);
    Post post = postService.add(postDTO);
    long postId = post.getPostId();
    assertThat(postId, greaterThan(1L));
    List<Post> posts = postService.getAllPublishedPosts();
    Optional<Post> unpublishedPost;
    unpublishedPost = posts.stream().filter(p -> p.getPostId().equals(post.getPostId())).findFirst();
    assertFalse(unpublishedPost.isPresent());
    List<Post> allposts = postService.getAllPosts();
    unpublishedPost = allposts.stream().filter(p -> p.getPostId().equals(post.getPostId())).findFirst();
    assertTrue(unpublishedPost.isPresent());
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostUtils.postDtoToPost(com.nixmash.blog.jpa.utils.PostUtils.postDtoToPost) PostDTO(com.nixmash.blog.jpa.dto.PostDTO) Test(org.junit.Test)

Example 19 with Post

use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.

the class PostServiceTests method updatePostDTO.

@Test
public void updatePostDTO() throws PostNotFoundException {
    Post post = postService.getPostById(1L);
    PostDTO postDTO = PostUtils.postToPostDTO(post);
    String newTitle = "New Title 897";
    postDTO.setPostTitle(newTitle);
    Post update = postService.update(postDTO);
    assertEquals(update.getPostTitle(), newTitle);
    // PostName does not change...yet
    assertEquals(update.getPostName(), PostUtils.createSlug(post.getPostName()));
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostUtils.postDtoToPost(com.nixmash.blog.jpa.utils.PostUtils.postDtoToPost) PostDTO(com.nixmash.blog.jpa.dto.PostDTO) Test(org.junit.Test)

Example 20 with Post

use of com.nixmash.blog.jpa.model.Post in project nixmash-blog by mintster.

the class PostServiceTests method pagedLikedPostsTest.

@Test
public void pagedLikedPostsTest() {
    List<Post> posts = postService.getPagedLikedPosts(3, 0, 2);
    // list contains 2 posts
    assertEquals(posts.size(), 2);
    ZonedDateTime firstPostDate = posts.get(0).getPostDate();
    ZonedDateTime secondPostDate = posts.get(1).getPostDate();
    // first PostDate is higher (more recent) than second PostDate [sort: postDate: DESC]
    assertTrue(firstPostDate.compareTo(secondPostDate) > 0);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Post(com.nixmash.blog.jpa.model.Post) PostUtils.postDtoToPost(com.nixmash.blog.jpa.utils.PostUtils.postDtoToPost) Test(org.junit.Test)

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