/ShowMeTheBestReply/test/integration/NewsTests.groovy

http://showmethebestreply.googlecode.com/ · Groovy · 70 lines · 51 code · 16 blank · 3 comment · 2 complexity · 26ab587ae4106cde39bc57a136dda88f MD5 · raw file

  1. import grails.test.*
  2. class NewsTests extends GrailsUnitTestCase {
  3. protected void setUp() {
  4. super.setUp()
  5. }
  6. protected void tearDown() {
  7. super.tearDown()
  8. }
  9. void testParsingRank() {
  10. String section = 'all'
  11. String date = new Date().format('yyyyMMdd').toString()
  12. Date dateParam = Date.parse('yyyyMMdd', date)
  13. def rankInfo = RankInfo.findBySectionAndDateCreatedBetween(section, new Date(dateParam.time), new Date((dateParam+1).time))
  14. if(!rankInfo) {
  15. rankInfo = RankInfo.parseRankInfo(section, date)
  16. rankInfo.save()
  17. }
  18. println "$section, $date"
  19. def sortedListOfArticleRank = rankInfo.listOfArticleRank.sort{ it.rank }
  20. sortedListOfArticleRank.each{
  21. println "$it.rank, $it.articleTitle"
  22. }
  23. }
  24. // ?? ?? ?? ???
  25. void testParsingArticle() {
  26. String articleUrl = 'http://news.nate.com/view/20091203n08304'
  27. def article = Article.parseArticle(articleUrl)
  28. println "$article.title($article.articleId, $article.url, $article.dateCreated, $article.dateModified, $article.media)"
  29. println "$article.imageLink, $article.thumbnailLink"
  30. println "$article.content"
  31. article.save()
  32. }
  33. // ?? ?? ?? ???
  34. void testParsingBestReplies() {
  35. String articleUrl = 'http://news.nate.com/view/20091203n08304'
  36. def listOfBeple = Reply.parseBestReplies(articleUrl)
  37. for(beple in listOfBeple) {
  38. println "$beple.username, $beple.content, $beple.dateCreated"
  39. beple.save()
  40. }
  41. assert Reply.count() > 0
  42. }
  43. // ?? ??? ??? ?? ???? ? ?????? ???
  44. void testArticleBestReplies() {
  45. String articleUrl = 'http://news.nate.com/view/20091203n08304'
  46. def article = Article.parseArticle(articleUrl)
  47. article.listOfBeple = Reply.parseBestReplies(articleUrl)
  48. article.save()
  49. def insertedArticle = Article.findByUrl(articleUrl)
  50. assert insertedArticle
  51. println insertedArticle
  52. insertedArticle.listOfBeple.sort{ it.countOfGood }.reverse().each{ beple -> println beple }
  53. }
  54. }