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";
}
}
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);
}
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));
}
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;
}
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");
}
Aggregations