private void createRuntimeInstances() { try { Jiffle jiffle = new Jiffle(); Map<String, Jiffle.ImageRole> imageParams = new HashMap<>(); imageParams.put(WORLD_NAME, Jiffle.ImageRole.SOURCE); imageParams.put(NEXT_WORLD_NAME, Jiffle.ImageRole.DEST); // First create a runtime for the toroidal world URL url = getClass().getResource("life-toroid.jfl"); File file = new File(url.toURI()); jiffle.setScript(file); jiffle.setImageParams(imageParams); jiffle.compile(); toroidRuntime = jiffle.getRuntimeInstance(); // Now create a second runtime for the hard-edged world url = getClass().getResource("life-edges.jfl"); file = new File(url.toURI()); jiffle.setScript(file); jiffle.setImageParams(imageParams); jiffle.compile(); edgeRuntime = jiffle.getRuntimeInstance(); // Set the active runtime activeRuntime = worldType == WorldType.EDGES ? edgeRuntime : toroidRuntime; } catch (Exception ex) { throw new RuntimeException(ex); } }
@Test(expected=UnsupportedOperationException.class) public void tryToModifyImageParams() { System.out.println(" trying to modify map returned by getImageParams"); imageParams.put("dest", Jiffle.ImageRole.DEST); jiffle.setImageParams(imageParams); Map<String, Jiffle.ImageRole> unmodifiableMap = jiffle.getImageParams(); // this should provoke an exception unmodifiableMap.clear(); }
@Test(expected=JiffleException.class) public void compileWithNoScript() throws Exception { System.out.println(" compile with no script set"); imageParams.put("dest", Jiffle.ImageRole.DEST); jiffle.setImageParams(imageParams); jiffle.compile(); }
/** * Creates a new instance by compiling the script read from {@code scriptFile}. * Using this constructor is equivalent to: * <pre><code> * Jiffle jiffle = new Jiffle(); * jiffle.setScript(scriptFile); * jiffle.setImageParams(params); * jiffle.compile(); * </code></pre> * * @param scriptFile file containing the Jiffle script * * @param params defines the names and roles of image variables * referred to in the script. * * @throws JiffleException on compilation errors */ public Jiffle(File scriptFile, Map<String, Jiffle.ImageRole> params) throws it.geosolutions.jaiext.jiffle.JiffleException { init(); setScript(scriptFile); setImageParams(params); compile(); }
/** * Creates a new instance by compiling the script read from {@code scriptFile}. * Using this constructor is equivalent to: * <pre><code> * Jiffle jiffle = new Jiffle(); * jiffle.setScript(scriptFile); * jiffle.setImageParams(params); * jiffle.compile(); * </code></pre> * * @param scriptFile file containing the Jiffle script * * @param params defines the names and roles of image variables * referred to in the script. * * @throws JiffleException on compilation errors */ public Jiffle(File scriptFile, Map<String, Jiffle.ImageRole> params) throws it.geosolutions.jaiext.jiffle.JiffleException { init(); setScript(scriptFile); setImageParams(params); compile(); }
private void setupSingleDestScript() throws JiffleException { String script = "dest = 42;"; jiffle.setScript(script); imageParams.put("dest", Jiffle.ImageRole.DEST); jiffle.setImageParams(imageParams); jiffle.compile(); }
/** * Creates a new instance by compiling the provided script. Using this * constructor is equivalent to: * <pre><code> * Jiffle jiffle = new Jiffle(); * jiffle.setScript(script); * jiffle.setImageParams(params); * jiffle.compile(); * </code></pre> * * @param script Jiffle source code to compile * * @param params defines the names and roles of image variables * referred to in the script. * @throws JiffleException on compilation errors * */ public Jiffle(String script, Map<String, Jiffle.ImageRole> params) throws it.geosolutions.jaiext.jiffle.JiffleException { init(); setScript(script); setImageParams(params); compile(); }
/** * Creates a new instance by compiling the provided script. Using this * constructor is equivalent to: * <pre><code> * Jiffle jiffle = new Jiffle(); * jiffle.setScript(script); * jiffle.setImageParams(params); * jiffle.compile(); * </code></pre> * * @param script Jiffle source code to compile * * @param params defines the names and roles of image variables * referred to in the script. * @throws JiffleException on compilation errors * */ public Jiffle(String script, Map<String, Jiffle.ImageRole> params) throws it.geosolutions.jaiext.jiffle.JiffleException { init(); setScript(script); setImageParams(params); compile(); }
@Test public void setImageParams() { System.out.println(" set and get image params"); imageParams.put("src1", Jiffle.ImageRole.SOURCE); imageParams.put("src2", Jiffle.ImageRole.SOURCE); imageParams.put("dest1", Jiffle.ImageRole.DEST); imageParams.put("dest2", Jiffle.ImageRole.DEST); jiffle.setImageParams(imageParams); Map<String, Jiffle.ImageRole> result = jiffle.getImageParams(); assertEquals(imageParams.size(), result.size()); for (String name : imageParams.keySet()) { assertTrue(imageParams.get(name).equals(result.get(name))); } }
@Test(expected=JiffleParserException.class) public void compileInvalidScriptThrowsException() throws Exception { System.out.println(" compile invalid script and get exception"); // script with an uninitialized variable String script = "dest = x;"; imageParams.put("dest", Jiffle.ImageRole.DEST); jiffle.setScript(script); jiffle.setImageParams(imageParams); jiffle.compile(); }
@Test(expected=JiffleException.class) public void getRuntimeBeforeCompiling() throws Exception { System.out.println(" getRuntimeInstance before compiling"); String script = "dest = 42;"; jiffle.setScript(script); imageParams.put("dest", Jiffle.ImageRole.DEST); jiffle.setImageParams(imageParams); JiffleRuntime runtime = jiffle.getRuntimeInstance(); } }
private JiffleDirectRuntime getRuntime(String script) throws Exception { Jiffle jiffle = new Jiffle(); jiffle.setScript(script); Map<String, Jiffle.ImageRole> params = new HashMap<>(); params.put("dest", Jiffle.ImageRole.DEST); jiffle.setImageParams(params); jiffle.compile(); return jiffle.getRuntimeInstance(); }
jiffle.setImageParams(imageParams); jiffle.compile(); runtime =
jiffle.setImageParams(imageParams); jiffle.compile(); runtime =
@Test public void compileValidScript() throws Exception { System.out.println(" compile valid script"); String script = "dest = 42;"; imageParams.put("dest", Jiffle.ImageRole.DEST); jiffle.setScript(script); jiffle.setImageParams(imageParams); jiffle.compile(); assertTrue(jiffle.isCompiled()); }
@Test public void compileInvalidScriptAndCheckStatus() throws Exception { System.out.println(" compile invalid script and check status"); // script with an uninitialized variable String script = "dest = x;"; imageParams.put("dest", Jiffle.ImageRole.DEST); jiffle.setScript(script); jiffle.setImageParams(imageParams); try { jiffle.compile(); } catch (JiffleParserException ignored) {} assertFalse(jiffle.isCompiled()); }
jiffle.setImageParams(imageParams);
private JiffleDirectRuntime getRuntime(String script) throws Exception { Jiffle jiffle = new Jiffle(); jiffle.setScript(script); Map<String, Jiffle.ImageRole> imageParams = new HashMap<>(); imageParams.put("dest", Jiffle.ImageRole.DEST); jiffle.setImageParams(imageParams); jiffle.compile(); JiffleDirectRuntime runtime = jiffle.getRuntimeInstance(); WritableRenderedImage destImg = ImageUtilities.createConstantImage(WIDTH, WIDTH, 0d); runtime.setDestinationImage("dest", destImg); return runtime; }