コード例 #1
0
  public void testHomePage() {
    Crawler crawler = new CorriereDellaSeraCrawler();

    try {
      Collection<String> urls = crawler.retrieveArticleUrlsFromFeed();
      urls.addAll(crawler.retrieveArticleUrlsFromHomePage());

      Iterator<String> i = urls.iterator();
      boolean result = true;
      while (i.hasNext()) {
        String s = i.next();
        try {
          if (crawler.getArticle(s) != null) {
            System.out.println("  OK  >> \t " + s);
            result &= true;
          }
        } catch (CrawlerCannotReadArticleException e) {
          System.err.println("ERROR >> \t " + s);
          result &= false;
          e.printStackTrace();
        } catch (Exception e) {
          System.err.println("CRITICAL >> \t " + s);
          e.printStackTrace();
        }
      }
      assertEquals(true, result);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
  public void testHomePageAndFeedLinks() {
    try {
      Crawler crawler = new LaRepubblicaCrawler();
      Set<String> set = new HashSet<String>();
      set.addAll(crawler.retrieveArticleUrlsFromFeed());
      set.addAll(crawler.retrieveArticleUrlsFromHomePage());

      Iterator<String> i = set.iterator();
      boolean result = true;
      while (i.hasNext()) {
        String s = i.next();
        try {
          if (crawler.getArticle(s) != null) {
            System.out.println("  OK  >> \t " + s);
            result &= true;
          }
        } catch (CrawlerCannotReadArticleException e) {
          System.err.println("ERROR >> \t " + s);
          result &= false;
          e.printStackTrace();
        }
      }
      assertEquals(true, result);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }