001: /*
002: * Created on Mar 31, 2003
003: */
004: package net.sf.jportlet.descriptor.test;
005:
006: import java.io.InputStream;
007:
008: import java.util.Locale;
009:
010: import junit.framework.TestCase;
011:
012: import net.sf.jportlet.portlet.Portlet;
013: import net.sf.jportlet.portlet.PortletAdapter;
014: import net.sf.jportlet.portlet.PortletException;
015: import net.sf.jportlet.portlet.descriptor.ApplicationDescriptor;
016: import net.sf.jportlet.portlet.descriptor.ApplicationDescriptorLoaderXml;
017: import net.sf.jportlet.portlet.descriptor.AuthConstraintDescriptor;
018: import net.sf.jportlet.portlet.descriptor.CacheDescriptor;
019: import net.sf.jportlet.portlet.descriptor.LanguageDescriptor;
020: import net.sf.jportlet.portlet.descriptor.PortletDescriptor;
021: import net.sf.jportlet.portlet.descriptor.WebflowActionDescriptor;
022: import net.sf.jportlet.portlet.event.ActionEvent;
023: import net.sf.jportlet.portlet.event.ActionListener;
024: import net.sf.jportlet.portlet.event.MessageEvent;
025: import net.sf.jportlet.portlet.event.MessageListener;
026:
027: /**
028: * @author herve
029: */
030: public class ApplicationDescriptorLoaderTest extends TestCase implements
031: ActionListener, MessageListener {
032: //~ Methods ----------------------------------------------------------------
033:
034: public void testLoad() throws Exception {
035: String path = "net/sf/jportlet/descriptor/test/portlet.xml";
036: InputStream in = getClass().getClassLoader()
037: .getResourceAsStream(path);
038:
039: ApplicationDescriptorLoaderXml loader = new ApplicationDescriptorLoaderXml();
040: ApplicationDescriptor app = loader.load(in);
041:
042: assertNotNull("app", app);
043: assertEquals("app.name", "Portlet Application", app.getName());
044: assertEquals("app.contextParameter[param1]", "value1", app
045: .getContextParameter("param1"));
046:
047: PortletDescriptor portlet = app
048: .getPortletDescriptor("portlet1");
049: assertNotNull("portlet1 not found", portlet);
050: assertEquals("portlet.name", "portlet1", portlet.getName());
051: assertEquals("portlet.portletClass", PortletAdapter.class,
052: portlet.getPortletClass());
053: assertEquals("portlet.actionListenerClass",
054: ApplicationDescriptorLoaderTest.class, portlet
055: .getActionListenerClass());
056: assertEquals("portlet.messageListenerClass",
057: ApplicationDescriptorLoaderTest.class, portlet
058: .getMessageListenerClass());
059: assertEquals("portlet.defaultLocale",
060: Locale.ENGLISH.toString(), portlet.getDefaultLocale());
061: assertEquals("portlet.initParameter[param1]", "value1", portlet
062: .getInitParameter("param1"));
063:
064: /* Markup support */
065: assertTrue("portlet.supports(html,view)", portlet.supports(
066: Portlet.Mode.VIEW, Portlet.Markup.HTML));
067: assertTrue("portlet.supports(html,edit)", portlet.supports(
068: Portlet.Mode.EDIT, Portlet.Markup.HTML));
069: assertTrue("portlet.supports(html,help)", portlet.supports(
070: Portlet.Mode.HELP, Portlet.Markup.HTML));
071: assertTrue("portlet.supports(html,configure)", portlet
072: .supports(Portlet.Mode.CONFIGURE, Portlet.Markup.HTML));
073:
074: assertTrue("portlet.supports(html,view)", portlet.supports(
075: Portlet.Mode.VIEW, Portlet.Markup.WML));
076: assertFalse("portlet.supports(wml,edit)", portlet.supports(
077: Portlet.Mode.EDIT, Portlet.Markup.WML));
078: assertFalse("portlet.supports(wml,help)", portlet.supports(
079: Portlet.Mode.HELP, Portlet.Markup.WML));
080: assertFalse("portlet.supports(wml,configure)", portlet
081: .supports(Portlet.Mode.CONFIGURE, Portlet.Markup.WML));
082:
083: /* Language */
084: LanguageDescriptor lang = portlet
085: .getLanguageDescriptor(Locale.ENGLISH);
086: assertNotNull("lang[en]", lang);
087: assertEquals("lang[en].title", "Portlet #1", lang.getTitle());
088: assertEquals("lang[en].titleShort", "P #1", lang
089: .getTitleShort());
090: assertEquals("lang[en].description",
091: "Description of Portlet #1", lang.getDescription());
092: assertEquals("lang[en].keywords", "test,portlet", lang
093: .getKeywords());
094:
095: LanguageDescriptor lang2 = portlet
096: .getLanguageDescriptor(new Locale("en", "US"));
097: assertNotNull("lang[en_US]", lang);
098: assertEquals("lang[en] != lang[en_US]", lang, lang2);
099:
100: lang = portlet.getLanguageDescriptor(Locale.FRENCH);
101: assertNotNull("lang[fr]", lang);
102: assertEquals("lang[fr].title", "Portlet No1", lang.getTitle());
103:
104: /* Cache */
105: CacheDescriptor cache = portlet
106: .getCacheDescriptor(Portlet.Mode.VIEW);
107: assertNotNull("cache[view]", cache);
108: assertEquals("cache[view].expires", 300, cache.getExpires());
109: assertFalse("cache[view].shared", cache.isShared());
110:
111: cache = portlet.getCacheDescriptor(Portlet.Mode.HELP);
112: assertNotNull("cache[help]", cache);
113: assertEquals("cache[help].expires", -1, cache.getExpires());
114: assertTrue("cache[help].shared", cache.isShared());
115:
116: /* auth */
117: AuthConstraintDescriptor auth = portlet
118: .getAuthConstraintDescriptor(Portlet.Mode.VIEW);
119: assertNotNull("auth[view]", auth);
120: assertTrue("auth[view].allowAnonymous", auth.isAllowAnonymous());
121: assertTrue("auth[view].role[author]", auth
122: .containsRole("author"));
123: assertTrue("auth[view].role[admin]", auth.containsRole("admin"));
124:
125: auth = portlet
126: .getAuthConstraintDescriptor(Portlet.Mode.CONFIGURE);
127: assertNotNull("auth[configure]", auth);
128: assertFalse("auth[configure].allowAnonymous", auth
129: .isAllowAnonymous());
130: assertFalse("auth[configure].role[author]", auth
131: .containsRole("author"));
132: assertTrue("auth[configure].role[admin]", auth
133: .containsRole("admin"));
134:
135: WebflowActionDescriptor wf = portlet.getWebflowAction("view");
136: assertNotNull("webflow[view]", wf);
137: assertEquals("webflow[view].success", "/success.jsp", wf
138: .getReturnURI("success"));
139: assertEquals("webflow[view].input",
140: "/portlet/capital/mode/view/state/maximized", wf
141: .getReturnURI("input"));
142: assertNull("webflow[view].???", wf.getReturnURI("???"));
143:
144: wf = portlet.getWebflowAction("???");
145: assertNull("webflow[???]", wf);
146: }
147:
148: /**
149: * @see net.sf.jportlet.portlet.event.ActionListener#actionPerformed(net.sf.jportlet.portlet.event.ActionEvent)
150: */
151: public void actionPerformed(ActionEvent event)
152: throws PortletException {
153: }
154:
155: /**
156: * @see net.sf.jportlet.portlet.event.MessageListener#messageReceived(net.sf.jportlet.portlet.event.MessageEvent)
157: */
158: public void messageReceived(MessageEvent event)
159: throws PortletException {
160: }
161: }
|