📄 simpleuserlayoutmanagertest.java
字号:
package org.jasig.portal.layout;import junit.framework.*;import org.jasig.portal.SingleDocumentUserLayoutStoreMock;import org.jasig.portal.UserProfile;import org.jasig.portal.PortalException;import org.jasig.portal.IUserLayoutStore;import org.jasig.portal.security.IPerson;import org.jasig.portal.security.PersonFactory;import java.io.*;import java.util.Enumeration;import org.w3c.dom.Document;import org.xml.sax.EntityResolver;import org.xml.sax.InputSource; public class SimpleUserLayoutManagerTest extends TestCase implements LayoutEventListener { Document sampleUserLayout=null; IUserLayoutStore uls=null; IPerson p=null; SimpleUserLayoutManager man=null; protected final static String SAMPLE_LAYOUT_FILENAME="userLayout.sample"; boolean nodeAdded, nodeDeleted, nodeMoved, nodeUpdated, layoutSaved, layoutLoaded; LayoutEvent lastEvent; public SimpleUserLayoutManagerTest(String s) { super(s); } protected void setUp() throws Exception { UserLayoutDTDResolver er=new UserLayoutDTDResolver(); // read in the layout DOM // note that we really do need to have a DOM structure here in order to introduce // persistent changes on the level of userLayout. //org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser(); javax.xml.parsers.DocumentBuilderFactory pf=javax.xml.parsers.DocumentBuilderFactory.newInstance(); pf.setValidating(true); javax.xml.parsers.DocumentBuilder parser=pf.newDocumentBuilder(); //org.apache.xerces.jaxp.DOMParser parser = new org.apache.xerces.parsers.DOMParser (); //parser.setFeature ("http://apache.org/xml/features/validation/dynamic", true); parser.setEntityResolver(er); parser.setErrorHandler(new org.xml.sax.helpers.DefaultHandler()); this.sampleUserLayout=parser.parse (new org.xml.sax.InputSource(this.getClass().getResourceAsStream(SAMPLE_LAYOUT_FILENAME))); p = PersonFactory.createPerson(); assertTrue(sampleUserLayout!=null); uls=new SingleDocumentUserLayoutStoreMock(sampleUserLayout); man=new SimpleUserLayoutManager(p,new UserProfile(),uls); // clear event-related markers nodeAdded=nodeDeleted=nodeMoved=nodeUpdated=layoutSaved=layoutLoaded=false; lastEvent=null; man.addLayoutEventListener(this); man.loadUserLayout(); } protected class UserLayoutDTDResolver implements EntityResolver { final static String dtdName="userLayout.dtd"; /** * Sets up a new input source based on the dtd specified in the xml document * @param publicId the public ID * @param systemId the system ID * @return an input source based on the dtd specified in the xml document */ public InputSource resolveEntity (String publicId, String systemId) { InputStream inStream = null; InputSource inSrc = null; if (systemId != null) { if (dtdName != null && systemId.indexOf(dtdName) != -1) { try { Class testClass=Class.forName("org.jasig.portal.layout.SimpleUserLayoutManagerTest"); inStream = testClass.getResourceAsStream(dtdName); } catch (Exception e) { e.printStackTrace(); return null; } } inSrc = new InputSource(inStream); } return inSrc; } } public void testGetNode() throws Exception { // test load event { assertTrue("layoutLoad event receive",layoutLoaded); } // get a folder { String id="s4"; IUserLayoutNodeDescription node=man.getNode(id); assertTrue(node!=null); if(node!=null) { // make up a fake node, with the same id UserLayoutFolderDescription ts=new UserLayoutFolderDescription(); ts.setId(node.getId()); ts.setName("Main"); ts.setHidden(false); ts.setImmutable(true); ts.setUnremovable(true); ts.setFolderType(UserLayoutFolderDescription.REGULAR_TYPE); assertEquals(ts,node); } } // get a channel { String id="n6"; IUserLayoutNodeDescription node=man.getNode(id); assertTrue(node!=null); if(node!=null) { // make up a fake node, with the same id UserLayoutChannelDescription ts=new UserLayoutChannelDescription(); ts.setId(node.getId()); ts.setName("uPortal-Powered Sites"); ts.setTitle("uPortal-Powered Sites"); ts.setHidden(false); ts.setImmutable(true); ts.setUnremovable(true); ts.setClassName("org.jasig.portal.channels.CGenericXSLT"); ts.setFunctionalName(""); ts.setChannelPublishId("5"); ts.setChannelTypeId("0"); ts.setDescription("uPortal Demos channel"); ts.setEditable(false); ts.setHasAbout(false); ts.setHasHelp(false); ts.setTimeout(10000); ts.setParameterValue("xmlUri","http://www.interactivebusiness.com/publish/jasigPortalDemos.rss"); ts.setParameterValue("sslUri","CGenericXSLT/RSS/RSS-0_9x.ssl"); assertEquals(ts,node); } } } public void testAddChannel() throws Exception { // testing by doing add and subsequent get // add a channel UserLayoutChannelDescription nchan=new UserLayoutChannelDescription(); nchan.setName("Newly added channel"); nchan.setTitle("Newly added channel"); nchan.setHidden(false); nchan.setImmutable(true); nchan.setUnremovable(true); nchan.setClassName("org.jasig.portal.channels.CGenericXSLT"); nchan.setFunctionalName(""); nchan.setChannelPublishId("5"); nchan.setChannelTypeId("0"); nchan.setDescription("some example channel"); nchan.setEditable(false); nchan.setHasAbout(false); nchan.setHasHelp(false); nchan.setTimeout(10000); nchan.setParameterValue("xmlUri","http://www.interactivebusiness.com/publish/jasigPortalDemos.rss"); nchan.setParameterValue("sslUri","CGenericXSLT/RSS/RSS-0_9x.ssl"); String parentId="s7"; String siblingId="n8"; assertTrue("can a node be added ?",man.canAddNode(nchan,parentId,siblingId)); UserLayoutChannelDescription rchan=(UserLayoutChannelDescription) man.addNode(nchan,parentId,siblingId); // System.out.println("Layout\n"+XML.serializeNode(man.getUserLayoutDOM())); assertTrue("addNode() returned null",rchan!=null); nchan.setId(rchan.getId()); assertEquals("comparing the original and addNode() result: ",nchan,rchan); // do a get IUserLayoutNodeDescription gnode=man.getNode(nchan.getId()); assertEquals("comparing the original and getNode() result: ",nchan,gnode); assertEquals("parentId is the specified attachment point",parentId,man.getParentId(nchan.getId())); assertEquals("siblingId is the specified next sibling",siblingId,man.getNextSiblingId(nchan.getId())); assertTrue("nodeAdded event received",nodeAdded); assertTrue("LayoutEvent is not null",lastEvent!=null); assertEquals("LayoutEvent nodeId",nchan.getId(),lastEvent.getNodeDescription().getId()); } public void testAddFolder() throws Exception { // testing by doing add and subsequent get // add a channel UserLayoutFolderDescription nfold=new UserLayoutFolderDescription(); nfold.setName("Newly added folder"); nfold.setHidden(false); nfold.setImmutable(true); nfold.setUnremovable(true); nfold.setFolderType(UserLayoutFolderDescription.REGULAR_TYPE); String parentId="s7"; assertTrue("can a node be added ?",man.canAddNode(nfold,parentId,null)); UserLayoutFolderDescription rfold=(UserLayoutFolderDescription) man.addNode(nfold,parentId,null); // System.out.println("Layout\n"+XML.serializeNode(man.getUserLayoutDOM())); assertTrue("addNode() returned null",rfold!=null); nfold.setId(rfold.getId()); assertEquals("comparing the original and addNode() result: ",nfold,rfold); // do a get IUserLayoutNodeDescription gnode=man.getNode(nfold.getId()); assertEquals("comparing the original and getNode() result: ",nfold,gnode); assertEquals("parentId is the specified attachment point",parentId,man.getParentId(nfold.getId())); assertTrue("nodeAdded event received",nodeAdded); assertTrue("LayoutEvent is not null",lastEvent!=null); assertEquals("LayoutEvent nodeId",nfold.getId(),lastEvent.getNodeDescription().getId()); } public void testCanMove() throws Exception { // try moving a channel String nodeId="n8";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -