diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/PythonPreferenceStore.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/PythonPreferenceStore.java index 5015cb67da..4430845ad9 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/PythonPreferenceStore.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/PythonPreferenceStore.java @@ -55,6 +55,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority; * ------------ ---------- ----------- -------------------------- * Dec 11, 2009 njensen Initial creation * Jun 22, 2011 9897 ryu allow new GFE config and send notification + * Sep 05, 2013 #2307 dgilling Use better PythonScript constructor. * * * @@ -70,7 +71,7 @@ public class PythonPreferenceStore implements IPreferenceStore, private final List propertyChangeListeners; private final List configurationChangeListeners; - + private Map baseConfiguration; private Map selectedConfiguration; @@ -80,12 +81,12 @@ public class PythonPreferenceStore implements IPreferenceStore, public PythonPreferenceStore(String configName) { this.propertyChangeListeners = new ArrayList(); this.configurationChangeListeners = new ArrayList(); - + this.loadConfiguration(configName); } - + @SuppressWarnings("unchecked") - public void loadConfiguration(String configName) { + public void loadConfiguration(String configName) { IPathManager pathMgr = PathManagerFactory.getPathManager(); String utilityDir = pathMgr.getFile( pathMgr.getContext(LocalizationType.CAVE_STATIC, @@ -100,7 +101,8 @@ public class PythonPreferenceStore implements IPreferenceStore, try { py = new PythonScript( utilityDir + File.separator + "loadConfig.py", - PyUtil.buildJepIncludePath(configPath, vtecPath)); + PyUtil.buildJepIncludePath(configPath, vtecPath), this + .getClass().getClassLoader()); } catch (JepException e) { statusHandler.handle(Priority.CRITICAL, "Unable to load GFE config", e); @@ -116,7 +118,8 @@ public class PythonPreferenceStore implements IPreferenceStore, "Unable to load baseline GFE config", e); } - //Map originalSelectedConfiguration = selectedConfiguration; + // Map originalSelectedConfiguration = + // selectedConfiguration; args.put("configName", configName); try { selectedConfiguration = (Map) py.execute( @@ -131,7 +134,7 @@ public class PythonPreferenceStore implements IPreferenceStore, if (py != null) { py.dispose(); } - + fireConfigurationChangeEvent(configName); this.configName = configName; } @@ -156,10 +159,11 @@ public class PythonPreferenceStore implements IPreferenceStore, } @Override - public void addConfigurationChangeListener(IConfigurationChangeListener listener) { + public void addConfigurationChangeListener( + IConfigurationChangeListener listener) { this.configurationChangeListeners.add(listener); } - + /* * (non-Javadoc) * @@ -191,6 +195,7 @@ public class PythonPreferenceStore implements IPreferenceStore, for (final IPropertyChangeListener listener : this.propertyChangeListeners) { SafeRunnable.run(new SafeRunnable(JFaceResources .getString("PreferenceStore.changeError")) { //$NON-NLS-1$ + @Override public void run() { listener.propertyChange(pe); } @@ -203,13 +208,14 @@ public class PythonPreferenceStore implements IPreferenceStore, for (final IConfigurationChangeListener listener : this.configurationChangeListeners) { SafeRunnable.run(new SafeRunnable(JFaceResources .getString("PreferenceStore.changeError")) { //$NON-NLS-1$ + @Override public void run() { listener.configurationChanged(config); } }); - } + } } - + /* * (non-Javadoc) * @@ -433,9 +439,11 @@ public class PythonPreferenceStore implements IPreferenceStore, } @Override - public void removeConfigurationChangeListener(IConfigurationChangeListener listener) { + public void removeConfigurationChangeListener( + IConfigurationChangeListener listener) { this.configurationChangeListeners.remove(listener); } + /* * (non-Javadoc) * diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManager.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManager.java index 721d9188a1..af7a1439d0 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManager.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/core/DataManager.java @@ -97,6 +97,7 @@ import com.raytheon.viz.gfe.textformatter.TextProductManager; * 04/24/2013 1936 dgilling Move initialization of TextProductMgr * to GFE startup. * 08/27/2013 2302 randerso Code cleanup for AutoSaveJob + * 09/05/2013 2307 dgilling Use better PythonScript constructor. * * * @@ -570,7 +571,7 @@ public class DataManager { .getFile( pathMgr.getContext(LocalizationType.COMMON_STATIC, LocalizationLevel.BASE), "python") - .getPath())); + .getPath()), this.getClass().getClassLoader()); Map args = new HashMap(); args.put("str", response.get(1)); Map obj = (Map) script.execute("unPickle", diff --git a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/textformatter/CombinationsFileUtil.java b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/textformatter/CombinationsFileUtil.java index e26329e468..b3d604378d 100644 --- a/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/textformatter/CombinationsFileUtil.java +++ b/cave/com.raytheon.viz.gfe/src/com/raytheon/viz/gfe/textformatter/CombinationsFileUtil.java @@ -223,7 +223,8 @@ public class CombinationsFileUtil { map.put("comboName", comboName); PythonScript python = null; try { - python = new PythonScript(scriptPath, comboPath); + python = new PythonScript(scriptPath, comboPath, + CombinationsFileUtil.class.getClassLoader()); Object com = python.execute("getCombinations", map); combos = (List>) com; } catch (JepException e) { diff --git a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelFactory2.java b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelFactory2.java index b88d4bf43a..9c2b5862fa 100644 --- a/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelFactory2.java +++ b/cave/com.raytheon.viz.pointdata/src/com/raytheon/viz/pointdata/PlotModelFactory2.java @@ -89,6 +89,7 @@ import com.raytheon.viz.pointdata.rsc.PlotResourceData; * Jun 29, 2009 2538 jsanchez Implemented pointdata. * Aug 09, 2012 1085 jkorman Corrected data construction. * Sep 05, 2013 2316 bsteffen Unify pirep and ncpirep. + * Sep 05, 2013 2307 dgilling Use better PythonScript constructor. * * * @@ -460,11 +461,13 @@ public class PlotModelFactory2 { StringBuilder sb = new StringBuilder(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); - if (Node.TEXT_NODE == child.getNodeType()) + if (Node.TEXT_NODE == child.getNodeType()) { sb.append(((Text) child).getData()); + } } - if (sb.length() > 0) + if (sb.length() > 0) { scriptInfo.scriptText = sb.toString(); + } sampleScriptInfo = new ScriptInfo(); sampleScriptInfo.plotDelegateName = scriptInfo.plotDelegateName; @@ -599,8 +602,9 @@ public class PlotModelFactory2 { Object result = script.executePlotDelegateMethod("isValid", "rec", stationData); if (result instanceof Boolean - && !((Boolean) result).booleanValue()) + && !((Boolean) result).booleanValue()) { return null; + } } catch (JepException e) { statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); @@ -1272,9 +1276,9 @@ public class PlotModelFactory2 { public PlotPythonScript getScript() throws JepException { if (script != null) { - if (Thread.currentThread() == scriptThread) + if (Thread.currentThread() == scriptThread) { return script; - else { + } else { statusHandler.handle(Priority.ERROR, "Plot model scripting was not properly disposed."); script = null; @@ -1290,8 +1294,9 @@ public class PlotModelFactory2 { public void disposeScript() throws JepException { if (script != null) { try { - if (Thread.currentThread() == scriptThread) + if (Thread.currentThread() == scriptThread) { script.dispose(); + } } finally { script = null; scriptThread = null; @@ -1312,8 +1317,9 @@ public class PlotModelFactory2 { StringBuilder includePath = new StringBuilder(); for (LocalizationLevel ll : keys) { LocalizationFile lf = map.get(ll); - if (includePath.length() > 0) + if (includePath.length() > 0) { includePath.append(File.pathSeparator); + } includePath.append(lf.getFile().getAbsolutePath()); } @@ -1322,8 +1328,9 @@ public class PlotModelFactory2 { + "PlotModelInterface.py"); script = new PlotPythonScript(baseFile.getAbsolutePath(), includePath.toString(), plotDelegateName); - if (scriptText != null) + if (scriptText != null) { script.evaluate(scriptText); + } script.executePlotDelegateMethod("init", "plotModelFactory", PlotModelFactory2.this); return script; @@ -1338,7 +1345,8 @@ public class PlotModelFactory2 { public PlotPythonScript(String filePath, String anIncludePath, String plotDelegateName) throws JepException { - super(filePath, anIncludePath); + super(filePath, anIncludePath, PlotPythonScript.class + .getClassLoader()); jep.eval("def " + CHEAT_RUN + "(text):\n return eval(compile(text,'string','exec'),globals(),globals())"); @@ -1359,8 +1367,9 @@ public class PlotModelFactory2 { map.put(argName, argValue); } return execute(methodName, plotDelegateName, map); - } else + } else { return null; + } } } diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/GfeIRT.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/GfeIRT.java index ae835c32b4..90724f0a69 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/GfeIRT.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/GfeIRT.java @@ -60,6 +60,7 @@ import com.raytheon.uf.common.util.FileUtil; * 07/14/09 1995 bphillip Initial creation * Mar 14, 2013 1794 djohnson FileUtil.listFiles now returns List. * 06/13/13 2044 randerso Refactored to use IFPServer + * Sep 05, 2013 2307 dgilling Use better PythonScript constructor. * * * @@ -132,7 +133,8 @@ public class GfeIRT extends Thread { GfePyIncludeUtil.getCommonPythonIncludePath(), GfePyIncludeUtil.getIscScriptsIncludePath(), GfePyIncludeUtil.getGfeConfigIncludePath(siteID)); - script = new PythonScript(scriptFile, includePath); + script = new PythonScript(scriptFile, includePath, this.getClass() + .getClassLoader()); Map args = new HashMap(); GridLocation domain = config.dbDomain(); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IscSendScript.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IscSendScript.java index 2c3bd1888d..a2dd2059fc 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IscSendScript.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/isc/IscSendScript.java @@ -35,6 +35,7 @@ import com.raytheon.uf.common.python.PythonScript; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Oct 25, 2011 dgilling Initial creation + * Sep 05, 2013 #2307 dgilling Use better PythonScript constructor. * * * @@ -53,7 +54,7 @@ public class IscSendScript extends PythonScript { */ public IscSendScript(String aFilePath, String anIncludePath) throws JepException { - super(aFilePath, anIncludePath); + super(aFilePath, anIncludePath, IscSendScript.class.getClassLoader()); } public Object execute(Map args) throws JepException { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/log/LogPurger.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/log/LogPurger.java index 32a353c60c..8e8139b09c 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/log/LogPurger.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/log/LogPurger.java @@ -44,6 +44,7 @@ import com.raytheon.uf.common.python.PythonScript; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Jul 26, 2011 bphillip Initial creation + * Sep 05, 2013 #2307 dgilling Use better PythonScript constructor. * * * @@ -77,7 +78,8 @@ public class LogPurger { PythonScript script = siteScriptMap.get(siteID); if (script == null) { - script = new PythonScript(scriptFile, includePath); + script = new PythonScript(scriptFile, includePath, this + .getClass().getClassLoader()); siteScriptMap.put(siteID, script); } Map args = new HashMap(); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscCreateDomainDictHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscCreateDomainDictHandler.java index 09a1c6e284..b3cca91af2 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscCreateDomainDictHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscCreateDomainDictHandler.java @@ -52,6 +52,7 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; * ------------ ---------- ----------- -------------------------- * 07/06/09 1995 bphillip Initial port * 09/22/09 3058 rjpeter Converted to IRequestHandler + * 09/05/13 2307 dgilling Use better PythonScript constructor. * * * @author bphillip @@ -80,7 +81,8 @@ public class IscCreateDomainDictHandler implements .getCommonPythonIncludePath(), GfePyIncludeUtil .getIscScriptsIncludePath(), GfePyIncludeUtil .getGfeConfigIncludePath(request.getSiteID())); - script = new PythonScript(scriptFile, includePath); + script = new PythonScript(scriptFile, includePath, this.getClass() + .getClassLoader()); Map args = new HashMap(); args.put("xml", request.getXml()); Object obj = script.execute("createDomainDict", args); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscGetRequestXmlHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscGetRequestXmlHandler.java index b63861bb15..e36921c399 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscGetRequestXmlHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscGetRequestXmlHandler.java @@ -49,6 +49,7 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; * ------------ ---------- ----------- -------------------------- * 08/21/09 1995 bphillip Initial port * 09/22/09 3058 rjpeter Converted to IRequestHandler + * 09/05/13 2307 dgilling Use better PythonScript constructor. * * * @author bphillip @@ -75,7 +76,8 @@ public class IscGetRequestXmlHandler implements .getCommonPythonIncludePath(), GfePyIncludeUtil .getIscScriptsIncludePath(), GfePyIncludeUtil .getGfeConfigIncludePath(request.getSiteID())); - script = new PythonScript(scriptFile, includePath); + script = new PythonScript(scriptFile, includePath, this.getClass() + .getClassLoader()); Map args = new HashMap(); args.put("xml", request.getXml()); args.put("selectedServers", request.getSelectedServers()); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscMakeRequestHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscMakeRequestHandler.java index f0a5bdfdf6..f61357963d 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscMakeRequestHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscMakeRequestHandler.java @@ -61,6 +61,8 @@ import com.raytheon.uf.common.util.FileUtil; * 08/21/09 1995 bphillip Initial port * 09/22/09 3058 rjpeter Converted to IRequestHandler * 03/07/13 1759 dgilling Refactor to not use GfeScript. + * 09/05/13 2307 dgilling Use better PythonScript constructor. + * * * * @author bphillip @@ -132,7 +134,8 @@ public class IscMakeRequestHandler implements IRequestHandler { try { PythonScript script = null; try { - script = new PythonScript(scriptPath, includePath); + script = new PythonScript(scriptPath, includePath, + IscMakeRequestHandler.class.getClassLoader()); try { script.execute(METHOD_NAME, args); } catch (JepException e) { diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscRequestQueryHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscRequestQueryHandler.java index 4de887c78d..561451fa0c 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscRequestQueryHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/IscRequestQueryHandler.java @@ -57,6 +57,7 @@ import com.raytheon.uf.common.serialization.comm.IRequestHandler; * ------------ ---------- ----------- -------------------------- * 07/06/09 1995 bphillip Initial port * 09/22/09 3058 rjpeter Converted to IRequestHandler + * 09/05/13 2307 dgilling Use better PythonScript constructor. * * * @author bphillip @@ -96,7 +97,7 @@ public class IscRequestQueryHandler implements } else if (ancf.isEmpty()) { irtUnavailable = true; } - + if (irtUnavailable) { if (bncf == null) { irtUnavailable = true; @@ -140,7 +141,8 @@ public class IscRequestQueryHandler implements GfePyIncludeUtil.getCommonPythonIncludePath(), GfePyIncludeUtil.getIscScriptsIncludePath(), GfePyIncludeUtil.getGfeConfigIncludePath(siteID)); - script = new PythonScript(scriptFile, includePath); + script = new PythonScript(scriptFile, includePath, this.getClass() + .getClassLoader()); Map args = new HashMap(); args.put("ancfURL", ancf); args.put("bncfURL", bncf); @@ -168,7 +170,8 @@ public class IscRequestQueryHandler implements GfePyIncludeUtil.getCommonPythonIncludePath(), GfePyIncludeUtil.getIscScriptsIncludePath(), GfePyIncludeUtil.getGfeConfigIncludePath(siteID)); - script = new PythonScript(scriptFile, includePath); + script = new PythonScript(scriptFile, includePath, this.getClass() + .getClassLoader()); Map args = new HashMap(); args.put("xml", xml); domainDict = script.execute("createDomainDict", args); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/PurgeGfeGridsRequestHandler.java b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/PurgeGfeGridsRequestHandler.java index 8724ee36f3..4f0c8da6d5 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/PurgeGfeGridsRequestHandler.java +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/src/com/raytheon/edex/plugin/gfe/server/handler/PurgeGfeGridsRequestHandler.java @@ -55,6 +55,7 @@ import com.raytheon.uf.common.util.FileUtil; * Mar 07, 2013 1759 dgilling Refactored to remove dependency * on GfeScriptExecutor. * Jun 13, 2013 #2044 randerso Refactored to use IFPServer + * Sep 05, 2013 #2307 dgilling Use better PythonScript constructor. * * * @@ -96,7 +97,8 @@ public class PurgeGfeGridsRequestHandler implements String includePath = PyUtil.buildJepIncludePath( GfePyIncludeUtil.getCommonPythonIncludePath(), GfePyIncludeUtil.getIscScriptsIncludePath()); - script = new PythonScript(scriptPath, includePath); + script = new PythonScript(scriptPath, includePath, this.getClass() + .getClassLoader()); try { Map args = new HashMap(); args.put("databaseID", request.getDatabaseID().toString()); diff --git a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/gfe/isc/iscMosaic.py b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/gfe/isc/iscMosaic.py index 6ff58e0757..059b560bd2 100644 --- a/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/gfe/isc/iscMosaic.py +++ b/edexOsgi/com.raytheon.edex.plugin.gfe/utility/edex_static/base/gfe/isc/iscMosaic.py @@ -39,7 +39,6 @@ from com.raytheon.uf.common.time import TimeRange from com.vividsolutions.jts.geom import Coordinate from java.awt import Point -from com.raytheon.edex.plugin.gfe.server import GridParmManager from com.raytheon.edex.plugin.gfe.config import IFPServerConfigManager from com.raytheon.edex.plugin.gfe.smartinit import IFPDB from com.raytheon.uf.common.dataplugin.gfe import GridDataHistory @@ -82,6 +81,7 @@ from com.raytheon.uf.edex.database.cluster import ClusterTask # 05/23/13 1759 dgilling Remove unnecessary imports. # 06/05/13 2063 dgilling Change __siteInDbGrid() to # call IFPWE.history() like A1. +# 09/05/13 2307 dgilling Fix breakage caused by #2044. # # @@ -565,7 +565,7 @@ class IscMosaic: grid = self.__validateAdjustWeatherKeys(grid, self.__parmName, tr) - grid = self.__remap(self.__dbwe.getParmid(), grid, inGeoDict, inFillV) + grid = self.__remap(self.__dbwe, grid, inGeoDict, inFillV) # if rate parm, then may need to adjust the values if self.__rateParm and inTimes[i] != tr: @@ -1068,13 +1068,12 @@ class IscMosaic: return grid.astype(numpy.float32) - def __remap(self, pid, grid, inGeoDict, inFillV): - - gpi = GridParmManager.getGridParmInfo(pid).getPayload() + def __remap(self, we, grid, inGeoDict, inFillV): + gpi = we.getGpi() gridType = gpi.getGridType().toString() - gs = self.__decodeGridSlice(pid, grid, TimeRange()) + gs = self.__decodeGridSlice(we, grid, TimeRange()) pd = self.__decodeProj(inGeoDict) fill = inFillV @@ -1104,9 +1103,10 @@ class IscMosaic: newGrid = mapper.remap(gs.getDiscreteGrid(), fill, fill) return (newGrid.__numpy__[0], grid[1]) - def __decodeGridSlice(self, pid, value, tr, history=None): - - gpi = GridParmManager.getGridParmInfo(pid).getPayload() + def __decodeGridSlice(self, we, value, tr, history=None): + pid = we.getParmid() + gpi = we.getGpi() + gridType = gpi.getGridType().toString() hist = ArrayList() diff --git a/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/PythonInterpreter.java b/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/PythonInterpreter.java index 5a1ee77861..68c16135af 100644 --- a/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/PythonInterpreter.java +++ b/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/PythonInterpreter.java @@ -32,7 +32,9 @@ import jep.JepException; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Dec 7, 2009 njensen Initial creation + * Dec 07, 2009 njensen Initial creation + * Sep 05, 2013 #2307 dgilling Remove constructor without explicit + * ClassLoader. * * * @@ -49,22 +51,6 @@ public abstract class PythonInterpreter { protected Jep jep; - /** - * Constructor - * - * @param aFilePath - * the path to the python script - * @param anIncludePath - * the python include path, with multiple directories being - * separated by : - * @throws JepException - */ - public PythonInterpreter(String aFilePath, String anIncludePath) - throws JepException { - jep = new Jep(false, anIncludePath); - initializeJep(aFilePath, null); - } - /** * Constructor * diff --git a/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/PythonMapScript.java b/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/PythonMapScript.java deleted file mode 100644 index b1f75dadab..0000000000 --- a/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/PythonMapScript.java +++ /dev/null @@ -1,156 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ -package com.raytheon.uf.common.python; - -import java.util.List; -import java.util.Map; - -import jep.JepException; - -/** - * TODO Add Description - * - *
- * SOFTWARE HISTORY
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * Jul 25, 2008            wdougherty     Initial creation
- * 
- * - * @author wdougherty - * @version 1.0 - */ -@Deprecated -public class PythonMapScript extends PythonScript { - public PythonMapScript(String filePath, String anIncludePath, - ClassLoader classLoader, List preEvals) throws JepException { - super(filePath, anIncludePath, classLoader, preEvals); - } - - public PythonMapScript(String filePath, String anIncludePath, - ClassLoader classLoader) throws JepException { - super(filePath, anIncludePath, classLoader); - } - - public PythonMapScript(String script, String includePath) - throws JepException { - super(script, includePath); - } - - /** - * Set Python variables in the current script from argmap. For each item in - * the map, see if its value is a string beginning with "::". If it is not, - * create a python variable in this test script whose name is the same as - * the key, and assign it a value equal to the key's value. - * - * @param argmap - * a map of argument names to values - * @throws JepException - * if Jep chokes on the generated code. - */ - public void setArgs(Map argmap) throws JepException { - Object val; - - for (String arg : argmap.keySet()) { - if (arg.startsWith("::")) { - continue; - } - val = argmap.get(arg); - evaluateArgument(arg, val); - } - } - - /** - * Execute a method in a script. This is basically the same as the execute() - * method of the base PythonScript class, except that it takes a Map of - * argument names to values instead of twin arrays, and it has special - * handling when the key is a String beginning with "::". The purpose of the - * special handling is to allow complicated objects such as tuples and - * arrays to be created in the script with eval() and then used as - * parameters. - * - * @param methodName - * The name of a method to execute. - * @param instanceName - * The name of a class or module within which the method can be - * found. - * @param argmap - * Maps argument names to argument values. Argument names - * beginning with "::" are interpreted as defining variables - * which have already been declared in the script. - * @return The Object produced by executing the method, which may be null. - * @throws JepException - * if Jep chokes on the scripted code. - */ - @Override - public Object execute(String methodName, String instanceName, - Map argmap) throws JepException { - - setArgs(argmap); - - StringBuilder sb = new StringBuilder(); - - sb.append(PythonScript.RESULT); - sb.append(" = "); - if (instanceName != null) { - sb.append(instanceName).append("."); - } - sb.append(methodName).append("("); - // add method parameters - String ref; - String sep = ""; - for (String arg : argmap.keySet()) { - if ("self".equals(arg)) { - continue; - } - - if (arg.startsWith("::")) { - ref = (String) argmap.get(arg); - arg = arg.substring(2); - } else { - ref = arg; - } - sb.append(sep); - sb.append(arg).append("=").append(ref); - - sep = ","; - } - sb.append(")"); - // run the method - jep.eval(sb.toString()); - // get the result - return getExecutionResult(); - } - - /** - * Interpret an arbitrary Python expression in the script. This is just a - * wrapper around the eval() method of the Jep instance of PythonScript. - * - * @param pythonExpr - * Python expression to interpret. - * @return true if the expression can be interpreted, false otherwise - * (though usually a JepException is thrown). - * @throws JepException - * if Jepp chokes on the expression. - */ - public boolean evaluate(String pythonExpr) throws JepException { - return jep.eval(pythonExpr); - } -} diff --git a/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/PythonScript.java b/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/PythonScript.java index 9f92a1cc25..a5797470ff 100644 --- a/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/PythonScript.java +++ b/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/PythonScript.java @@ -57,6 +57,8 @@ import jep.JepException; * Sep 18, 2009 2899 njensen Added cProfile support * Dec 7, 2009 3310 njensen Separated some functionality up to PythonInterpreter * Jun 26, 2012 #776 dgilling Fix leaking of global names. + * Sep 05, 2013 #2307 dgilling Remove constructor without explicit + * ClassLoader. * * * @@ -70,21 +72,6 @@ public class PythonScript extends PythonInterpreter { protected boolean profile = false; - /** - * Constructor - * - * @param aFilePath - * the path to the python script - * @param anIncludePath - * the python include path, with multiple directories being - * separated by : - * @throws JepException - */ - public PythonScript(String aFilePath, String anIncludePath) - throws JepException { - super(aFilePath, anIncludePath); - } - /** * Constructor * diff --git a/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/thread/PythonScriptManager.java b/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/thread/PythonScriptManager.java index 0426a59eaf..5ffdce666e 100644 --- a/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/thread/PythonScriptManager.java +++ b/edexOsgi/com.raytheon.uf.common.python/src/com/raytheon/uf/common/python/thread/PythonScriptManager.java @@ -34,11 +34,27 @@ import com.raytheon.uf.common.python.PythonScript; * through invariant ScriptRequest objects in a concurrent queue. Output from * the scripts is through a concurrent Map based on the id from the * ScriptRequest. - * - * Why? Currently there are problems when a python script that includes pupynere - * is disposed of in edex such as leaked memory and errors reloading the library + *

+ * Why? Currently there are problems when a python script that includes numpy is + * disposed of in edex such as leaked memory and errors reloading the library * again. + *

+ * Instead of using this class it is recommended that developers instead use + * {@link PythonJobCoordinator#newInstance(AbstractPythonScriptFactory)} + * instead to provide multi-threaded Python execution to their code. + * + *

+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Sep 05, 2013  #2307     dgilling     Use better PythonScript constructor,
+ *                                      mark as Deprecated.
+ * 
+ * 
*/ +@Deprecated public class PythonScriptManager { private static final Object NullScriptResult = new Object(); @@ -104,7 +120,8 @@ public class PythonScriptManager { public void run() { PythonScript script; try { - script = new PythonScript(scriptPath, pythonIncludePath); + script = new PythonScript(scriptPath, pythonIncludePath, + this.getClass().getClassLoader()); } catch (JepException e1) { throw new RuntimeException("Failed to initialize script: " + scriptPath); diff --git a/tests/.classpath b/tests/.classpath index 6c492627ee..57efb368c2 100644 --- a/tests/.classpath +++ b/tests/.classpath @@ -1,6 +1,6 @@ - + diff --git a/tests/.project b/tests/.project index f981c149f7..68f08362fe 100644 --- a/tests/.project +++ b/tests/.project @@ -5,6 +5,11 @@ + + org.python.pydev.PyDevBuilder + + + org.eclipse.jdt.core.javabuilder @@ -13,5 +18,6 @@ org.eclipse.jdt.core.javanature + org.python.pydev.pythonNature diff --git a/tests/.pydevproject b/tests/.pydevproject new file mode 100644 index 0000000000..a9cca037b3 --- /dev/null +++ b/tests/.pydevproject @@ -0,0 +1,7 @@ + + + + +Default +python 2.7 + diff --git a/cave/build/static/common/cave/etc/gfe/userPython/tests/TestAbsTime.py b/tests/python/gfe/TestAbsTime.py similarity index 100% rename from cave/build/static/common/cave/etc/gfe/userPython/tests/TestAbsTime.py rename to tests/python/gfe/TestAbsTime.py diff --git a/cave/build/static/common/cave/etc/gfe/userPython/tests/TestSmartScript.py b/tests/python/gfe/TestSmartScript.py similarity index 73% rename from cave/build/static/common/cave/etc/gfe/userPython/tests/TestSmartScript.py rename to tests/python/gfe/TestSmartScript.py index a047c4c67a..670cd610be 100644 --- a/cave/build/static/common/cave/etc/gfe/userPython/tests/TestSmartScript.py +++ b/tests/python/gfe/TestSmartScript.py @@ -34,23 +34,36 @@ idxKL = ["", "one", "two", "three"] discreteGrid = (idxA, idxKL) from com.raytheon.uf.common.dataplugin.gfe.grid import Grid2DByte -from com.raytheon.viz.gfe.ui.runtimeui import TestSmartScript numpyByteArray = np.ones((3,3), dtype=np.byte) dimx = 3 dimy = 3 -def testGetGridShape(): +def testGetGridShape(dataMgr): + smartScript = SmartScript.SmartScript(dataMgr) valueExpected = (145, 145) valueObtained = smartScript.getGridShape() if not valueExpected==valueObtained: print "valueObtained =", valueObtained return (valueExpected==valueObtained) -def testGetGridInfo(model, element, level, timeRange, mostRecentModel=0): +def testGetGridInfo(dataMgr, model, element, level, timeRange, mostRecentModel=0): + smartScript = SmartScript.SmartScript(dataMgr) rtnInfo = smartScript.getGridInfo(model, element, level, timeRange, mostRecentModel) if rtnInfo is not None: gridTime = rtnInfo[0].gridTime() if gridTime is None: raise RuntimeError, "gridTime is None" - return True \ No newline at end of file + return True + +def testSortUglyStr(dataMgr, uglyStr): + smartScript = SmartScript.SmartScript(dataMgr) + return smartScript.sortUglyStr(uglyStr) + +def testGetIndex(dataMgr, keyList, uglyStr): + smartScript = SmartScript.SmartScript(dataMgr) + return smartScript.getIndex(uglyStr, keyList) + +def getParm(dataMgr, model, element, level): + smartScript = SmartScript.SmartScript(dataMgr) + return smartScript.getParm(model, element, level) \ No newline at end of file diff --git a/tests/unit/com/raytheon/uf/common/localization/TestPathManager.java b/tests/unit/com/raytheon/uf/common/localization/TestPathManager.java index 9a02b66b89..4b35a9ddf5 100644 --- a/tests/unit/com/raytheon/uf/common/localization/TestPathManager.java +++ b/tests/unit/com/raytheon/uf/common/localization/TestPathManager.java @@ -42,6 +42,7 @@ import com.raytheon.uf.common.util.FileUtil; * Oct 23, 2012 1286 djohnson Change to find more localization files. * Jan 16, 2013 1487 djohnson Avoid adding new localization files to baseline utility directories. * May 31, 2013 1650 djohnson Fix incorrect merge from vlab branch. + * Sep 05, 2013 2307 dgilling Better handling of directories in getPath(). * * * @@ -104,7 +105,6 @@ public class TestPathManager extends PathManager { */ @Override public File getPath(LocalizationContext context, String fileName) { - File foundFile = null; List utilityDirs = getUtilityDirs(); @@ -120,27 +120,42 @@ public class TestPathManager extends PathManager { // if needed } - final int length = utilityDirs.size(); - for (int i = 0; i < length; i++) { - File baseDir = new File(utilityDirs.get(i), context.toPath()); + for (File utilityDir : utilityDirs) { + File baseDir = new File(utilityDir, context.toPath()); + File toFind = new File(baseDir, fileName); - File file = new File(baseDir, fileName); - // If it's the final check or if a file exists - if (i == (length - 1) || file.exists()) { - foundFile = file; + if (toFind.exists()) { + if (!toFind.getAbsolutePath().startsWith( + savedLocalizationFileDir.getAbsolutePath())) { + foundFile = createTestIsolatedVersionOfLocalizationFile( + context, fileName, toFind); + } else { + foundFile = toFind; + } + } + + // if we found an actual file, we can be reasonably sure there's + // only one file in the whole project with that name and can + // stop looking. However, if we found a directory there may be + // multiple plugins contributing to that directory and we have + // to search the whole collection of directories to be sure + // we've got all files that belong in that dir. + if (toFind.isFile()) { break; } } - if (foundFile == null - || foundFile.getAbsolutePath().startsWith( - savedLocalizationFileDir.getAbsolutePath())) { + if (foundFile != null) { return foundFile; + } else { + // Have to create a default File and the previous revision's + // behavior was just to use the last File in utilityDirs. This + // ensures that the path desired gets created as empty. + return createTestIsolatedVersionOfLocalizationFile(context, + fileName, + new File(utilityDirs.get(utilityDirs.size() - 1), + fileName)); } - - File savedFile = createTestIsolatedVersionOfLocalizationFile( - context, fileName, foundFile); - return savedFile; } /** diff --git a/tests/unit/com/raytheon/viz/gfe/ui/runtimeui/TestAbsTime.java b/tests/unit/com/raytheon/viz/gfe/ui/runtimeui/TestAbsTime.java index 093985f87c..43d225c2db 100644 --- a/tests/unit/com/raytheon/viz/gfe/ui/runtimeui/TestAbsTime.java +++ b/tests/unit/com/raytheon/viz/gfe/ui/runtimeui/TestAbsTime.java @@ -19,16 +19,23 @@ **/ package com.raytheon.viz.gfe.ui.runtimeui; +import static org.junit.Assert.assertTrue; + import java.io.File; +import java.util.Collections; import java.util.Date; -import java.util.HashMap; import java.util.Map; import jep.JepException; -import junit.framework.TestCase; -import org.junit.Ignore; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import com.raytheon.uf.common.dataplugin.gfe.python.GfePyIncludeUtil; +import com.raytheon.uf.common.localization.PathManagerFactoryTest; +import com.raytheon.uf.common.python.PyUtil; import com.raytheon.uf.common.python.PythonScript; import com.raytheon.uf.common.time.TimeRange; @@ -39,65 +46,51 @@ import com.raytheon.uf.common.time.TimeRange; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Aug 1, 2008 wdougherty Initial creation + * Aug 01, 2008 wdougherty Initial creation + * Sep 05, 2013 #2307 dgilling Fix test case. * * * @author wdougherty * @version 1.0 */ -// TODO fix? -@Ignore -public class TestAbsTime extends TestCase { +public class TestAbsTime { - protected static final String testScriptName = "ROOT/build/static/common/cave/etc/gfe/userPython/tests/TestAbsTime.py"; + private static final File SCRIPT_FILE = new File( + "./python/gfe/TestAbsTime.py"); - protected static final String smartScriptPath = "ROOT/build/static/common/cave/etc/gfe/userPython/utilities" - + ":ROOT/build" - + ":ROOT/AWIPSEdex/opt/utility/common_static/base/python/gfe" - + ":ROOT/AWIPSEdex/opt/utility/common_static/base/python" - + ":ROOT/AWIPSEdex/extensions/plugin-gfe/src"; + private PythonScript testScript = null; - PythonScript testScript; + @BeforeClass + public static void setUpBeforeClass() throws Exception { + PathManagerFactoryTest.initLocalization(); + } - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - @Override + @Before public void setUp() throws Exception { + String includePath = PyUtil.buildJepIncludePath( + GfePyIncludeUtil.getCommonPythonIncludePath(), + GfePyIncludeUtil.getCommonGfeIncludePath(), + GfePyIncludeUtil.getUtilitiesIncludePath()); + try { - // Set up an interpreter that can run Python with Java classes. - // Hopefully, using user.home will make this portable to any - // developer. - String root = System.getProperty("user.home") + File.separator - + "workspace"; - - testScript = new PythonScript(testScriptName.replaceAll("ROOT", - root), smartScriptPath.replaceAll("ROOT", root)); - + testScript = new PythonScript(SCRIPT_FILE.getPath(), includePath, + this.getClass().getClassLoader()); } catch (JepException e) { throw new Exception(e); } } - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#tearDown() - */ - @Override - public void tearDown() { - // Free any resources the previous interpreter used. - testScript.dispose(); + @After + public void tearDown() throws Exception { + if (testScript != null) { + testScript.dispose(); + } } - /** - * @throws Exception - */ + @Test public void testAbsTimeZero() throws Exception { - Map emptyMap = new HashMap(); + Map emptyMap = Collections.emptyMap(); try { Date now = new Date(); // AbsTime truncates to the nearest second. Wait one second diff --git a/tests/unit/com/raytheon/viz/gfe/ui/runtimeui/TestSmartScript.java b/tests/unit/com/raytheon/viz/gfe/ui/runtimeui/TestSmartScript.java index 0d435f200a..825c4212d7 100644 --- a/tests/unit/com/raytheon/viz/gfe/ui/runtimeui/TestSmartScript.java +++ b/tests/unit/com/raytheon/viz/gfe/ui/runtimeui/TestSmartScript.java @@ -19,22 +19,33 @@ **/ package com.raytheon.viz.gfe.ui.runtimeui; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.File; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; import jep.JepException; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; -import com.raytheon.uf.common.python.PythonMapScript; +import com.raytheon.uf.common.dataplugin.gfe.python.GfePyIncludeUtil; +import com.raytheon.uf.common.localization.PathManagerFactoryTest; +import com.raytheon.uf.common.python.PyUtil; +import com.raytheon.uf.common.python.PythonScript; import com.raytheon.uf.common.time.TimeRange; -import com.raytheon.viz.gfe.Activator; import com.raytheon.viz.gfe.core.DataManager; import com.raytheon.viz.gfe.core.FakeDataManager; -import com.raytheon.viz.gfe.core.internal.AbstractParmManager; +import com.raytheon.viz.gfe.core.IParmManager; import com.raytheon.viz.gfe.core.internal.MockParmManager; import com.raytheon.viz.gfe.core.parm.Parm; import com.raytheon.viz.gfe.core.parm.Parm.CreateFromScratchMode; @@ -46,145 +57,66 @@ import com.raytheon.viz.gfe.core.parm.Parm.CreateFromScratchMode; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Jul 24, 2008 wdougherty Initial creation + * Jul 24, 2008 wdougherty Initial creation + * Sep 05, 2013 #2307 dgilling Code cleanup * * * @author wdougherty * @version 1.0 */ -public class TestSmartScript extends TestCase { +@Ignore +// FIXME: This test case is currently broken because of a NullPOinterException +// in AbstractSpatialDisplayManager +// Activator.getDefault() is returning null at the moment. +public class TestSmartScript { - protected static final String testScriptName = "ROOT/build/static/common/cave/etc/gfe/userPython/tests/TestSmartScript.py"; + private static final String SCRIPT_FILE_PATH = new File( + "./python/gfe/TestSmartScript.py").getPath(); - protected static final String smartScriptPath = "ROOT/build/static/common/cave/etc/gfe/userPython/utilities" - + ":ROOT/build" - + ":ROOT/AWIPSEdex/opt/utility/common_static/base/python/gfe" - + ":ROOT/AWIPSEdex/opt/utility/common_static/base/python" - + ":ROOT/AWIPSEdex/extensions/plugin-gfe/src"; + private PythonScript testScript = null; - /** - * A PythonScript. All PythonScript's constructors are protected, so we have - * to create this subclass in order to obtain an instance. While we're at - * it, create a modified execute() method and a helper method for setting - * groups of script variables. - * - */ + private DataManager dataMgr; - PythonMapScript testScript; + @BeforeClass + public static void setUpBeforeClass() throws Exception { + PathManagerFactoryTest.initLocalization(); + } - Map argmap; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - @Override + @Before public void setUp() throws Exception { + FakeDataManager fakeDataMgr = new FakeDataManager(); + IParmManager pm = new MockParmManager(fakeDataMgr); + fakeDataMgr.setParmManager(pm); + dataMgr = fakeDataMgr; + + String includePath = PyUtil.buildJepIncludePath( + GfePyIncludeUtil.getCommonPythonIncludePath(), + GfePyIncludeUtil.getCommonGfeIncludePath(), + GfePyIncludeUtil.getUtilitiesIncludePath()); try { - // Create a DataManager to pass to the SmartScript constructor. - DataManager dataManager = null; - Activator activator = Activator.getDefault(); - if (activator == null) { - FakeDataManager fakeDataManager = new FakeDataManager(); - AbstractParmManager pm = new MockParmManager(fakeDataManager); - fakeDataManager.setParmManager(pm); - dataManager = fakeDataManager; - } else { - dataManager = DataManager.getInstance(null); - } - - // Set up an interpreter that can run Python with Java classes. - // Hopefully, using user.home will make this portable to any - // developer. - String root = System.getProperty("user.home") + File.separator - + "workspace"; - ClassLoader classLoader = dataManager.getClass().getClassLoader(); - testScript = new PythonMapScript(testScriptName.replaceAll("ROOT", - root), smartScriptPath.replaceAll("ROOT", root), - classLoader); - - // Put the data manager in the interpreter - Map setupMap = new HashMap(); - setupMap.put("dataManager", dataManager); - testScript.setArgs(setupMap); - - // Create a SmartScript instance for use by the tests. - boolean evalResult; - evalResult = testScript - .evaluate("smartScript = SmartScript.SmartScript(dataManager)"); - - // If eval somehow failed without throwing a JepException, fail. - assertTrue(evalResult); - - // Create an argmap to pass parameters in. - argmap = new HashMap(); + testScript = new PythonScript(SCRIPT_FILE_PATH, includePath, this + .getClass().getClassLoader()); } catch (JepException e) { throw new Exception(e); } } - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#tearDown() - */ - @Override - public void tearDown() { - // Free any resources the previous interpreter used. - testScript.dispose(); - } - - /** - * Test the createGrid method of SmartScript.py when creating a discrete - * grid. - * - * NOTE: This test currently throws an exception because one of the objects - * supplied by MockParmManager always has a grid type of "SCALAR", which - * leads to a ClassCastException in the grid cycler when SmartScript passes - * a byte grid and keys to the grid cycler. If the code in the grid cycler - * is hacked to force the grid type to "DISCRETE" for the test, it completes - * successfully. - */ - @Test - public void testCreateGridDiscrete() throws Exception { - argmap.put("model", "Fcst"); - argmap.put("element", "hazXXX1234"); - argmap.put("elementType", "DISCRETE"); - argmap.put("timeRange", new TimeRange(new Date(), 10 * 3600 * 1000L)); - argmap.put("descriptiveName", "Discrete Test Grid"); - argmap.put("::timeConstraints", "tcTuple"); - argmap.put("units", ""); - argmap.put("::discreteKeys", "dkList"); - argmap.put("discreteOverlap", Boolean.FALSE); - argmap.put("discreteAuxDataLength", Integer.valueOf(4)); - argmap.put("defaultColorTable", "YesNo"); - argmap.put("::numericGrid", "discreteGrid"); - Object obj = null; - try { - if (!testScript.evaluate("tcTuple = (1000, 1200, 600)")) { - throw new Exception("eval(\"tcTuple... failed."); - } - if (!testScript - .evaluate("dkList = ['One', ('Singular', 'Sensation')]")) { - throw new Exception("eval(\"dklist = ... failed."); - } - obj = testScript.execute("createGrid", "smartScript", argmap); - } catch (JepException e) { - throw new Exception(e); + @After + public void tearDown() throws Exception { + if (testScript != null) { + testScript.dispose(); } } - /** - * @throws Exception - */ @Test public void testSortUglyStr() throws Exception { + Map argmap = new HashMap(2, 1.0f); argmap.put("uglyStr", "I^AM^THE^CAPTAIN^OF^PINAFORE"); + argmap.put("dataMgr", dataMgr); String outstr = null; try { - outstr = (String) testScript.execute("sortUglyStr", "smartScript", + outstr = (String) testScript.execute("testSortUglyStr", null, argmap); } catch (JepException e) { throw new Exception(e); @@ -194,43 +126,34 @@ public class TestSmartScript extends TestCase { @Test public void testGetIndex() throws Exception { + Map argmap = new HashMap(3, 1.0f); + argmap.put("dataMgr", dataMgr); + String key1 = "Twas^Brillig^and^the^slithy^toves"; String key2 = "Did^gyre^and^gimbol^in^the^wabe"; String key3 = "Twas^Brillig^and"; String key4 = "and^slithy^the^toves^Brillig^Twas"; + List keyList = Arrays.asList(key1, key2, key3, key4); + argmap.put("keyList", keyList); - Integer outInt = null; - try { - testScript.evaluate("keyList = []"); - argmap.put("::keys", "keyList"); - argmap.put("uglyStr", key1); - outInt = (Integer) testScript.execute("getIndex", "smartScript", - argmap); - assertEquals("key1", 0, outInt.intValue()); - - argmap.put("uglyStr", key2); - outInt = (Integer) testScript.execute("getIndex", "smartScript", - argmap); - assertEquals("key2", 1, outInt.intValue()); - - argmap.put("uglyStr", key3); - outInt = (Integer) testScript.execute("getIndex", "smartScript", - argmap); - assertEquals("key3", 2, outInt.intValue()); - - argmap.put("uglyStr", key4); - outInt = (Integer) testScript.execute("getIndex", "smartScript", - argmap); - assertEquals("key4", 0, outInt.intValue()); - - } catch (JepException e) { - throw new Exception(e); + for (int i = 0; i < keyList.size(); i++) { + Integer outInt = null; + argmap.put("uglyStr", keyList.get(i)); + try { + outInt = (Integer) testScript.execute("testGetIndex", null, + argmap); + assertEquals("key" + (i + 1), i, outInt.intValue()); + } catch (JepException e) { + throw new Exception(e); + } } } @Test public void testGetGridShape() throws Exception { try { + Map argmap = new HashMap(1, 1.0f); + argmap.put("dataMgr", dataMgr); Boolean testResult = (Boolean) testScript.execute( "testGetGridShape", null, argmap); assertTrue("Tuples should match", testResult); @@ -241,16 +164,18 @@ public class TestSmartScript extends TestCase { @Test public void testGetGridInfo() throws Exception { + Map argmap = new HashMap(5, 1.0f); + argmap.put("dataMgr", dataMgr); argmap.put("model", "Fcst"); argmap.put("element", "Hazards"); argmap.put("level", "SFC"); - Parm parm = null; try { - parm = (Parm) testScript.execute("getParm", "smartScript", argmap); - } catch (JepException e1) { - throw new Exception(e1); + parm = (Parm) testScript.execute("getParm", null, argmap); + } catch (JepException e) { + throw new Exception(e); } + assertNotNull("Retrieved Hazards_SFC parm.", parm); TimeRange tr = new TimeRange(new Date(), 1000L); boolean created = parm.createFromScratchTR(tr, @@ -272,6 +197,5 @@ public class TestSmartScript extends TestCase { } catch (JepException e) { throw new Exception(e); } - } }