Search in sources :

Example 21 with Post

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

the class PostServiceTests method updatePostWithTags.

@Test
public void updatePostWithTags() throws DuplicatePostNameException, PostNotFoundException {
    // Post(5L) is loaded with 2 tags in H2
    Post post = postService.getPostById(5L);
    PostDTO postDTO = PostUtils.postToPostDTO(post);
    postDTO.getTags().add(new TagDTO("updatePostWithTags1"));
    Post updated = postService.update(postDTO);
    assertEquals(updated.getTags().size(), 3);
    Post retrieved = postService.getPostById(5L);
    assertEquals(retrieved.getTags().size(), 3);
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostUtils.postDtoToPost(com.nixmash.blog.jpa.utils.PostUtils.postDtoToPost) TagDTO(com.nixmash.blog.jpa.dto.TagDTO) PostDTO(com.nixmash.blog.jpa.dto.PostDTO) Test(org.junit.Test)

Example 22 with Post

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

the class PostServiceTests method postDtoToPostShouldRetainPostSourceOf_NA_ForNullLink.

@Test
public void postDtoToPostShouldRetainPostSourceOf_NA_ForNullLink() {
    PostDTO postDTO = PostDTO.getBuilder(USER_ID, POST_TITLE, POST_NAME, null, POST_CONTENT, POST_TYPE, DISPLAY_TYPE, CATEGORY_ID, TWITTER_CARD_SUMMARY).build();
    assertEquals(postDTO.getPostSource(), null);
    Post post = postDtoToPost(postDTO);
    assertEquals(post.getPostSource(), null);
}
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 23 with Post

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

the class PostRepoTests method newCategoryAdded.

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

Example 24 with Post

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

the class PostRepoTests method nonextistentPostFromRepository.

@Test
public void nonextistentPostFromRepository() {
    Post post = postRepository.findByPostId(-100L);
    assertNull(post);
}
Also used : Post(com.nixmash.blog.jpa.model.Post) Test(org.junit.Test)

Example 25 with Post

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

the class PostCachingTests method updatedPostIsRetrievedFromCache.

@Test
public void updatedPostIsRetrievedFromCache() throws Exception {
    // Confirm our pagedPosts Cache is populated
    postService.getPublishedPosts(0, 10);
    assertThat(pagedPostsCache.get("0-10")).isNotNull();
    // Update Post Title and call Post Update Service
    String newTitle = "Something Wonderful";
    Post post = postService.getPostById(1L);
    String originalPostName = post.getPostName();
    PostDTO postDTO = PostUtils.postToPostDTO(post);
    postDTO.setPostTitle(newTitle);
    postService.update(postDTO);
    // Updated Post with New Title in Post Caches by Name and PostId
    // AFTER it is evicted - Updated v0.4.5
    assertNull(postCache.get(post.getPostName()));
    postService.getPost(originalPostName);
    Post postByName = (Post) postCache.get(post.getPostName()).get();
    assertThat(postByName.getPostTitle()).isEqualTo(newTitle);
    assertNull(postCache.get(post.getPostId()));
    postService.getPostById(1L);
    Post postById = (Post) postCache.get(post.getPostId()).get();
    assertThat(postById.getPostTitle()).isEqualTo(newTitle);
    // Paged Posts cache evicted on Post Update, rebuilt on next call
    assertThat(pagedPostsCache.get("0-10")).isNull();
    postService.getPublishedPosts(0, 10);
    assertThat(pagedPostsCache.get("0-10")).isNotNull();
}
Also used : Post(com.nixmash.blog.jpa.model.Post) PostDTO(com.nixmash.blog.jpa.dto.PostDTO) 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