Search in sources :

Example 61 with Post

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

the class PostServiceTests method deletedCategoryIncreasesUncategorizedBySame.

@Test
public void deletedCategoryIncreasesUncategorizedBySame() throws Exception {
    // H2 "ShortTimer" category removed, existing posts assigned "uncategorized"
    int startCount = postService.getAllPostsByCategoryId(1L).size();
    List<Post> posts = postService.getAllPostsByCategoryId(6L);
    int postCount = posts.size();
    postService.deleteCategory(new CategoryDTO(6L, "shorttimer", 1, true, false), posts);
    int endCount = postService.getAllPostsByCategoryId(1L).size();
    assertEquals(endCount, startCount + postCount);
}
Also used : CategoryDTO(com.nixmash.blog.jpa.dto.CategoryDTO) Post(com.nixmash.blog.jpa.model.Post) PostUtils.postDtoToPost(com.nixmash.blog.jpa.utils.PostUtils.postDtoToPost) Test(org.junit.Test)

Example 62 with Post

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

the class PostServiceTests method addPostDTO.

// region Posts
@Test
public void addPostDTO() throws DuplicatePostNameException {
    PostDTO postDTO = PostTestUtils.createPostDTO(1);
    Post post = postService.add(postDTO);
    assertNotNull(post);
}
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 63 with Post

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

the class PostServiceTests method newPostContainsAssignedCategory.

@Test
public void newPostContainsAssignedCategory() throws DuplicatePostNameException {
    PostDTO postDTO = PostTestUtils.createPostDTO(100);
    postDTO.setCategoryId(2L);
    Post post = postService.add(postDTO);
    assertNotNull(post);
    assertNotNull(post.getCategory());
    Category category = post.getCategory();
    assertEquals(category.getCategoryValue(), "Java");
}
Also used : Category(com.nixmash.blog.jpa.model.Category) 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 64 with Post

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

the class PostServiceTests method addPostWithTags.

// endregion
// region Tags
@Test
public void addPostWithTags() throws DuplicatePostNameException, PostNotFoundException {
    PostDTO postDTO = PostTestUtils.createPostDTO(3);
    postDTO.getTags().add(new TagDTO("addPostWithTags1"));
    postDTO.getTags().add(new TagDTO("addPostWithTags2"));
    Post post = postService.add(postDTO);
    assertEquals(post.getTags().size(), 2);
    Post retrieved = postService.getPostById(post.getPostId());
    assertEquals(retrieved.getTags().size(), 2);
}
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 65 with Post

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

the class PostServiceTests method getAllPostsIsGreaterThanPagedTotal.

@Test
public void getAllPostsIsGreaterThanPagedTotal() {
    List<Post> posts = postService.getAllPosts();
    assertThat(posts.size(), Matchers.greaterThan(3));
    ZonedDateTime firstPostDate = posts.get(0).getPostDate();
    ZonedDateTime secondPostDate = posts.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