/*
* Created on Mar 31, 2003
*/
package net.sf.jportlet.descriptor.test;
import java.io.InputStream;
import java.util.Locale;
import junit.framework.TestCase;
import net.sf.jportlet.portlet.Portlet;
import net.sf.jportlet.portlet.PortletAdapter;
import net.sf.jportlet.portlet.PortletException;
import net.sf.jportlet.portlet.descriptor.ApplicationDescriptor;
import net.sf.jportlet.portlet.descriptor.ApplicationDescriptorLoaderXml;
import net.sf.jportlet.portlet.descriptor.AuthConstraintDescriptor;
import net.sf.jportlet.portlet.descriptor.CacheDescriptor;
import net.sf.jportlet.portlet.descriptor.LanguageDescriptor;
import net.sf.jportlet.portlet.descriptor.PortletDescriptor;
import net.sf.jportlet.portlet.descriptor.WebflowActionDescriptor;
import net.sf.jportlet.portlet.event.ActionEvent;
import net.sf.jportlet.portlet.event.ActionListener;
import net.sf.jportlet.portlet.event.MessageEvent;
import net.sf.jportlet.portlet.event.MessageListener;
/**
* @author herve
*/
public class ApplicationDescriptorLoaderTest
extends TestCase
implements ActionListener,
MessageListener
{
//~ Methods ----------------------------------------------------------------
public void testLoad( )
throws Exception
{
String path = "net/sf/jportlet/descriptor/test/portlet.xml";
InputStream in = getClass( ).getClassLoader( ).getResourceAsStream( path );
ApplicationDescriptorLoaderXml loader = new ApplicationDescriptorLoaderXml( );
ApplicationDescriptor app = loader.load( in );
assertNotNull( "app", app );
assertEquals( "app.name", "Portlet Application", app.getName( ) );
assertEquals( "app.contextParameter[param1]", "value1", app.getContextParameter( "param1" ) );
PortletDescriptor portlet = app.getPortletDescriptor( "portlet1" );
assertNotNull( "portlet1 not found", portlet );
assertEquals( "portlet.name", "portlet1", portlet.getName( ) );
assertEquals( "portlet.portletClass", PortletAdapter.class, portlet.getPortletClass( ) );
assertEquals( "portlet.actionListenerClass", ApplicationDescriptorLoaderTest.class, portlet.getActionListenerClass( ) );
assertEquals( "portlet.messageListenerClass", ApplicationDescriptorLoaderTest.class, portlet.getMessageListenerClass( ) );
assertEquals( "portlet.defaultLocale", Locale.ENGLISH.toString( ), portlet.getDefaultLocale( ) );
assertEquals( "portlet.initParameter[param1]", "value1", portlet.getInitParameter( "param1" ) );
/* Markup support */
assertTrue( "portlet.supports(html,view)", portlet.supports( Portlet.Mode.VIEW, Portlet.Markup.HTML ) );
assertTrue( "portlet.supports(html,edit)", portlet.supports( Portlet.Mode.EDIT, Portlet.Markup.HTML ) );
assertTrue( "portlet.supports(html,help)", portlet.supports( Portlet.Mode.HELP, Portlet.Markup.HTML ) );
assertTrue( "portlet.supports(html,configure)", portlet.supports( Portlet.Mode.CONFIGURE, Portlet.Markup.HTML ) );
assertTrue( "portlet.supports(html,view)", portlet.supports( Portlet.Mode.VIEW, Portlet.Markup.WML ) );
assertFalse( "portlet.supports(wml,edit)", portlet.supports( Portlet.Mode.EDIT, Portlet.Markup.WML ) );
assertFalse( "portlet.supports(wml,help)", portlet.supports( Portlet.Mode.HELP, Portlet.Markup.WML ) );
assertFalse( "portlet.supports(wml,configure)", portlet.supports( Portlet.Mode.CONFIGURE, Portlet.Markup.WML ) );
/* Language */
LanguageDescriptor lang = portlet.getLanguageDescriptor( Locale.ENGLISH );
assertNotNull( "lang[en]", lang );
assertEquals( "lang[en].title", "Portlet #1", lang.getTitle( ) );
assertEquals( "lang[en].titleShort", "P #1", lang.getTitleShort( ) );
assertEquals( "lang[en].description", "Description of Portlet #1", lang.getDescription( ) );
assertEquals( "lang[en].keywords", "test,portlet", lang.getKeywords( ) );
LanguageDescriptor lang2 = portlet.getLanguageDescriptor( new Locale( "en", "US" ) );
assertNotNull( "lang[en_US]", lang );
assertEquals( "lang[en] != lang[en_US]", lang, lang2 );
lang = portlet.getLanguageDescriptor( Locale.FRENCH );
assertNotNull( "lang[fr]", lang );
assertEquals( "lang[fr].title", "Portlet No1", lang.getTitle( ) );
/* Cache */
CacheDescriptor cache = portlet.getCacheDescriptor( Portlet.Mode.VIEW );
assertNotNull( "cache[view]", cache );
assertEquals( "cache[view].expires", 300, cache.getExpires( ) );
assertFalse( "cache[view].shared", cache.isShared( ) );
cache = portlet.getCacheDescriptor( Portlet.Mode.HELP );
assertNotNull( "cache[help]", cache );
assertEquals( "cache[help].expires", -1, cache.getExpires( ) );
assertTrue( "cache[help].shared", cache.isShared( ) );
/* auth */
AuthConstraintDescriptor auth = portlet.getAuthConstraintDescriptor( Portlet.Mode.VIEW );
assertNotNull( "auth[view]", auth );
assertTrue( "auth[view].allowAnonymous", auth.isAllowAnonymous( ) );
assertTrue( "auth[view].role[author]", auth.containsRole( "author" ) );
assertTrue( "auth[view].role[admin]", auth.containsRole( "admin" ) );
auth = portlet.getAuthConstraintDescriptor( Portlet.Mode.CONFIGURE );
assertNotNull( "auth[configure]", auth );
assertFalse( "auth[configure].allowAnonymous", auth.isAllowAnonymous( ) );
assertFalse( "auth[configure].role[author]", auth.containsRole( "author" ) );
assertTrue( "auth[configure].role[admin]", auth.containsRole( "admin" ) );
WebflowActionDescriptor wf = portlet.getWebflowAction( "view" );
assertNotNull( "webflow[view]", wf );
assertEquals( "webflow[view].success", "/success.jsp", wf.getReturnURI("success"));
assertEquals( "webflow[view].input", "/portlet/capital/mode/view/state/maximized", wf.getReturnURI("input"));
assertNull( "webflow[view].???", wf.getReturnURI("???"));
wf = portlet.getWebflowAction( "???" );
assertNull( "webflow[???]", wf );
}
/**
* @see net.sf.jportlet.portlet.event.ActionListener#actionPerformed(net.sf.jportlet.portlet.event.ActionEvent)
*/
public void actionPerformed( ActionEvent event )
throws PortletException {}
/**
* @see net.sf.jportlet.portlet.event.MessageListener#messageReceived(net.sf.jportlet.portlet.event.MessageEvent)
*/
public void messageReceived( MessageEvent event )
throws PortletException {}
}