Search in sources :

Example 1 with CategoryDTO

use of com.nixmash.blog.jpa.dto.CategoryDTO in project nixmash-blog by mintster.

the class PostServiceTests method createCategory.

@Test
public void createCategory() {
    CategoryDTO categoryDTO = new CategoryDTO(WOW_CATEGORY_NAME);
    long categoryId = postService.createCategory(categoryDTO).getCategoryId();
    Category category = postService.getCategoryById(categoryId);
    assertTrue(category.getCategoryValue().equals(WOW_CATEGORY_NAME));
}
Also used : CategoryDTO(com.nixmash.blog.jpa.dto.CategoryDTO) Category(com.nixmash.blog.jpa.model.Category) Test(org.junit.Test)

Example 2 with CategoryDTO

use of com.nixmash.blog.jpa.dto.CategoryDTO in project nixmash-blog by mintster.

the class PostServiceTests method startCount_isEqual_to_endCount.

private boolean startCount_isEqual_to_endCount(long categoryId) {
    int startCount = postService.getAllCategories().size();
    Category category = postService.getCategoryById(categoryId);
    postService.deleteCategory(new CategoryDTO(categoryId, "something", 0, true, false), null);
    int endCount = postService.getAllCategories().size();
    return startCount == endCount;
}
Also used : CategoryDTO(com.nixmash.blog.jpa.dto.CategoryDTO) Category(com.nixmash.blog.jpa.model.Category)

Example 3 with CategoryDTO

use of com.nixmash.blog.jpa.dto.CategoryDTO in project nixmash-blog by mintster.

the class PostServiceTests method uncategorizedCategoryIsNotUpdated.

@Test
public void uncategorizedCategoryIsNotUpdated() throws Exception {
    // H2Data Status: Uncategorized is CategoryId 1
    Category uncategorized = postService.getCategoryById(1L);
    assertEquals(uncategorized.getCategoryValue(), "Uncategorized");
    Category updated = postService.updateCategory(new CategoryDTO(1L, "Categorized", 0, true, false));
    uncategorized = postService.getCategoryById(1L);
    assertEquals(uncategorized.getCategoryValue(), "Uncategorized");
}
Also used : CategoryDTO(com.nixmash.blog.jpa.dto.CategoryDTO) Category(com.nixmash.blog.jpa.model.Category) Test(org.junit.Test)

Example 4 with CategoryDTO

use of com.nixmash.blog.jpa.dto.CategoryDTO in project nixmash-blog by mintster.

the class AdminPostsController method categoryList.

// endregion
// region Categories
@RequestMapping(value = "/categories", method = GET)
public ModelAndView categoryList(Model model) {
    ModelAndView mav = new ModelAndView();
    List<CategoryDTO> categories = postService.getAdminCategories();
    mav.addObject("categories", categories);
    mav.addObject("newCategory", new Category());
    mav.setViewName(ADMIN_CATEGORIES_VIEW);
    return mav;
}
Also used : CategoryDTO(com.nixmash.blog.jpa.dto.CategoryDTO) Category(com.nixmash.blog.jpa.model.Category) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 5 with CategoryDTO

use of com.nixmash.blog.jpa.dto.CategoryDTO 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)

Aggregations

CategoryDTO (com.nixmash.blog.jpa.dto.CategoryDTO)6 Category (com.nixmash.blog.jpa.model.Category)5 Test (org.junit.Test)4 Post (com.nixmash.blog.jpa.model.Post)1 PostUtils.postDtoToPost (com.nixmash.blog.jpa.utils.PostUtils.postDtoToPost)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1