We help IT Professionals succeed at work.

junit test case

gobicse
gobicse asked
on
618 Views
Last Modified: 2013-11-23
hi there
   i have to write test cases for my web crawler application. i have so many methods in it. can any one help me how to write test case for the following method... i can do the remaining methods by understanding how you have written... i go through lots of links.. but all of them are very simple test cases... can anyone please help me...
public static void crawl(String startUrl, int maxUrls, boolean limitHost,String searchString, boolean caseSensitive,int flag)
	  
	  {
	  System.out.println("Enterig crawl method.....");
	    // Setup crawl lists.
	    HashSet crawledList = new HashSet();
	    LinkedHashSet toCrawlList = new LinkedHashSet();
	    
	    System.out.println("Enterig crawl method"+startUrl);
	    // Add start URL to the to crawl list.
	    toCrawlList.add(startUrl); 
	    // Perform actual crawling by looping through the to crawl list. 
	    System.out.println("Enterig crawling looppppppppp.....");
	    while (crawling && toCrawlList.size() > 0)
	    {
	      // Check to see if the max URL count has been reached, if it was specified.
    	System.out.println("size of crawl list is ....." + toCrawlList.size());
	    	System.out.println( "Max URLZZZZ : "+maxUrls);
	      if (maxUrls != -1) {
	        if (crawledList.size() == maxUrls) {
	          break;
	        }
	      } 
	      // Get URL at bottom of the list.
	      String url = (String) toCrawlList.iterator().next();
	  		System.out.println( "URL at bottom of the list is  : "+url);
	      // Remove URL from the to crawl list.
	      toCrawlList.remove(url); 
	      // Convert string url to URL object.
	      URL verifiedUrl = urlProcess.UrlVerification.verifyUrl(url); 
	      // Skip URL if robots are not allowed to access it.
	      if (!urlProcess.RobotCheck.isRobotAllowed(verifiedUrl)) {
	        continue;
	      } 
	      userInterface.SearchCrawler.updateStats(url, crawledList.size(), toCrawlList.size(),
	        maxUrls,startUrl); 
	      // Add page to the crawled list.
	      crawledList.add(url); 
	      // Download the page at the given url.
	        String pageContents = urlProcess.PageDownload.downloadPage(verifiedUrl,flag);
	     //  If the page was downloaded successfully, retrieve all of its links and then see if it contains the search string. 
	      if (pageContents != null && pageContents.length() > 0)
	      {
	        // Retrieve list of valid links from page.
	        ArrayList links =
	          crawlProcess.LinkRetrieval.retrieveLinks(verifiedUrl, pageContents, crawledList,
	            limitHost,flag); 
	        // Add links to the to crawl list.
	        toCrawlList.addAll(links); 
	        
	         //Check if search string is present in page and if so record a match. 
	        if (crawlProcess.StringMatch.searchStringMatches(pageContents, searchString,caseSensitive))
	        {
	        	userInterface.SearchCrawler.addMatch(url,startUrl);
	        }
	      }
	      // Update crawling stats.
	      userInterface.SearchCrawler.updateStats(url, crawledList.size(), toCrawlList.size(),
	        maxUrls, startUrl);
	    }

Open in new window

Comment
Watch Question

CERTIFIED EXPERT

Commented:

Author

Commented:
hi gurvinder...
   i go through all these links.. esp that money example... the problem is i dunno how the test case should be for  my application.. tats y i need your help.. kindly let me know how the test case should be for the above method.. or atleast the skeleton part for it...
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
a_b
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.