/** * Tests if the {@link PageInstanceMapper} is used if {@link * org.apache.wicket.settings.def.PageSettings#getRecreateMountedPagesAfterExpiry()} is disabled */ @Test public void testLinkOnPageWithRecreationDisabled() { tester.getApplication().getPageSettings().setRecreateMountedPagesAfterExpiry(false); PageWithLink page = tester.startPage(PageWithLink.class, new PageParameters().add("param", "value")); Link<?> link = (Link<?>) page.get("link"); String url = link.getURL().toString(); assertEquals("./wicket/page?0-1.ILinkListener-link", url); tester.executeUrl(url); }
/** ... and this should throw a {@link PageExpiredException} if the page is expired */ @Test(expected = PageExpiredException.class) public void testExpiredPageWithRecreationDisabled() { tester.getApplication().getPageSettings().setRecreateMountedPagesAfterExpiry(false); PageWithLink page = tester.startPage(PageWithLink.class, new PageParameters().add("param", "value")); Link<?> link = (Link<?>) page.get("link"); String url = link.getURL().toString(); assertEquals("./wicket/page?0-1.ILinkListener-link", url); // simulate a page expiry url = url.replace("page?0", "page?3"); tester.executeUrl(url); }
public void run(String[] args) throws IOException { System.out.println( "Crawling for " + maxPages + " pages relevant to " + args[1] + " starting from " + startingUrl); System.out.println("\n"); try { URL url = new URL(startingUrl); Link newLink = new Link(url, ""); knownUrls.put(url, newLink); urlQueue.add(newLink); allLinks.put(url, newLink); } catch (MalformedURLException e) { System.out.println("Invalid starting URL " + args[0]); } while ((!(urlQueue.size() == 0)) && (knownUrls.size() < maxPages)) { Link newLink = urlQueue.poll(); URL newUrl = newLink.getURL(); if (debug) { System.out.println( "Downloading : " + newLink.getURL() + " with score = " + newLink.getScore()); } if (!robotSafe(newUrl)) { continue; } File dFile = downloadFile(newUrl); if (dFile != null) { if (debug) { System.out.println("Received : " + newUrl); } // knownUrls.put(newUrl, newLink); fetchAnchorLinks(dFile, newUrl); } } }
public void fetchAnchorLinks(File file, URL parentUrl) throws IOException { Document doc = Jsoup.parse(file, "UTF-8", parentUrl.toString()); Elements links = doc.select("a[href]"); for (Element link : links) { String linkHref = link.attr("href"); String anchorText = link.text(); URL childUrl = new URL(parentUrl, linkHref); Link newLink = new Link(childUrl, anchorText); int score = computeScore(file, link, query, parentUrl); if (knownUrls.size() == maxPages) { break; } if (!knownUrls.containsKey(childUrl)) { if (!urlQueue.contains(newLink)) { newLink.setScore(score); urlQueue.add(newLink); // allLinks.put(childUrl, newLink); if (debug) { System.out.println( "Adding to queue: " + newLink.getURL() + " with score = " + newLink.getScore()); } } } else { Link retrievedLink = knownUrls.get(childUrl); if (urlQueue.contains(retrievedLink)) { int newScore = score + retrievedLink.getScore(); retrievedLink.setScore(newScore); // knownUrls.put(childUrl,retrievedLink); if (debug) { System.out.println("Adding " + score + " to score of " + retrievedLink.getURL()); } } } } System.out.println("\n"); }
/** * Tests if it is possible to re-instantiate the page if it is expired. The page should be * instantiated with the same page parameters. The link will not be clicked however. */ @Test public void testLinkOnExpiredPage() { PageWithLink page = tester.startPage(PageWithLink.class, new PageParameters().add("param", "value")); assertEquals("value", page.getPageParameters().get("param").toString()); tester.assertContains("param=value"); Link<?> link = (Link<?>) page.get("link"); String url = link.getURL().toString(); // simulate a page expiry url = url.replace("?0", "?3"); tester.executeUrl(url); // request parameters to callback urls should be ignored for the re-created page // (WICKET-4594) tester.assertContainsNot("param=value"); }
/** * Tests if the page parameters are part of the url of the link, and if the link actually works. */ @Test public void testPageParametersInLink() { PageWithLink page = tester.startPage(PageWithLink.class, new PageParameters().add("param", "value")); Link<?> link = (Link<?>) page.get("link"); String url = link.getURL().toString(); if (mount) assertTrue( "URL for link should contain 'mount/value/part2': " + url, url.toString().contains("mount/value/part2")); else assertTrue( "URL for link should contain 'param=value': " + url, url.toString().contains("param=value")); tester.executeUrl(url); }