Ejemplo n.º 1
0
  public void testTag() throws Exception {
    // set Data
    setData();
    Tag tag = createTag("Tag1");
    Tag tag2 = createTag("Tag2");
    Tag tag3 = createTag("Tag3");

    // add tag
    List<Tag> tags = new ArrayList<Tag>();
    tags.add(tag);
    tags.add(tag2);
    tags.add(tag3);
    Topic topic = forumService_.getTopic(categoryId, forumId, topicId, "");
    forumService_.addTag(tags, USER_ROOT, topic.getPath());
    // get Tags name in topic by root.
    // List<String> list = forumService_.getTagNameInTopic(USER_ROOT+","+topicId);

    // Test get tag
    String id = Utils.TAG + tag.getName();
    tag = forumService_.getTag(id);
    assertNotNull(tag);

    // Get all tag
    // assertEquals("All tags size is not 3", 3, forumService_.getAllTags().size());

  }
Ejemplo n.º 2
0
  public void testPost() throws Exception {
    // set Data
    setData();

    List<Post> posts = new ArrayList<Post>();
    for (int i = 0; i < 25; ++i) {
      Post post = createdPost();
      posts.add(post);
      forumService_.savePost(categoryId, forumId, topicId, post, true, new MessageBuilder());
    }
    // getPost
    assertNotNull(forumService_.getPost(categoryId, forumId, topicId, posts.get(0).getId()));

    // get ListPost
    JCRPageList pagePosts =
        forumService_.getPosts(categoryId, forumId, topicId, "", "", "", "root");
    assertEquals(
        pagePosts.getAvailable(), posts.size() + 1); // size = 26 (first post and new postList)
    List page1 = pagePosts.getPage(1);
    assertEquals(page1.size(), 10);
    List page3 = pagePosts.getPage(3);
    assertEquals(page3.size(), 6);
    // getPost by Ip
    JCRPageList pageIpPosts = forumService_.getListPostsByIP("192.168.1.11", null);
    assertEquals(pageIpPosts.getAvailable(), 25); // size = 25 (not content first post)
    // update Post First
    Post newPost = (Post) pagePosts.getPage(1).get(1);
    newPost.setMessage("New message");
    forumService_.savePost(categoryId, forumId, topicId, newPost, false, new MessageBuilder());
    assertEquals(
        "New message",
        forumService_.getPost(categoryId, forumId, topicId, newPost.getId()).getMessage());

    // test movePost
    Topic topicnew = createdTopic("root");
    forumService_.saveTopic(categoryId, forumId, topicnew, true, false, new MessageBuilder());
    topicnew = forumService_.getTopic(categoryId, forumId, topicnew.getId(), "root");

    forumService_.movePost(
        new String[] {newPost.getPath()}, topicnew.getPath(), false, "test mail content", "");
    assertNotNull(forumService_.getPost(categoryId, forumId, topicnew.getId(), newPost.getId()));

    // test remove Post return post
    assertNotNull(forumService_.removePost(categoryId, forumId, topicnew.getId(), newPost.getId()));
    assertNull(forumService_.getPost(categoryId, forumId, topicnew.getId(), newPost.getId()));

    // getViewPost
  }
Ejemplo n.º 3
0
  public void testTopic() throws Exception {
    Category cat = createCategory(getId(Utils.CATEGORY));
    forumService_.saveCategory(cat, true);
    Forum forum = createdForum();
    forumService_.saveForum(cat.getId(), forum, true);

    List<String> listTopicId = new ArrayList<String>();
    // add 10 Topics
    List<Topic> list = new ArrayList<Topic>();
    Topic topic;
    for (int i = 0; i < 10; i++) {
      topic = createdTopic("Owner");
      list.add(topic);
      listTopicId.add(topic.getId());
      forumService_.saveTopic(cat.getId(), forum.getId(), topic, true, false, new MessageBuilder());
    }
    topic = list.get(8);

    // get Topic - topic in position 8
    Topic topica = forumService_.getTopic(cat.getId(), forum.getId(), topic.getId(), "");
    assertNotNull(topica);

    // get Topic by path
    topica =
        forumService_.getTopicByPath(
            cat.getId() + "/" + forum.getId() + "/" + topic.getId(), false);
    assertNotNull(topica);

    // update Topic
    topica.setIsSticky(true);
    topica.setTopicName("topic 8");
    forumService_.saveTopic(cat.getId(), forum.getId(), topica, false, false, new MessageBuilder());
    assertEquals(
        "This topic name not is 'topic 8'",
        "topic 8",
        forumService_.getTopic(cat.getId(), forum.getId(), topic.getId(), "").getTopicName());

    // modifyTopic
    topica.setIsLock(true);
    list.clear();
    list.add(topica);
    forumService_.modifyTopic(list, 2);
    topica = forumService_.getTopic(cat.getId(), forum.getId(), topic.getId(), "");
    assertEquals("This topic is open.", topica.getIsLock(), true);
    // get PageList Topic
    JCRPageList pagelist = forumService_.getPageTopic(cat.getId(), forum.getId(), "", "");
    assertEquals("Available all topics not equals 10.", pagelist.getAvailable(), 10);
    pagelist.setPageSize(5);
    List<Topic> listTopic = pagelist.getPage(1);
    assertEquals("Available page not equals 5", listTopic.size(), 5);
    assertEquals(pagelist.getAvailablePage(), 2);

    // get Topic By User
    topic = createdTopic("demo");
    forumService_.saveTopic(cat.getId(), forum.getId(), topic, true, false, new MessageBuilder());
    // We have 11 topic: 10 by Owner and 1 by demo
    pagelist = forumService_.getPageTopicByUser("Owner", true, "");
    assertEquals(pagelist.getAvailable(), 10);

    // auto prune
    // set 5 topics for old
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(cal.getTimeInMillis() - 2 * 86400000);
    Node topicNode;
    for (Topic topic2 : listTopic) {
      topicNode = root_.getNode(topic2.getPath().replaceFirst("/", ""));
      topicNode.setProperty(ForumNodeTypes.EXO_LAST_POST_DATE, cal);
      topicNode.save();
    }

    listTopic = forumService_.getAllTopicsOld(1, forum.getPath());
    assertEquals(
        "Failed to run auto prune. List topic has size not equals 5.", listTopic.size(), 5);

    // move Topic
    // move topic from forum to forum 1
    Forum forum1 = createdForum();
    forumService_.saveForum(cat.getId(), forum1, true);
    forum1 = forumService_.getForum(cat.getId(), forum1.getId());
    List<Topic> topics = new ArrayList<Topic>();
    topics.add(topica);
    forumService_.moveTopic(topics, forum1.getPath(), "", "");
    assertNotNull(
        "Failed to moved topic, topic is null.",
        forumService_.getTopic(cat.getId(), forum1.getId(), topica.getId(), ""));

    // test remove Topic return Topic
    // remove id topic moved in list topicIds.
    if (listTopicId.contains(topica.getId())) listTopicId.remove(topica.getId());
    for (String topicId : listTopicId) {
      forumService_.removeTopic(cat.getId(), forum.getId(), topicId);
    }
    List<Topic> topics2 = forumService_.getTopics(cat.getId(), forum.getId());
    assertEquals(
        "Topics in forum failed to remove. List topic has size more than 1.", topics2.size(), 1);
  }