/*
* 1. initialize script engine by script engine name
*/
PortletContext portletContext = new MockPortletContext(new DefaultResourceLoader());
MockPortletConfig portletConfig = new MockPortletConfig(portletContext);
portletConfig.addInitParameter(ScriptPortlet.ENGINE, scriptEngine);
if (evalPortletKey != null)
{
portletConfig.addInitParameter(ScriptPortlet.EVAL_KEY, evalPortletKey);
}
portletConfig.addInitParameter(ScriptPortlet.SOURCE, scriptSource);
ScriptPortlet helloScriptPortlet = new ScriptPortlet();
try
{
helloScriptPortlet.init(portletConfig);
assertTrue(helloScriptPortlet.getScriptSourceLastEvaluated() > 0L);
}
catch (PortletException e)
{
e.printStackTrace();
fail("Failed to initialize portlet: " + e);
}
/*
* 2. initialize script engine by script file extension
*/
portletContext = new MockPortletContext(new DefaultResourceLoader());
portletConfig = new MockPortletConfig(portletContext);
if (evalPortletKey != null)
{
portletConfig.addInitParameter(ScriptPortlet.EVAL_KEY, evalPortletKey);
}
portletConfig.addInitParameter(ScriptPortlet.SOURCE, scriptSource);
helloScriptPortlet = new ScriptPortlet();
try
{
helloScriptPortlet.init(portletConfig);
assertTrue(helloScriptPortlet.getScriptSourceLastEvaluated() > 0L);
}
catch (PortletException e)
{
e.printStackTrace();
fail("Failed to initialize portlet: " + e);
}
/*
* 3. initialize script engine by script mime type
*/
portletContext = new MockPortletContext(new DefaultResourceLoader())
{
@Override
public String getMimeType(String filePath)
{
return getScriptMimeType();