package ca.unknown.scrapper;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Collection;

import org.junit.Test;

import ca.unknown.scrapper.action.Action;
import ca.unknown.scrapper.action.ExitAction;
import ca.unknown.scrapper.action.FollowLinkAction;
import ca.unknown.scrapper.action.ScrapeAction;
import ca.unknown.scrapper.invoker.ConcreteInvoker;
import ca.unknown.scrapper.invoker.Invoker;
import ca.unknown.scrapper.scrapeTarget.AttributeTarget;
import org.junit.Test;

public class JsoupHtmlScrapperTest {
	
	@Test
	public void shouldPrintABunchOfRelativeLinkComingFromTheVbAddictBattleHistoryTable() {
		String entryPoint = "http://www.vbaddict.net/battlehistory.php?go=search";
		
		String replayPageLinkSelection = "#table-statistics tr td:last-child a";
		
		HtmlScrapper scrapper = new JsoupHtmlScrapper(entryPoint);
		Collection<String> scraps = new ArrayList<String>();
		
		Action scrape		= new ScrapeAction(scrapper, new AttributeTarget(replayPageLinkSelection,"href"), scraps);
		Action followLink 	= new FollowLinkAction(scrapper, new AttributeTarget("a[rel=next]","href"));
		Action exit 		= new ExitAction(scrapper);
				
		scrape.setCallback(followLink);
		followLink.setCallback(scrape);
		followLink.setFailureCallback(exit);
		
		Invoker invoker 	= new ConcreteInvoker(scrape);
		
		invoker.setMaxExecution(2); //Fetching for 5 pages
		invoker.run();
		
		System.out.println("Number of scrap element " + scrapper.getScrapeResult().size());
		
		for(String scrapeResult : scraps)
			System.out.println(scrapeResult);
	}
	
	@Test
	public void shouldStartThreeAsynchronousExecutionForScrapeResult(){
		
	}
}

@@ -174,32 +174,86 @@
 .action.Action;%0A
+import ca.unknown.scrapper.action.AsynchronousAction;%0A
 import ca.unknow
@@ -534,39 +534,16 @@
 eTarget;
-%0Aimport org.junit.Test;
 %0A%0Apublic
@@ -1683,14 +1683,569 @@
 lt()%7B%0A%09%09
+Thread t = new Thread();%0A%09%09%0A%09%09String entryPoint = %22http://www.vbaddict.net/battlehistory.php?go=search%22;%0A%09%09%0A%09%09String replayPageLinkSelection = %22#table-statistics tr td:last-child a%22;%0A%09%09%0A%09%09HtmlScrapper scrapper = new JsoupHtmlScrapper(entryPoint);%0A%09%09Collection%3CString%3E scraps = new ArrayList%3CString%3E();%0A%09%09%0A%09%09Action scrape%09%09= new ScrapeAction(scrapper, new AttributeTarget(replayPageLinkSelection,%22href%22), scraps);%0A%0A%09%09Action followLink %09= new FollowLinkAction(scrapper, new AttributeTarget(%22a%5Brel=next%5D%22,%22href%22));%0A%09%09Action exit %09%09= new ExitAction(scrapper);
 %0A%09%7D%0A%7D%0A

Test skeleton for asynchronous action