001 /* 002 * Copyright 1999,2004 The Apache Software Foundation. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.apache.commons.feedparser.test; 018 019 import java.io.BufferedReader; 020 import java.io.InputStreamReader; 021 import java.net.URL; 022 import java.net.URLConnection; 023 024 import junit.framework.TestCase; 025 026 import org.apache.commons.feedparser.FeedList; 027 import org.apache.commons.feedparser.locate.BlogServiceDiscovery; 028 import org.apache.commons.feedparser.locate.FeedLocator; 029 import org.apache.commons.feedparser.locate.FeedReference; 030 import org.apache.commons.feedparser.locate.ProbeLocator; 031 import org.apache.commons.feedparser.locate.blogservice.AOLJournal; 032 import org.apache.commons.feedparser.locate.blogservice.BlogService; 033 import org.apache.commons.feedparser.locate.blogservice.Blogger; 034 import org.apache.commons.feedparser.locate.blogservice.Blosxom; 035 import org.apache.commons.feedparser.locate.blogservice.GreyMatter; 036 import org.apache.commons.feedparser.locate.blogservice.LiveJournal; 037 import org.apache.commons.feedparser.locate.blogservice.PMachine; 038 import org.apache.commons.feedparser.locate.blogservice.RadioUserland; 039 import org.apache.commons.feedparser.locate.blogservice.TextAmerica; 040 import org.apache.commons.feedparser.locate.blogservice.TextPattern; 041 import org.apache.commons.feedparser.locate.blogservice.Typepad; 042 import org.apache.commons.feedparser.locate.blogservice.Unknown; 043 import org.apache.commons.feedparser.locate.blogservice.WordPress; 044 import org.apache.commons.feedparser.locate.blogservice.Xanga; 045 046 /** 047 * 048 * @author <a href="mailto:bkn3@columbia.edu">Brad Neuberg</a> 049 * @version $Id: TestProbeLocator.java 373622 2006-01-30 22:53:00Z mvdb $ 050 */ 051 public class TestProbeLocator extends TestCase { 052 public static boolean NO_ATOM_FEED = false; 053 public static boolean HAS_ATOM_FEED = true; 054 055 public static boolean NO_RSS_FEED = false; 056 public static boolean HAS_RSS_FEED = true; 057 058 public TestProbeLocator(String name) throws Exception { 059 super(name); 060 ProbeLocator.AGGRESIVE_PROBING_ENABLED = true; 061 ProbeLocator.BLOG_SERVICE_PROBING_ENABLED = true; 062 } 063 064 public static void main( String[] args ) throws Exception { 065 TestProbeLocator test = new TestProbeLocator( null ); 066 067 test.testBlogger(); 068 test.testLiveJournal(); 069 test.testDiaryLand(); 070 test.testMovableType(); 071 test.testXanga(); 072 test.testWordPress(); 073 test.testAOLJournal(); 074 test.testTypePad(); 075 test.testGreyMatter(); 076 test.testPMachine(); 077 //test.testBlosxom(); 078 test.testRadioUserland(); 079 test.testTextPattern(); 080 test.testTextAmerica(); 081 } 082 083 public void testBlogger() throws Exception { 084 System.out.println("\nTesting Blogger..."); 085 testSite( "http://edpro.blogspot.com/", 086 new Blogger(), 087 1, 088 new String[] { FeedReference.ATOM_MEDIA_TYPE }, 089 new String[] { "http://edpro.blogspot.com/atom.xml" }, 090 HAS_ATOM_FEED, 091 "http://edpro.blogspot.com/atom.xml", 092 NO_RSS_FEED, 093 null ); 094 095 testSite("http://carolinascl.blogspot.com/", new Blogger(), 1, 096 new String[] { FeedReference.ATOM_MEDIA_TYPE }, 097 new String[] { "http://carolinascl.blogspot.com/atom.xml" }, 098 HAS_ATOM_FEED, "http://carolinascl.blogspot.com/atom.xml", 099 NO_RSS_FEED, null); 100 101 testSite("http://azizindia.blogspot.com/", new Blogger(), 1, 102 new String[] { FeedReference.ATOM_MEDIA_TYPE }, 103 new String[] { "http://azizindia.blogspot.com/atom.xml" }, 104 HAS_ATOM_FEED, "http://azizindia.blogspot.com/atom.xml", 105 NO_RSS_FEED, null); 106 107 // This site has no blogs 108 testSite("http://davebarry.blogspot.com/", new Blogger(), 0, 109 new String[] { }, 110 new String[] { }, 111 NO_ATOM_FEED, null, 112 NO_RSS_FEED, null); 113 } 114 115 public void testLiveJournal() throws Exception { 116 System.out.println("\nTesting LiveJournal..."); 117 testSite("http://www.livejournal.com/community/indiexiankids/", 118 new LiveJournal(), 2, 119 new String[] { 120 FeedReference.ATOM_MEDIA_TYPE, 121 FeedReference.RSS_MEDIA_TYPE 122 }, 123 new String[] { 124 "http://www.livejournal.com/community/indiexiankids/data/atom", 125 "http://www.livejournal.com/community/indiexiankids/data/rss" 126 }, 127 HAS_ATOM_FEED, "http://www.livejournal.com/community/indiexiankids/data/atom", 128 HAS_RSS_FEED, "http://www.livejournal.com/community/indiexiankids/data/rss"); 129 130 testSite("http://www.livejournal.com/community/ajoyforever/", 131 new LiveJournal(), 2, 132 new String[] { 133 FeedReference.ATOM_MEDIA_TYPE, 134 FeedReference.RSS_MEDIA_TYPE 135 }, 136 new String[] { 137 "http://www.livejournal.com/community/ajoyforever/data/atom", 138 "http://www.livejournal.com/community/ajoyforever/data/rss" 139 }, 140 HAS_ATOM_FEED, "http://www.livejournal.com/community/ajoyforever/data/atom", 141 HAS_RSS_FEED, "http://www.livejournal.com/community/ajoyforever/data/rss"); 142 143 testSite("http://www.livejournal.com/users/_jb_/12332.html", 144 new LiveJournal(), 2, 145 new String[] { 146 FeedReference.ATOM_MEDIA_TYPE, 147 FeedReference.RSS_MEDIA_TYPE 148 }, 149 new String[] { 150 "http://www.livejournal.com/users/_jb_/data/atom", 151 "http://www.livejournal.com/users/_jb_/data/rss" 152 }, 153 HAS_ATOM_FEED, "http://www.livejournal.com/users/_jb_/data/atom", 154 HAS_RSS_FEED, "http://www.livejournal.com/users/_jb_/data/rss"); 155 } 156 157 public void testDiaryLand() throws Exception { 158 System.out.println("\nTesting DiaryLand... No tests currently"); 159 // FIXME: Test this 160 } 161 162 public void testMovableType() throws Exception { 163 System.out.println("\nTesting MovableType... No tests currently"); 164 // FIXME: Test this 165 } 166 167 public void testXanga() throws Exception { 168 System.out.println("\nTesting Xanga..."); 169 testSite("http://www.xanga.com/home.aspx?user=lithium98", 170 new Xanga(), 1, 171 new String[] { FeedReference.RSS_MEDIA_TYPE }, 172 new String[] { "http://www.xanga.com/rss.aspx?user=lithium98" }, 173 NO_ATOM_FEED, null, 174 HAS_RSS_FEED, "http://www.xanga.com/rss.aspx?user=lithium98"); 175 176 testSite("http://www.xanga.com/home.aspx?user=ChUnSA_86", 177 new Xanga(), 1, 178 new String[] { FeedReference.RSS_MEDIA_TYPE }, 179 new String[] { "http://www.xanga.com/rss.aspx?user=ChUnSA_86" }, 180 NO_ATOM_FEED, null, 181 HAS_RSS_FEED, "http://www.xanga.com/rss.aspx?user=ChUnSA_86"); 182 183 testSite("http://www.xanga.com/home.aspx?user=wdfphillz", 184 new Xanga(), 1, 185 new String[] { FeedReference.RSS_MEDIA_TYPE }, 186 new String[] { "http://www.xanga.com/rss.aspx?user=wdfphillz" }, 187 NO_ATOM_FEED, null, 188 HAS_RSS_FEED, "http://www.xanga.com/rss.aspx?user=wdfphillz"); 189 190 // FIXME: We should be able to pass this test when we 191 // expand resources inside of the Feed Parser; we don't 192 // currently do this yet, Brad Neuberg, bkn3@columbia.edu 193 /*testSite("http://xanga.com/home.aspx?user=joe", 194 new Xanga(), 1, 195 new String[] { FeedReference.RSS_MEDIA_TYPE }, 196 new String[] { "http://www.xanga.com/rss.aspx?user=joe" }, 197 NO_ATOM_FEED, null, 198 HAS_RSS_FEED, "http://www.xanga.com/rss.aspx?user=joe");*/ 199 } 200 201 public void testWordPress() throws Exception { 202 System.out.println("\nTesting WordPress..."); 203 // This site went down 204 /*testSite("http://zh.yazzy.org/blog/index.php", 205 new WordPress(), 3, 206 new String[] { 207 FeedReference.ATOM_MEDIA_TYPE, 208 FeedReference.RSS_MEDIA_TYPE, 209 FeedReference.RSS_MEDIA_TYPE 210 }, 211 new String[] { 212 "http://synflood.at/blog/wp-atom.php", 213 "http://synflood.at/blog/wp-rss2.php", 214 "http://synflood.at/blog/wp-rss.php" 215 }, 216 HAS_ATOM_FEED, "http://synflood.at/blog/wp-atom.php", 217 HAS_RSS_FEED, "http://synflood.at/blog/wp-rss2.php"); 218 */ 219 // We need to firm up our autodiscovery regular expressions before 220 // this will pass; what happens is it has autodiscovery, but those 221 // point to a different location than the usual ones aggresive 222 // discovery would find (which are also there). We get back different 223 // results at different times 224 /*testSite("http://zh.yazzy.org/blog/index.php", 225 new WordPress(), 3, 226 new String[] { 227 FeedReference.ATOM_MEDIA_TYPE, 228 FeedReference.RSS_MEDIA_TYPE, 229 FeedReference.RSS_MEDIA_TYPE 230 }, 231 new String[] { 232 "http://zh.yazzy.org/blog/wp-atom.php", 233 "http://zh.yazzy.org/blog/wp-rss2.php", 234 "http://zh.yazzy.org/blog/wp-rss.php" 235 }, 236 HAS_ATOM_FEED, "http://zh.yazzy.org/blog/wp-atom.php", 237 HAS_RSS_FEED, "http://zh.yazzy.org/blog/wp-rss2.php"); 238 */ 239 testSite("http://holmes.hgen.pitt.edu/~dweeks/wordpress/", 240 new WordPress(), 3, 241 new String[] { 242 FeedReference.ATOM_MEDIA_TYPE, 243 FeedReference.RSS_MEDIA_TYPE, 244 FeedReference.RSS_MEDIA_TYPE 245 }, 246 new String[] { 247 "http://holmes.hgen.pitt.edu/~dweeks/wordpress/wp-atom.php", 248 "http://holmes.hgen.pitt.edu/~dweeks/wordpress/wp-rss2.php", 249 "http://holmes.hgen.pitt.edu/~dweeks/wordpress/wp-rss.php" 250 }, 251 HAS_ATOM_FEED, "http://holmes.hgen.pitt.edu/~dweeks/wordpress/wp-atom.php", 252 HAS_RSS_FEED, "http://holmes.hgen.pitt.edu/~dweeks/wordpress/wp-rss2.php"); 253 } 254 255 public void testAOLJournal() throws Exception { 256 System.out.println("\nTesting AOL Journal..."); 257 /* AOL recently turned on experimental Atom support, but it is still 258 buggy; it turns out we can "see" it through autodiscovery but not 259 through aggresive link probing, since their server returns a 500 260 HTTP internal server error if we do a HEAD request. For this 261 reason we have to divide our testing between the probe locator 262 and feed locator because they give different results for this 263 kind of blog service currently. 264 */ 265 testProbeLocator( 266 "http://journals.aol.com/redhdka/BrandNewDay/", 267 new AOLJournal(), 1, 268 new String[] { 269 FeedReference.RSS_MEDIA_TYPE 270 }, 271 new String[] { 272 "http://journals.aol.com/redhdka/BrandNewDay/rss.xml" 273 }, 274 NO_ATOM_FEED, null, 275 HAS_RSS_FEED, "http://journals.aol.com/redhdka/BrandNewDay/rss.xml"); 276 testFeedLocator( 277 "http://journals.aol.com/redhdka/BrandNewDay/", 278 new AOLJournal(), 2, 279 new String[] { 280 FeedReference.ATOM_MEDIA_TYPE, 281 FeedReference.RSS_MEDIA_TYPE 282 }, 283 new String[] { 284 "http://journals.aol.com/redhdka/BrandNewDay/atom.xml", 285 "http://journals.aol.com/redhdka/BrandNewDay/rss.xml" 286 }, 287 HAS_ATOM_FEED, "http://journals.aol.com/redhdka/BrandNewDay/atom.xml", 288 HAS_RSS_FEED, "http://journals.aol.com/redhdka/BrandNewDay/rss.xml"); 289 290 testProbeLocator( 291 "http://journals.aol.com/goldenchildnc/GCS/", 292 new AOLJournal(), 1, 293 new String[] { 294 FeedReference.RSS_MEDIA_TYPE 295 }, 296 new String[] { 297 "http://journals.aol.com/goldenchildnc/GCS/rss.xml" 298 }, 299 NO_ATOM_FEED, null, 300 HAS_RSS_FEED, "http://journals.aol.com/goldenchildnc/GCS/rss.xml"); 301 testFeedLocator( 302 "http://journals.aol.com/goldenchildnc/GCS/", 303 new AOLJournal(), 2, 304 new String[] { 305 FeedReference.ATOM_MEDIA_TYPE, 306 FeedReference.RSS_MEDIA_TYPE 307 }, 308 new String[] { 309 "http://journals.aol.com/goldenchildnc/GCS/atom.xml", 310 "http://journals.aol.com/goldenchildnc/GCS/rss.xml" 311 }, 312 HAS_ATOM_FEED, "http://journals.aol.com/goldenchildnc/GCS/atom.xml", 313 HAS_RSS_FEED, "http://journals.aol.com/goldenchildnc/GCS/rss.xml"); 314 315 316 testProbeLocator( 317 "http://journals.aol.com/mkgninja/MelissasMisunderstandingsofLife/", 318 new AOLJournal(), 1, 319 new String[] { 320 FeedReference.RSS_MEDIA_TYPE 321 }, 322 new String[] { 323 "http://journals.aol.com/mkgninja/MelissasMisunderstandingsofLife/rss.xml" 324 }, 325 NO_ATOM_FEED, null, 326 HAS_RSS_FEED, "http://journals.aol.com/mkgninja/MelissasMisunderstandingsofLife/rss.xml"); 327 testFeedLocator( 328 "http://journals.aol.com/mkgninja/MelissasMisunderstandingsofLife/", 329 new AOLJournal(), 2, 330 new String[] { 331 FeedReference.ATOM_MEDIA_TYPE, 332 FeedReference.RSS_MEDIA_TYPE 333 }, 334 new String[] { 335 "http://journals.aol.com/mkgninja/MelissasMisunderstandingsofLife/atom.xml", 336 "http://journals.aol.com/mkgninja/MelissasMisunderstandingsofLife/rss.xml" 337 }, 338 HAS_ATOM_FEED, "http://journals.aol.com/mkgninja/MelissasMisunderstandingsofLife/atom.xml", 339 HAS_RSS_FEED, "http://journals.aol.com/mkgninja/MelissasMisunderstandingsofLife/rss.xml"); 340 } 341 342 public void testTypePad() throws Exception { 343 System.out.println("\nTesting TypePad..."); 344 // This site has no feed that we can link probe for (it's in a different 345 // location then usual). 346 // However, we get a feed when we go through the FeedParser since 347 // the site has autodiscovery 348 testSite("http://lynikers.typepad.com/", 349 new Typepad(), 0, 350 new String[] { }, 351 new String[] { }, 352 HAS_ATOM_FEED, "http://lynikers.typepad.com/on_buck_lake/atom.xml", 353 HAS_RSS_FEED, "http://lynikers.typepad.com/on_buck_lake/index.rdf"); 354 355 // This site has no feed that we can link probe for (it's in a different 356 // location then usual). 357 testSite("http://emmeke.typepad.com/", 358 new Typepad(), 0, 359 new String[] { }, 360 new String[] { }, 361 NO_ATOM_FEED, null, 362 HAS_RSS_FEED, "http://emmeke.typepad.com/blog/index.rdf"); 363 364 testSite("http://www.prettypolitical.com/", 365 new Typepad(), 2, 366 new String[] { 367 FeedReference.ATOM_MEDIA_TYPE, 368 FeedReference.RSS_MEDIA_TYPE 369 }, 370 new String[] { 371 "http://www.prettypolitical.com/atom.xml", 372 "http://www.prettypolitical.com/index.rdf" 373 }, 374 HAS_ATOM_FEED, "http://www.prettypolitical.com/atom.xml", 375 HAS_RSS_FEED, "http://www.prettypolitical.com/index.rdf"); 376 } 377 378 public void testGreyMatter() throws Exception { 379 System.out.println("\nTesting GreyMatter..."); 380 // No feeds supported 381 testSite("http://www.chattbike.com/gilligan/", 382 new GreyMatter(), 0, 383 new String[] { }, 384 new String[] { }, 385 NO_ATOM_FEED, null, 386 NO_RSS_FEED, null); 387 388 // No feeds supported 389 testSite("http://www.electricedge.com/greymatter/", 390 new GreyMatter(), 0, 391 new String[] { }, 392 new String[] { }, 393 NO_ATOM_FEED, null, 394 NO_RSS_FEED, null); 395 } 396 397 public void testPMachine() throws Exception { 398 System.out.println("\nTesting PMachine..."); 399 testSite("http://bamph.com", 400 new Unknown(), 1, 401 new String[] { FeedReference.RSS_MEDIA_TYPE }, 402 new String[] { "http://bamph.com/index.xml" }, 403 NO_ATOM_FEED, null, 404 HAS_RSS_FEED, "http://bamph.com/index.xml"); 405 406 testSite("http://bucsfishingreport.com/pMachine/weblog.php", 407 new PMachine(), 1, 408 new String[] { FeedReference.RSS_MEDIA_TYPE }, 409 new String[] { "http://bucsfishingreport.com/pMachine/index.xml" }, 410 NO_ATOM_FEED, null, 411 HAS_RSS_FEED, "http://bucsfishingreport.com/pMachine/index.xml"); 412 413 testSite("http://www.simplekindoflife.com/pMachine/weblog.php", 414 new PMachine(), 1, 415 new String[] { FeedReference.RSS_MEDIA_TYPE }, 416 new String[] { "http://www.simplekindoflife.com/pMachine/index.xml" }, 417 NO_ATOM_FEED, null, 418 HAS_RSS_FEED, "http://www.simplekindoflife.com/pMachine/index.xml"); 419 420 testSite("http://www.mondfish.net/pmachine/weblog.php", 421 new PMachine(), 1, 422 new String[] { FeedReference.RSS_MEDIA_TYPE }, 423 new String[] { "http://www.mondfish.net/pmachine/index.xml" }, 424 NO_ATOM_FEED, null, 425 HAS_RSS_FEED, "http://www.mondfish.net/pmachine/index.xml"); 426 } 427 428 public void testBlosxom() throws Exception { 429 System.out.println("\nTesting Blosxom..."); 430 testSite("http://mikemason.ca/", 431 new Blosxom(), 1, 432 new String[] { FeedReference.RSS_MEDIA_TYPE }, 433 new String[] { "http://mikemason.ca/index.rss" }, 434 NO_ATOM_FEED, null, 435 HAS_RSS_FEED, "http://mikemason.ca/index.rss"); 436 437 // Wed Mar 02 2005 06:07 PM (burton1@rojo.com): note... this no longer 438 // looks like a Bloxsom blog. It has autodiscovery though. 439 // 440 // 441 // testSite("http://www.foobargeek.com/", 442 // new Blosxom(), 1, 443 // new String[] { FeedReference.RSS_MEDIA_TYPE }, 444 // new String[] { "http://www.foobargeek.com/index.rss" }, 445 // NO_ATOM_FEED, null, 446 // HAS_RSS_FEED, "http://www.foobargeek.com/index.rss"); 447 448 // The FeedParser gets a different location for the XML file then 449 // through the aggresive prober for this feed 450 451 // testSite("http://www.pipetree.com/qmacro/", 452 // new Blosxom(), 1, 453 // new String[] { FeedReference.RSS_MEDIA_TYPE }, 454 // new String[] { "http://www.pipetree.com/qmacro/index.rss" }, 455 // NO_ATOM_FEED, null, 456 // HAS_RSS_FEED, "http://www.pipetree.com/qmacro/xml"); 457 458 testSite("http://www.bitbucketheaven.com/cgi-bin/blosxom.cgi", 459 new Blosxom(), 1, 460 new String[] { FeedReference.RSS_MEDIA_TYPE }, 461 new String[] { "http://www.bitbucketheaven.com/cgi-bin/blosxom.cgi/index.rss" }, 462 NO_ATOM_FEED, null, 463 HAS_RSS_FEED, "http://www.bitbucketheaven.com/cgi-bin/blosxom.cgi/index.rss"); 464 } 465 466 public void testRadioUserland() throws Exception { 467 System.out.println("\nTesting Radio Userland..."); 468 testSite("http://radio.weblogs.com/0131722/", 469 new RadioUserland(), 1, 470 new String[] { FeedReference.RSS_MEDIA_TYPE }, 471 new String[] { "http://radio.weblogs.com/0131722/rss.xml" }, 472 NO_ATOM_FEED, null, 473 HAS_RSS_FEED, "http://radio.weblogs.com/0131722/rss.xml"); 474 475 testSite("http://radio.weblogs.com/0131724/", 476 new RadioUserland(), 1, 477 new String[] { FeedReference.RSS_MEDIA_TYPE }, 478 new String[] { "http://radio.weblogs.com/0131724/rss.xml" }, 479 NO_ATOM_FEED, null, 480 HAS_RSS_FEED, "http://radio.weblogs.com/0131724/rss.xml"); 481 482 testSite("http://radio.weblogs.com/0131734/", 483 new RadioUserland(), 1, 484 new String[] { FeedReference.RSS_MEDIA_TYPE }, 485 new String[] { "http://radio.weblogs.com/0131734/rss.xml" }, 486 NO_ATOM_FEED, null, 487 HAS_RSS_FEED, "http://radio.weblogs.com/0131734/rss.xml"); 488 } 489 490 public void testTextPattern() throws Exception { 491 System.out.println("\nTesting TextPattern..."); 492 testSite("http://www.digitalmediaminute.com/", 493 new TextPattern(), 2, 494 new String[] { 495 FeedReference.ATOM_MEDIA_TYPE, 496 FeedReference.RSS_MEDIA_TYPE 497 }, 498 new String[] { 499 "http://www.digitalmediaminute.com/?atom=1", 500 "http://www.digitalmediaminute.com/?rss=1" 501 }, 502 HAS_ATOM_FEED, "http://www.digitalmediaminute.com/?atom=1", 503 HAS_RSS_FEED, "http://www.digitalmediaminute.com/?rss=1"); 504 } 505 506 public void testTextAmerica() throws Exception { 507 System.out.println("\nTesting TextAmerica..."); 508 testSite("http://morganwebb.textamerica.com/", 509 new TextAmerica(), 1, 510 new String[] { 511 FeedReference.RSS_MEDIA_TYPE 512 }, 513 new String[] { 514 "http://morganwebb.textamerica.com/rss.aspx" 515 }, 516 NO_ATOM_FEED, null, 517 HAS_RSS_FEED, "http://morganwebb.textamerica.com/rss.aspx"); 518 519 testSite("http://northlan.textamerica.com/", 520 new TextAmerica(), 1, 521 new String[] { 522 FeedReference.RSS_MEDIA_TYPE 523 }, 524 new String[] { 525 "http://northlan.textamerica.com/rss.aspx" 526 }, 527 NO_ATOM_FEED, null, 528 HAS_RSS_FEED, "http://northlan.textamerica.com/rss.aspx"); 529 530 testSite("http://mycamphone.textamerica.com/", 531 new TextAmerica(), 1, 532 new String[] { 533 FeedReference.RSS_MEDIA_TYPE 534 }, 535 new String[] { 536 "http://mycamphone.textamerica.com/rss.aspx" 537 }, 538 NO_ATOM_FEED, null, 539 HAS_RSS_FEED, "http://mycamphone.textamerica.com/rss.aspx"); 540 } 541 542 /** Grabs all the content for a weblog for testing purposes. */ 543 protected String getContent(String resource) throws Exception { 544 545 //FIXME: use the IO package from NewsMonster for this. 546 547 URL resourceURL = new URL(resource); 548 URLConnection con = resourceURL.openConnection(); 549 con.connect(); 550 BufferedReader in = new BufferedReader(new InputStreamReader(con 551 .getInputStream())); 552 StringBuffer results = new StringBuffer(); 553 String line = null; 554 555 while ((line = in.readLine()) != null) { 556 results.append(line); 557 } 558 559 return results.toString(); 560 } 561 562 private void testSite(String resource, BlogService correctBlogService, 563 int numberOfFeeds, String feedType[], 564 String feedURL[], boolean hasAtomFeed, 565 String atomFeedURL, boolean hasRSSFeed, 566 String rssFeedURL) throws Exception { 567 System.out.println("Testing " + resource + "..."); 568 /* Test through the probe locator */ 569 testProbeLocator(resource, correctBlogService, numberOfFeeds, 570 feedType, feedURL, hasAtomFeed, 571 atomFeedURL, hasRSSFeed, rssFeedURL); 572 573 /* Test through the FeedLocator */ 574 testFeedLocator(resource, correctBlogService, numberOfFeeds, 575 feedType, feedURL, hasAtomFeed, 576 atomFeedURL, hasRSSFeed, rssFeedURL); 577 } 578 579 private FeedList testProbeLocator(String resource, BlogService correctBlogService, 580 int numberOfFeeds, String feedType[], 581 String feedURL[], boolean hasAtomFeed, 582 String atomFeedURL, boolean hasRSSFeed, 583 String rssFeedURL) throws Exception { 584 String content = getContent(resource); 585 assertNotNull(content); 586 587 BlogService blogService = BlogServiceDiscovery.discover(resource, content); 588 assertEquals(correctBlogService, blogService); 589 590 FeedList list = new FeedList(); 591 ProbeLocator.locate(resource, content, list); 592 assertEquals(numberOfFeeds, list.size()); 593 594 FeedReference[] feeds = (FeedReference[])list.toArray(new FeedReference[list.size()]); 595 assertEquals(numberOfFeeds, feeds.length); 596 597 for (int i = 0; i < feeds.length; i++) { 598 assertEquals(FeedReference.METHOD_PROBE_DISCOVERY, feeds[i].method); 599 assertNull(null, feeds[i].title); 600 assertEquals(feedType[i], feeds[i].type); 601 assertEquals(feedURL[i], feeds[i].resource); 602 } 603 604 return list; 605 } 606 607 private FeedList testFeedLocator( String resource, 608 BlogService correctBlogService, 609 int numberOfFeeds, 610 String feedType[], 611 String feedURL[], 612 boolean hasAtomFeed, 613 String atomFeedURL, 614 boolean hasRSSFeed, 615 String rssFeedURL ) throws Exception { 616 617 FeedList list = FeedLocator.locate( resource ); 618 FeedReference atomFeed = list.getAdAtomFeed(); 619 FeedReference rssFeed = list.getAdRSSFeed(); 620 if (hasAtomFeed) { 621 assertNotNull(atomFeed); 622 assertEquals(FeedReference.ATOM_MEDIA_TYPE, atomFeed.type); 623 assertEquals(atomFeedURL, atomFeed.resource); 624 } 625 else 626 assertNull(atomFeed); 627 628 if (hasRSSFeed) { 629 assertNotNull(rssFeed); 630 assertEquals(FeedReference.RSS_MEDIA_TYPE, rssFeed.type); 631 assertEquals(rssFeedURL, rssFeed.resource); 632 } 633 else 634 assertNull(rssFeed); 635 636 return list; 637 } 638 }