Package com.scraper.test

Source Code of com.scraper.test.DownloaderUITest

package com.scraper.test;

import static org.junit.Assert.assertTrue;

import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.fest.swing.core.BasicComponentFinder;
import org.fest.swing.core.ComponentFinder;
import org.fest.swing.edt.GuiActionRunner;
import org.fest.swing.edt.GuiQuery;
import org.fest.swing.edt.GuiTask;
import org.fest.swing.finder.JFileChooserFinder;
import org.fest.swing.fixture.FrameFixture;
import org.fest.swing.fixture.JButtonFixture;
import org.fest.swing.fixture.JFileChooserFixture;
import org.fest.swing.fixture.JTextComponentFixture;
import org.fest.util.Files;
import org.junit.Assert;
import org.junit.Test;
import com.scraper.DownloaderUI;
import com.scraper.parser.HTMLParser;

public class DownloaderUITest extends FestSwingJUnitTestCase {

  private FrameFixture window;

  @Override
  protected void onSetUp()
  {
    JFrame frame = GuiActionRunner.execute(new GuiQuery<JFrame>() {
      @Override
      protected JFrame executeInEDT()
      {
        return new DownloaderUI().display();
      }
    });
    window = new FrameFixture(robot(), frame);
    window.show();
  }

  @Test
  public void testInvalidInputDialog()
  {
    final ComponentFinder finder = BasicComponentFinder
        .finderWithCurrentAwtHierarchy();
    JButtonFixture btn = window.button();
    JTextComponentFixture url = window.textBox();
    url.enterText("not a url");
    btn.click();

    window.dialog().requireVisible();

    window.dialog().button().click();

    btn.requireEnabled();
    btn.requireEnabled();

    url.enterText("www.yahoo.com");
    url.pressKey(KeyEvent.VK_ENTER);

    final JFileChooserFixture fc = JFileChooserFinder.findFileChooser()
        .withTimeout(15000).using(window.robot);
    final JButtonFixture fBtn = btn;

    GuiActionRunner.execute(new GuiTask() {
      @Override
      public void executeInEDT()
      {
        fc.target.setSelectedFile(Files.currentFolder());
        fc.target.approveSelection();
        fBtn.requireDisabled();
        fBtn.requireDisabled();
      }
    });

    JPanel panel = (JPanel) finder.findByName("Download Progress");
    Assert.assertTrue(panel.getComponentCount() > 0);
  }

  @Test
  public void testParser()
  {
    HTMLParser parser = HTMLParser.parseImages("not a url");
    assertTrue(parser.hasError());
    parser = HTMLParser.parseImages("www.yahoocom");
    assertTrue(parser.hasError());
    parser = HTMLParser.parseImages("www.yahoo.com");
    assertTrue(!parser.hasError());
    parser = HTMLParser.parseImages("http://www.yahoo.com");
    assertTrue(!parser.hasError());
    parser = HTMLParser.parseImages("https://www.yahoo.com/");
    assertTrue(!parser.hasError());
    assertTrue(parser.hasNextImage());
  }
}
TOP

Related Classes of com.scraper.test.DownloaderUITest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.