private Comment createComment(int i, UUID targetId) {
    Comment comment = new Comment();
    comment.setTargetId(targetId);
    comment.setAuthor("Pretentious Douchebag " + i);
    comment.setContent("This test sucks. 0/5 would not test again.");
    comment.setImage(bitmap);

    return comment;
  }
  public void testDeleteComment() throws Exception {
    Comment c = new Comment();
    c.setAuthor("lolcat");
    c.setContent("Can I haz ID?");
    c.setTargetId(UUID.randomUUID());
    c.setId(UUID.randomUUID());

    boolean result = es.putComment(c);
    assertTrue(es.getErrorMessage(), result);

    System.out.println("Comment ID: " + c.getId());

    result = es.deleteComment(c.getId());
    assertTrue(es.getErrorMessage(), result);
  }
Esempio n. 3
0
  private static void insertComments(SessionWrapper sessionWrapper, Post post, int numComments) {
    for (int i = 0; i < numComments; i++) {
      Comment com = new Comment();
      com.setCommenter(getCommenter());
      com.setContent(getString(1, 10));
      com.setId(getTimeUUID());
      com.setPostedOn(System.currentTimeMillis());
      com.setPostId(post.getId());
      com.setTitle(getString(1, 3));
      com.save(sessionWrapper);

      CommentVotes votes = new CommentVotes();
      votes.setCommentId(com.getId());
      votes.setDownvotes(getInt(0, 10));
      votes.setUpvotes(getInt(0, 10));
      votes.save(sessionWrapper);
    }
  }
Esempio n. 4
0
 public static BlogCommentList parse(InputStream inputStream) throws IOException, AppException {
   BlogCommentList commlist = new BlogCommentList();
   Comment comm = null;
   Reply reply = null;
   Refer refer = null;
   // 获得XmlPullParser解析器
   XmlPullParser xmlParser = Xml.newPullParser();
   try {
     xmlParser.setInput(inputStream, UTF8);
     // 获得解析到的事件类别,这里有开始文档,结束文档,开始标签,结束标签,文本等等事件。
     int evtType = xmlParser.getEventType();
     // 一直循环,直到文档结束
     while (evtType != XmlPullParser.END_DOCUMENT) {
       String tag = xmlParser.getName();
       switch (evtType) {
         case XmlPullParser.START_TAG:
           if (tag.equalsIgnoreCase("allCount")) {
             commlist.allCount = StringUtils.toInt(xmlParser.nextText(), 0);
           } else if (tag.equalsIgnoreCase("pageSize")) {
             commlist.pageSize = StringUtils.toInt(xmlParser.nextText(), 0);
           } else if (tag.equalsIgnoreCase("comment")) {
             comm = new Comment();
           } else if (comm != null) {
             if (tag.equalsIgnoreCase("id")) {
               comm.id = StringUtils.toInt(xmlParser.nextText(), 0);
             } else if (tag.equalsIgnoreCase("portrait")) {
               comm.setFace(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("author")) {
               comm.setAuthor(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("authorid")) {
               comm.setAuthorId(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase("content")) {
               comm.setContent(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("pubDate")) {
               comm.setPubDate(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("appclient")) {
               comm.setAppClient(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase("reply")) {
               reply = new Reply();
             } else if (reply != null && tag.equalsIgnoreCase("rauthor")) {
               reply.rauthor = xmlParser.nextText();
             } else if (reply != null && tag.equalsIgnoreCase("rpubDate")) {
               reply.rpubDate = xmlParser.nextText();
             } else if (reply != null && tag.equalsIgnoreCase("rcontent")) {
               reply.rcontent = xmlParser.nextText();
             } else if (tag.equalsIgnoreCase("refer")) {
               refer = new Refer();
             } else if (refer != null && tag.equalsIgnoreCase("refertitle")) {
               refer.refertitle = xmlParser.nextText();
             } else if (refer != null && tag.equalsIgnoreCase("referbody")) {
               refer.referbody = xmlParser.nextText();
             }
           }
           // 通知信息
           else if (tag.equalsIgnoreCase("notice")) {
             commlist.setNotice(new Notice());
           } else if (commlist.getNotice() != null) {
             if (tag.equalsIgnoreCase("atmeCount")) {
               commlist.getNotice().setAtmeCount(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase("msgCount")) {
               commlist.getNotice().setMsgCount(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase("reviewCount")) {
               commlist.getNotice().setReviewCount(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase("newFansCount")) {
               commlist.getNotice().setNewFansCount(StringUtils.toInt(xmlParser.nextText(), 0));
             }
           }
           break;
         case XmlPullParser.END_TAG:
           // 如果遇到标签结束,则把对象添加进集合中
           if (tag.equalsIgnoreCase("comment") && comm != null) {
             commlist.getCommentlist().add(comm);
             comm = null;
           } else if (tag.equalsIgnoreCase("reply") && comm != null && reply != null) {
             comm.getReplies().add(reply);
             reply = null;
           } else if (tag.equalsIgnoreCase("refer") && comm != null && refer != null) {
             comm.getRefers().add(refer);
             refer = null;
           }
           break;
       }
       // 如果xml没有结束,则导航到下一个节点
       evtType = xmlParser.next();
     }
   } catch (XmlPullParserException e) {
     throw AppException.xml(e);
   } finally {
     inputStream.close();
   }
   return commlist;
 }
Esempio n. 5
0
 public static BlogCommentList parse(InputStream inputStream) throws IOException, AppException {
   BlogCommentList commlist = new BlogCommentList();
   Comment comm = null;
   // Reply reply = null;
   // Refer refer = null;
   // 获得XmlPullParser解�器
   XmlPullParser xmlParser = Xml.newPullParser();
   try {
     xmlParser.setInput(inputStream, UTF8);
     // 获得解æž�到的事件类别,这里有开始文档,结æ�Ÿæ–‡æ¡£ï¼Œå¼€å§‹æ
     //  ‡ç­¾ï¼Œç»“æ�Ÿæ ‡ç­¾ï¼Œæ–‡æœ¬ç­‰ç­‰äº‹ä»¶ã€‚
     int evtType = xmlParser.getEventType();
     // 一直循环,直到文档结�
     while (evtType != XmlPullParser.END_DOCUMENT) {
       String tag = xmlParser.getName();
       switch (evtType) {
         case XmlPullParser.START_TAG:
           if (tag.equalsIgnoreCase("allCount")) {
             commlist.allCount = StringUtils.toInt(xmlParser.nextText(), 0);
           } else if (tag.equalsIgnoreCase("pageSize")) {
             commlist.pageSize = StringUtils.toInt(xmlParser.nextText(), 0);
           } else if (tag.equalsIgnoreCase("comment")) {
             comm = new Comment();
           } else if (comm != null) {
             if (tag.equalsIgnoreCase("id")) {
               comm.id = StringUtils.toInt(xmlParser.nextText(), 0);
             } else if (tag.equalsIgnoreCase("portrait")) {
               comm.setFace(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("author")) {
               comm.setAuthor(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("authorid")) {
               comm.setAuthorId(StringUtils.toInt(xmlParser.nextText(), 0));
             } else if (tag.equalsIgnoreCase("content")) {
               comm.setContent(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("pubDate")) {
               comm.setPubDate(xmlParser.nextText());
             } else if (tag.equalsIgnoreCase("appclient")) {
               comm.setAppClient(StringUtils.toInt(xmlParser.nextText(), 0));
             }
             /*
             else if(tag.equalsIgnoreCase("reply"))
             {
             	reply = new Reply();
             }
             else if(reply!=null && tag.equalsIgnoreCase("rauthor"))
             {
             	reply.rauthor = xmlParser.nextText();
             }
             else if(reply!=null && tag.equalsIgnoreCase("rpubDate"))
             {
             	reply.rpubDate = xmlParser.nextText();
             }
             else if(reply!=null && tag.equalsIgnoreCase("rcontent"))
             {
             	reply.rcontent = xmlParser.nextText();
             }
             else if(tag.equalsIgnoreCase("refer"))
             {
             	refer = new Refer();
             }
             else if(refer!=null && tag.equalsIgnoreCase("refertitle"))
             {
             	refer.refertitle = xmlParser.nextText();
             }
             else if(refer!=null && tag.equalsIgnoreCase("referbody"))
             {
             	refer.referbody = xmlParser.nextText();
             }
             */
           }
           /*
                 //通知信�
                 else if(tag.equalsIgnoreCase("notice"))
           {
                 	commlist.setNotice(new Notice());
           }
                 else if(commlist.getNotice() != null)
           {
           	if(tag.equalsIgnoreCase("atmeCount"))
                  {
           		commlist.getNotice().setAtmeCount(StringUtils.toInt(xmlParser.nextText(),0));
                  }
                  else if(tag.equalsIgnoreCase("msgCount"))
                  {
                  	commlist.getNotice().setMsgCount(StringUtils.toInt(xmlParser.nextText(),0));
                  }
                  else if(tag.equalsIgnoreCase("reviewCount"))
                  {
                  	commlist.getNotice().setReviewCount(StringUtils.toInt(xmlParser.nextText(),0));
                  }
                  else if(tag.equalsIgnoreCase("newFansCount"))
                  {
                  	commlist.getNotice().setNewFansCount(StringUtils.toInt(xmlParser.nextText(),0));
                  }
           }
           */
           break;
         case XmlPullParser.END_TAG:
           // 如果�到标签结�,则把对象添加进集�中
           if (tag.equalsIgnoreCase("comment") && comm != null) {
             commlist.getCommentlist().add(comm);
             comm = null;
           }
           /*
           else if (tag.equalsIgnoreCase("reply") && comm!=null && reply!=null) {
           	comm.getReplies().add(reply);
           	reply = null;
           }
           else if(tag.equalsIgnoreCase("refer") && comm!=null && refer!=null) {
           	comm.getRefers().add(refer);
           	refer = null;
           }
           */
           break;
       }
       // 如果xml没有结�,则导航到下一个节点
       evtType = xmlParser.next();
     }
   } catch (XmlPullParserException e) {
     throw AppException.xml(e);
   } finally {
     inputStream.close();
   }
   return commlist;
 }