APILocator.getFolderAPI().createFolders("/a_test/b_test/", host, sysuser, false);
Folder Fa=APILocator.getFolderAPI().findFolderByPath("/a_test/", host, sysuser, false);
Folder Fab=APILocator.getFolderAPI().findFolderByPath("/a_test/b_test", host, sysuser, false);
HTMLPage page1=new HTMLPage();
page1.setFriendlyName("index");
page1.setPageUrl("index."+pageExt);
page1.setTitle("index page");
page1.setTemplateId(template.getIdentifier());
page1=APILocator.getHTMLPageAPI().saveHTMLPage(page1, template, Fa, sysuser, false);
HTMLPage page2=new HTMLPage();
page2.setFriendlyName("something");
page2.setPageUrl("something."+pageExt);
page2.setTitle("something");
page2.setTemplateId(template.getIdentifier());
page2=APILocator.getHTMLPageAPI().saveHTMLPage(page2, template, Fa, sysuser, false);
HTMLPage page3=new HTMLPage();
page3.setFriendlyName("index");
page3.setPageUrl("index."+pageExt);
page3.setTitle("index page");
page3.setTemplateId(template.getIdentifier());
page3=APILocator.getHTMLPageAPI().saveHTMLPage(page3, template, Fab, sysuser, false);
HTMLPage page4=new HTMLPage();
page4.setFriendlyName("something");
page4.setPageUrl("something."+pageExt);
page4.setTitle("something");
page4.setTemplateId(template.getIdentifier());
page4=APILocator.getHTMLPageAPI().saveHTMLPage(page4, template, Fab, sysuser, false);
extlinks=new String[] {
page1.getURI(), page2.getURI(), page3.getURI(), page4.getURI(), // direct hit!
"/a_test/", "/a_test/b_test", // should be good as it hits index page
"/a_test/notnotnot_exists."+pageExt, // a bad one!
"?relative=yes", // should be ignored
"#id_inside_page", // ignored too
page2.getURI()+"?a=1&b=2" // with query string
};
sb=new StringBuilder("<html><body>\n");
for(String ll : extlinks) sb.append("<a href='").append(ll).append("'>link</a>\n");
sb.append("</body></html>");
con=new Contentlet();
con.setStructureInode(structure.getInode());
con.setStringProperty("html", sb.toString());
con=APILocator.getContentletAPI().checkin(con, sysuser, false);
APILocator.getContentletAPI().isInodeIndexed(con.getInode());
invalids = APILocator.getLinkCheckerAPI().findInvalidLinks(con);
assertTrue(invalids!=null);
assertEquals(invalids.size(),1);
assertEquals(invalids.get(0).getUrl(),"/a_test/notnotnot_exists."+pageExt);
////////////////////////
// basic urlmap links //
////////////////////////
con=new Contentlet();
con.setStructureInode(urlmapstructure.getInode());
con.setStringProperty("a", "url1");
con=APILocator.getContentletAPI().checkin(con, sysuser, false);
APILocator.getContentletAPI().isInodeIndexed(con.getInode());
con=new Contentlet();
con.setStructureInode(urlmapstructure.getInode());
con.setStringProperty("a", "url2");
con=APILocator.getContentletAPI().checkin(con, sysuser, false);
APILocator.getContentletAPI().isInodeIndexed(con.getInode());
extlinks=new String[] {
"/test_mapped/url1","/test_mapped/url2/", // those should be good
"/test_mapped/url1#ignorethis",
"/test_mapped/url2/#againignore",
"/test_mapped/url3" // a bad one
};
sb=new StringBuilder("<html><body>\n");
for(String ll : extlinks) sb.append("<a href='").append(ll).append("'>link</a>\n");
sb.append("</body></html>");
con=new Contentlet();
con.setStructureInode(structure.getInode());
con.setStringProperty("html", sb.toString());
con=APILocator.getContentletAPI().checkin(con, sysuser, false);
APILocator.getContentletAPI().isInodeIndexed(con.getInode());
invalids = APILocator.getLinkCheckerAPI().findInvalidLinks(con);
assertTrue(invalids!=null);
assertEquals(invalids.size(),1);
assertEquals(invalids.get(0).getUrl(),"/test_mapped/url3");
/* Now using two hosts. In host1 we gonna put a content with a valid
* internal link to a page. Then we add the contentlet in a page that
* lives in another host. That should break the internal link */
con=new Contentlet();
con.setStringProperty("html", "<html><body>" +
"<a href='"+page2.getURI()+"'>thislink</a>" +
"<a href='"+page3.getURI()+"'>thislink</a>" +
"<a href='"+page4.getURI()+"'>thislink</a>" +
"</body></html>");
con.setStructureInode(structure.getInode());
con=APILocator.getContentletAPI().checkin(con, sysuser, false);
APILocator.getContentletAPI().isInodeIndexed(con.getInode());
MultiTree mtree=new MultiTree();
mtree.setParent1(page1.getIdentifier());
mtree.setParent2(container.getIdentifier());
mtree.setChild(con.getIdentifier());
mtree.setTreeOrder(1);
MultiTreeFactory.saveMultiTree(mtree);
// that should be ok. It is in the same host where those pages are valid
invalids = APILocator.getLinkCheckerAPI().findInvalidLinks(con);
assertTrue(invalids!=null);
assertEquals(invalids.size(),0);
// now lets add some salt here. If the content is added in a page in host2 it
// should break the internal links
Folder home=APILocator.getFolderAPI().createFolders("/home/", host2, sysuser, false);
HTMLPage page5=new HTMLPage();
page5.setFriendlyName("something");
page5.setPageUrl("something."+pageExt);
page5.setTitle("something");
page5.setTemplateId(template.getIdentifier());
page5=APILocator.getHTMLPageAPI().saveHTMLPage(page5, template, home, sysuser, false);
mtree=new MultiTree();
mtree.setParent1(page5.getIdentifier());
mtree.setParent2(container.getIdentifier());
mtree.setChild(con.getIdentifier());
mtree.setTreeOrder(1);
MultiTreeFactory.saveMultiTree(mtree);