Search in sources :

Example 1 with Category

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

the class AdminPostsController method addCategory.

@RequestMapping(value = "/categories/new", method = RequestMethod.POST)
public String addCategory(@Valid CategoryDTO categoryDTO, BindingResult result, SessionStatus status, RedirectAttributes attributes) {
    if (result.hasErrors()) {
        return ADMIN_CATEGORIES_VIEW;
    } else {
        Category category = postService.createCategory(categoryDTO);
        logger.info("Category Added: {}", category.getCategoryValue());
        status.setComplete();
        webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_CATEGORY_ADDED, category.getCategoryValue());
        return "redirect:/admin/posts/categories";
    }
}
Also used : Category(com.nixmash.blog.jpa.model.Category)

Example 2 with Category

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

the class AdminPostsControllerTests method updateCategoryTests.

@Test
public void updateCategoryTests() throws Exception {
    // H2Data VALUES (4, 'PHP', 0, 0);
    Category category = postService.getCategory("PHP");
    mvc.perform(updateCategoryRequest(category.getCategoryId(), "NOPE", true, true)).andExpect(redirectedUrl("/admin/posts/categories"));
    Category updated = postService.getCategory("nope");
    assertEquals(category.getCategoryId(), updated.getCategoryId());
    assertEquals(category.getIsDefault(), true);
}
Also used : Category(com.nixmash.blog.jpa.model.Category) Test(org.junit.Test)

Example 3 with Category

use of com.nixmash.blog.jpa.model.Category 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 4 with Category

use of com.nixmash.blog.jpa.model.Category 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 5 with Category

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

Aggregations

Category (com.nixmash.blog.jpa.model.Category)9 Test (org.junit.Test)6 CategoryDTO (com.nixmash.blog.jpa.dto.CategoryDTO)5 PostDTO (com.nixmash.blog.jpa.dto.PostDTO)1 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