Search in sources :

Example 56 with Post

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

the class PostRepoTests method newLinkHasPostSourceDomain.

@Test
public void newLinkHasPostSourceDomain() {
    Post post = Post.getBuilder(1L, "New Link", "new-link", "http://linksource.com", "New link content!", PostType.LINK, PostDisplayType.LINK_SUMMARY).tags(getTestTags(2)).category(getTestCategory()).build();
    Post saved = postRepository.save(post);
    assertNotNull(saved);
    assertEquals(saved.getPostType(), PostType.LINK);
    // postSource is domain of url passed to builder
    assertEquals(saved.getPostSource(), "linksource.com");
}
Also used : Post(com.nixmash.blog.jpa.model.Post) Test(org.junit.Test)

Example 57 with Post

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

the class PostCachingTests method savedPostIsRetrievedFromCache.

@Test
public void savedPostIsRetrievedFromCache() throws Exception {
    String appender = "post-cache";
    PostDTO postDTO = PostTestUtils.createPostDTO(appender);
    String savedPostName = String.format("%s-%s", POST_NAME, appender);
    assertThat(postCache.get(savedPostName)).isNull();
    Post post = postService.add(postDTO);
    long postId = post.getPostId();
    String postName = post.getPostName();
    assertNull(postCache.get(post.getPostName()));
    assertNull(postCache.get(postId));
    Post postById = postService.getPostById(postId);
    Post postByName = postService.getPost(postName);
    assertThat((Post) postCache.get(postName).get()).isEqualTo(postByName);
    assertThat((Post) postCache.get(postId).get()).isEqualTo(postById);
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostDTO(com.nixmash.blog.jpa.dto.PostDTO) Test(org.junit.Test)

Example 58 with Post

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

the class PostCachingTests method validateCacheByPostId.

@Test
public void validateCacheByPostId() throws Exception {
    assertThat(postCache.get(1L)).isNull();
    Post post = postService.getPostById(1L);
    assertThat((Post) postCache.get(post.getPostId()).get()).isEqualTo(post);
}
Also used : Post(com.nixmash.blog.jpa.model.Post) Test(org.junit.Test)

Example 59 with Post

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

the class PostServiceTests method postContainsAuthorObject.

@Test
public void postContainsAuthorObject() throws Exception {
    Post post = postService.getPostById(1L);
    assertNotNull(post.author);
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostUtils.postDtoToPost(com.nixmash.blog.jpa.utils.PostUtils.postDtoToPost) Test(org.junit.Test)

Example 60 with Post

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

the class PostServiceTests method findAllWithPaging.

@Test
public void findAllWithPaging() {
    Slice<Post> posts = postService.getPosts(0, 3);
    assertEquals(posts.getSize(), 3);
    ZonedDateTime firstPostDate = posts.getContent().get(0).getPostDate();
    ZonedDateTime secondPostDate = posts.getContent().get(1).getPostDate();
    // firstPostDate is higher (more recent) than secondPostDate with [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