PageRenderTime 24ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/ShowMeTheBestReply/test/integration/NewsTests.groovy

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