01: /* Copyright 2004 - 2005 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal;
07:
08: import javax.xml.parsers.DocumentBuilderFactory;
09: import javax.xml.parsers.ParserConfigurationException;
10:
11: import org.w3c.dom.Document;
12: import org.w3c.dom.Element;
13:
14: import junit.framework.TestCase;
15:
16: /**
17: * Testcase for ChannelDefinition class.
18: * @version $Revision: 35463 $ $Date: 2005-03-29 11:24:45 -0700 (Tue, 29 Mar 2005) $
19: */
20: public class ChannelDefinitionTest extends TestCase {
21:
22: /**
23: * Test that ChannelDefinition identifies CPortletAdaptor as a portlet but
24: * does not identify CGenericXSLT as a portlet.
25: */
26: public void testIsPortlet() {
27: ChannelDefinition cd = new ChannelDefinition(72);
28:
29: cd.setJavaClass("org.jasig.portal.channels.CGenericXSLT");
30: assertFalse(cd.isPortlet());
31:
32: cd
33: .setJavaClass("org.jasig.portal.channels.portlet.CPortletAdapter");
34: assertTrue(cd.isPortlet());
35:
36: }
37:
38: /**
39: * Test Element representation of channel to see that its node name is
40: * 'channel' and that it has the proper owning document and that the channel
41: * element has the correct identifer such that it can be gotten by ID.
42: * @throws ParserConfigurationException
43: */
44: public void testGetDocument() throws ParserConfigurationException {
45: ChannelDefinition cd = new ChannelDefinition(73);
46:
47: cd.setDescription("A test channel description.");
48: cd.setEditable(false);
49: cd.setFName("test_fname");
50: cd.setHasAbout(true);
51: cd.setHasHelp(false);
52: cd.setIsSecure(false);
53: cd.setJavaClass("org.jasig.portal.channels.CGenericXSLT");
54: cd.setName("testName");
55: cd.setTimeout(500);
56: cd.setTitle("testTitle");
57: cd.setTypeId(12);
58:
59: Document doc = DocumentBuilderFactory.newInstance()
60: .newDocumentBuilder().newDocument();
61:
62: Element channelElement = cd.getDocument(doc, "testId");
63:
64: assertEquals("channel", channelElement.getNodeName());
65: assertSame(doc, channelElement.getOwnerDocument());
66:
67: doc.appendChild(channelElement);
68:
69: assertSame(channelElement, doc.getElementById("testId"));
70:
71: assertEquals("A test channel description.", channelElement
72: .getAttribute("description"));
73: assertEquals("false", channelElement.getAttribute("editable"));
74: assertEquals("test_fname", channelElement.getAttribute("fname"));
75: assertEquals("true", channelElement.getAttribute("hasAbout"));
76: assertEquals("false", channelElement.getAttribute("hasHelp"));
77: assertEquals("false", channelElement.getAttribute("secure"));
78: assertEquals("org.jasig.portal.channels.CGenericXSLT",
79: channelElement.getAttribute("class"));
80: assertEquals("testName", channelElement.getAttribute("name"));
81: assertEquals("500", channelElement.getAttribute("timeout"));
82: assertEquals("testTitle", channelElement.getAttribute("title"));
83: assertEquals("12", channelElement.getAttribute("typeID"));
84:
85: }
86:
87: }
|