1 4 package org.openedit.links; 5 6 import com.openedit.BaseTestCase; 7 import com.openedit.BaseWebPageRequest; 8 import com.openedit.WebPageRequest; 9 import com.openedit.page.Page; 10 import com.openedit.page.PageAction; 11 12 16 public class LinkTest extends BaseTestCase 17 { 18 19 22 public LinkTest(String inArg0) 23 { 24 super(inArg0); 25 } 26 49 public void testCrumb() throws Exception 50 { 51 LinkModule module = (LinkModule)getModule("LinkTree"); 52 WebPageRequest req = getFixture().createPageRequest("/salecatalogs.html"); 53 54 PageAction action = new PageAction("LinkTree.loadLinks"); 55 req.setCurrentAction(action); 56 module.loadLinks(req); 57 module.setSelectedLinkByUrl( req ); 58 59 ((BaseWebPageRequest)req).setContentPage(getPage("linktree/linktest.html")); 61 req.setCurrentAction(action); 62 module.loadLinks(req); 63 module.setSelectedLinkByUrl( req ); 64 65 LinkTree tree = (LinkTree)req.getPageValue("linktree"); 66 Link selectedLink = tree.getSelectedLink(); 67 assertEquals( selectedLink.getId(),"lancelot1"); 68 assertTrue( selectedLink.isSelected()); 69 assertTrue( selectedLink.getParentLink().isChildSelected()); 70 71 Link root = tree.findSelectedParentLink(0); 72 assertEquals(root,tree.getRootLink()); 73 74 Link child = tree.findSelectedParentLink(1); 75 assertEquals(selectedLink.getParentLink(),child); 76 77 } 78 79 93 public void testChangeId() throws Exception 94 { 95 LinkModule module = (LinkModule)getModule("LinkTree"); 97 WebPageRequest req = getFixture().createPageRequest("/linktree/linktest.html"); 98 PageAction action = new PageAction("LinkTree.loadLinks"); 99 req.setCurrentAction(action); 100 module.loadLinks(req); 101 module.setSelectedLinkByUrl( req ); 102 LinkTree tree = (LinkTree)req.getPageValue("linktree"); 103 104 Link rootLink = tree.getLink( "charleston" ); 106 tree.changeLinkId( rootLink, "root" ); 107 108 Link changedRootLink = tree.getLink( "root" ); 110 assertTrue( changedRootLink == rootLink ); 111 Link oldRootLink = tree.getLink( "charleston" ); 112 assertNull( oldRootLink ); 113 } 114 public void testFileSize() throws Exception 115 { 116 117 LinkModule module = (LinkModule)getModule("LinkTree"); 118 WebPageRequest req = getFixture().createPageRequest("/linktree/linktest.html"); 119 PageAction action = new PageAction("LinkTree.loadSizer"); 120 req.setCurrentAction(action); 121 module.loadSizer(req); 122 FileSize files = (FileSize)req.getPageValue("filesize"); 123 String ks = files.inKs("/scales.gif"); 124 assertEquals("5",ks); 125 126 } 127 public void testRedirect() throws Exception 128 { 129 WebPageRequest req = getFixture().createPageRequest("/noexist1/index.html"); 130 getFixture().getEngine().executePathActions(req); 131 String re = (String )req.getPageValue("redirect"); 132 assertEquals( "/exist/index.html", re); 133 } 134 public void testRedirectWildcards() throws Exception 135 { 136 LinkModule module = (LinkModule)getModule("LinkTree"); 137 WebPageRequest req = getFixture().createPageRequest("/noexist2/index.html"); 138 getFixture().getEngine().executePathActions(req); 139 String re = (String )req.getPageValue("redirect"); 140 assertEquals( "/exist/index.html", re); 141 142 LinkTree tree = module.getLinkTree(req); 143 144 String res = tree.findRedirect( "/noexist2/sub1/more/stuff/stuff.html" ); 145 assertEquals( "/exist/more/stuff/stuff.html", res); 147 148 re = tree.findRedirect( "/store/products/stuff.html" ); 150 assertEquals( "http://acme.com/store/products/stuff.html", re); 151 } 152 153 public void testEdit() throws Exception 154 { 155 LinkModule module = (LinkModule)getModule("LinkTree"); 156 Page draft = getPage("/links.draft.xml"); 157 getFixture().getPageManager().removePage(draft); 158 159 WebPageRequest req = getFixture().createPageRequest("/index.html"); 160 req.getUser().put("oe.edit.draftmode", "true"); 161 req.setRequestParameter("linkid", "index"); 162 163 LinkTree tree = module.loadLinks(req); 164 165 module.appendLink(req); 166 167 assertNotNull(tree); 168 String newId = tree.getSelectedLink().getId(); 169 170 req = getFixture().createPageRequest("/index.html"); 171 req.setRequestParameter("linkid", newId); 172 173 module.appendLink(req); 174 tree = module.loadLinks(req); 175 assertTrue(!newId.equals(tree.getSelectedLink().getId())); 176 } 177 178 public void testDuplicateSelection() throws Exception 179 { 180 LinkModule module = (LinkModule)getModule("LinkTree"); 181 WebPageRequest req = getFixture().createPageRequest("/linktree/fake.html"); 182 PageAction action = new PageAction("LinkTree.loadLinks"); 183 req.setCurrentAction(action); 184 module.loadLinks(req); 185 module.setSelectedLinkByUrl( req ); 186 LinkTree tree = (LinkTree)req.getPageValue("linktree"); 187 188 Link rootLink = tree.getSelectedLink(); 190 assertTrue(rootLink.isSelected()); 191 192 Link child = tree.getLink("fake2"); 193 assertTrue( child.isSelected()); 194 195 } 196 } 197 | Popular Tags |