Package com.jdkcn.myblog.domain

Examples of com.jdkcn.myblog.domain.Category


      if (category.getOrder() == null) {
        category.setOrder(getMaxOrder(parentId) + 1);
      }
      category.setCount(0);
    }
    Category exist = getByName(category.getName(), parentId);
    if (exist != null && !StringUtils.equals(category.getId(), exist.getId())) {
      throw new DuplicateException("category in parentId[" + parentId + "] duplicate with name:" + category.getName());
    }
    Category savedCategory = entityManagerProvider.get().merge(category);
    if (category.getParent() != null) {
      category.getParent().getChildren().add(savedCategory);
    }
    return savedCategory;
  }
View Full Code Here


    categoryService = injector.getInstance(CategoryService.class);
  }

  @Test
  public void testSaveOrUpdate() throws Exception {
    Category category1 = new Category();
    category1.setType(Type.ENTRY);
    category1.setName("Programming");
    category1 = categoryService.saveOrUpdate(category1);

    Category category2 = new Category();
    category2.setName("Java");
    category2.setType(Type.ENTRY);
    category2.setParent(category1);

    categoryService.saveOrUpdate(category2);

    Category javaCategory = categoryService.getByName("Java", category1.getId());

    assertEquals("Java", javaCategory.getName());
    assertEquals("Programming", javaCategory.getParent().getName());

    assertNotNull(javaCategory.getParent());

    assertEquals("Programming", categoryService.getByName("Programming", null).getName());

    Category proCate = categoryService.get(category1.getId());
    assertEquals(1, proCate.getChildren().size());
  }
View Full Code Here

    myblogInitializer.checkInit();
    message = "Welcome to myblog 2.0";
    blog = new Blog();
    blog.setName("Myblog 2.0");
    blog.setTheme("prototype");
    Category exist = categoryService.getByName("Test Entry Category", null);
    if (exist == null) {
      exist = new Category("Test Entry Category", Type.ENTRY);
      categoryService.saveOrUpdate(exist);
    }
    categoryService.getRoots(Type.ENTRY);
  }
View Full Code Here

    assertEquals(1, proCate.getChildren().size());
  }

  @Test
  public void testCategoryOrder() throws Exception {
    Category category1 = new Category();
    category1.setType(Type.ENTRY);
    category1.setName("Programming");
    category1 = categoryService.saveOrUpdate(category1);

    Category category2 = new Category();
    category2.setName("Java");
    category2.setType(Type.ENTRY);
    category2.setParent(category1);
    categoryService.saveOrUpdate(category2);

    Category category3 = new Category();
    category3.setName("Python");
    category3.setType(Type.ENTRY);
    category3.setParent(category1);
    categoryService.saveOrUpdate(category3);

    assertEquals(1, category2.getOrder().intValue());
    assertEquals(2, category3.getOrder().intValue());
  }
View Full Code Here

    assertEquals(2, category3.getOrder().intValue());
  }

  @Test
  public void testChildren() throws Exception {
    Category category1 = new Category();
    category1.setType(Type.ENTRY);
    category1.setName("Programming");
    category1 = categoryService.saveOrUpdate(category1);

    Category category2 = new Category();
    category2.setName("Java");
    category2.setType(Type.ENTRY);
    category2.setParent(category1);
    categoryService.saveOrUpdate(category2);

    Category category3 = new Category();
    category3.setName("Python");
    category3.setType(Type.ENTRY);
    category3.setParent(category1);
    categoryService.saveOrUpdate(category3);

    Category programmingCategory = categoryService.getByName("Programming", null);
    assertNotNull(programmingCategory);
    assertEquals(2, programmingCategory.getChildren().size());
  }
View Full Code Here

    assertEquals(2, programmingCategory.getChildren().size());
  }
 
  @Test(expected = DuplicateException.class)
  public void testDuplicate() throws Exception {
    Category category1 = new Category();
    category1.setType(Type.ENTRY);
    category1.setName("Programming");
    category1 = categoryService.saveOrUpdate(category1);

    Category category2 = new Category();
    category2.setName("Java");
    category2.setType(Type.ENTRY);
    category2.setParent(category1);
    categoryService.saveOrUpdate(category2);

    Category category3 = new Category();
    category3.setName("Java");
    category3.setType(Type.ENTRY);
    category3.setParent(category1);
    categoryService.saveOrUpdate(category3);
   
  }
View Full Code Here

   
  }
 
  @Test
  public void testNotDuplicate() throws Exception {
    Category category1 = new Category();
    category1.setType(Type.ENTRY);
    category1.setName("Programming");
    category1 = categoryService.saveOrUpdate(category1);
   
    Category category2 = new Category();
    category2.setName("Java");
    category2.setType(Type.ENTRY);
    category2.setParent(category1);
    categoryService.saveOrUpdate(category2);
   
    Category category3 = new Category();
    category3.setName("Programming");
    category3.setType(Type.ENTRY);
    category3.setParent(category1);
    category3 = categoryService.saveOrUpdate(category3);
   
    String categoryId = category3.getId();
    Category updateCategory = categoryService.get(categoryId);
    updateCategory.setDescription("New Description");
    categoryService.saveOrUpdate(updateCategory);
  }
View Full Code Here

 
 
 
  @Test(expected = DuplicateException.class)
  public void testDuplicate2() throws Exception {
    Category category1 = new Category();
    category1.setType(Type.ENTRY);
    category1.setName("Programming");
    category1 = categoryService.saveOrUpdate(category1);
   
    Category category2 = new Category();
    category2.setType(Type.ENTRY);
    category2.setName("Programming");
    category2 = categoryService.saveOrUpdate(category2);
   
  }
View Full Code Here

TOP

Related Classes of com.jdkcn.myblog.domain.Category

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.