/**
   * Tests whether the page parser can pull prices, URL's, and titles from valid and empty pages.
   *
   * @throws ParserConfigurationException
   * @throws SAXException
   * @throws IOException
   */
  @Test
  public void testPageParser() throws ParserConfigurationException, SAXException, IOException {

    // Test a page that has valid results.
    InputStream validResultsInputStream =
        new FileInputStream(new File(PROJECT_PATH + TEST_VALID_XML_PATH));
    List<Ad> adsFromValidPage = PageParser.fromInputStream(validResultsInputStream);

    // Test a few prices.
    assertEquals(1500000, adsFromValidPage.get(0).getPriceInCents());
    assertEquals(119900000, adsFromValidPage.get(10).getPriceInCents());
    assertEquals(209800000, adsFromValidPage.get(24).getPriceInCents());

    // Test a title.
    assertEquals(
        "One Bluxome Street #316 OPEN HOUSE TODAY 1-4:00 PM 2Bed/1.5 Bath (SOMA / south beach) $1199000 2bd 1361sqft",
        adsFromValidPage.get(10).getDcTitle());

    // Test a URL.
    assertEquals(
        "http://sfbay.craigslist.org/sfc/reb/3963411826.html", adsFromValidPage.get(11).getURL());

    // Test whether a page that has no results can instantiate.
    InputStream noResultsFileStream =
        new FileInputStream(new File(PROJECT_PATH + TEST_NO_RESULTS_XML_PATH));
    try {
      List<Ad> adsFromNoResultsPage = PageParser.fromInputStream(noResultsFileStream);
    } catch (Exception e) {
      e.printStackTrace();
      fail("Could not parse a page with no results");
    }
  }
Ejemplo n.º 2
0
 @Before
 protected void setUp() throws SAXException, IOException, ParserConfigurationException {
   fileStream = new FileInputStream(new File(TestPageParser.PROJECT_PATH + TEST_STATS_XML));
   stats = new Stats(PageParser.fromInputStream(fileStream));
 }