GroovyCurvesSupplier implements CurvesSupplier { @Override public List<Curve> get(Network network) { List<Curve> curves = new ArrayList<>(); Binding binding = new Binding(); binding.setVariable("network", network); ExpressionDslLoader.prepareClosures(binding); extensions.forEach(e -> e.load(binding, curves::add)); GroovyShell shell = new GroovyShell(binding, new CompilerConfiguration()); shell.evaluate(codeSource); return curves; } GroovyCurvesSupplier(Path path);  GroovyCurvesSupplier(Path path, List<CurveGroovyExtension> extensions); @Override String getName(); @Override List<Curve> get(Network network);  }
@Test public void test() { Network network = EurostagTutorialExample1Factory.create(); List<CurveGroovyExtension> extensions = GroovyExtension.find(CurveGroovyExtension.class, "dummy"); assertEquals(1, extensions.size()); assertTrue(extensions.get(0) instanceof DummyCurveGroovyExtension); CurvesSupplier supplier = new GroovyCurvesSupplier(fileSystem.getPath("/curves.groovy"), extensions); List<Curve> curves = supplier.get(network); assertEquals(2, curves.size()); assertTrue(curves.get(0) instanceof DummyCurve); DummyCurve curve1 = (DummyCurve) curves.get(0); assertEquals("id", curve1.getId()); assertEquals("variable", curve1.getVariable()); assertTrue(curves.get(1) instanceof DummyCurve); DummyCurve curve2 = (DummyCurve) curves.get(1); assertEquals("LOAD", curve2.getId()); assertEquals("p0", curve2.getVariable()); }