Beispiel #1
0
 public void testImportXML() throws Exception {
   Category cat = createCategory(getId(Utils.CATEGORY));
   forumService_.saveCategory(cat, true);
   cat = forumService_.getCategory(cat.getId());
   String pathNode = cat.getPath();
   assertEquals(
       "Before import data, category don't have any forum",
       forumService_.getForums(cat.getId(), "").size(),
       0);
   try {
     File file =
         new File(System.getProperty("user.dir") + "/src/test/resources/conf/portal/Data.xml");
     String content = FileUtils.readFileToString(file, "UTF-8");
     byte currentXMLBytes[] = content.getBytes();
     ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(currentXMLBytes);
     // Import forum into category
     forumService_.importXML(
         pathNode, byteArrayInputStream, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
     assertEquals(
         "Can't import forum into category", forumService_.getForums(cat.getId(), "").size(), 1);
   } catch (IOException e) {
     log.debug("Failed to test importXML", e);
   }
 }
Beispiel #2
0
  public void testForum() throws Exception {
    String catId = getId(Utils.CATEGORY);
    Category cat = createCategory(catId);
    // create new category
    forumService_.saveCategory(cat, true);

    // create new forum
    Forum forum = createdForum();
    String forumId = forum.getId();

    // add forum
    forumService_.saveForum(catId, forum, true);

    // getForum
    forum = forumService_.getForum(catId, forumId);
    assertNotNull("Forum is null", forum);

    // getList Forum
    // Created 5 new forum, we have total 6 forum.
    List<Forum> forums = new ArrayList<Forum>();
    for (int i = 0; i < 5; i++) {
      forumService_.saveForum(cat.getId(), createdForum(), true);
    }
    forums.addAll(forumService_.getForums(catId, ""));

    // check size of list forum
    assertEquals("List forums size not equals 6", forums.size(), 6);

    // update Forum
    forum.setForumName("Forum update");
    forumService_.saveForum(catId, forum, false);
    assertEquals(forum.getForumName(), forumService_.getForum(catId, forumId).getForumName());

    // modifyForum
    forum.setIsLock(true);
    forumService_.modifyForum(forum, 2);
    forum = forumService_.getForum(catId, forumId);
    assertEquals(forum.getIsLock(), true);

    // saveModerateOfForum
    List<String> list = new ArrayList<String>();
    list.add(catId + "/" + forum.getId());
    forumService_.saveModerateOfForums(list, "demo", false);
    forum = forumService_.getForum(catId, forumId);
    list.clear();
    list.addAll(Arrays.asList(forum.getModerators()));
    assertEquals(list.contains("demo"), true);

    // test moderator of category.
    cat.setModerators(new String[] {"admin", "john"});
    forumService_.saveCategory(cat, false);
    forum = forumService_.getForum(catId, forumId);
    list.clear();
    list.addAll(Arrays.asList(forum.getModerators()));
    // assertEquals("Forum in category can not content moderatort user admin",
    // list.contains("admin"), true);

    // test moveForum, Move list Forum from Category 'cat' to Category 'cate'

    // create new Category
    Category cate = createCategory(getId(Utils.CATEGORY));
    forumService_.saveCategory(cate, true);
    Category cateNew = forumService_.getCategory(cate.getId());

    // move forum
    forumService_.moveForum(forums, cateNew.getPath());

    // get forum in new category
    forum = forumService_.getForum(cate.getId(), forumId);
    assertNotNull(forum);

    // remove Forum and return this Forum
    for (Forum forum2 : forums) {
      forumService_.removeForum(cate.getId(), forum2.getId());
    }

    // check remove
    forums = forumService_.getForumSummaries(catId, "");
    assertEquals("List forums can not equals 0", forums.size(), 0);
  }