Skip to content

Commit

Permalink
add new constructor with inputStream for GroovyDynamicModelsSupplier (#…
Browse files Browse the repository at this point in the history
…1613)

Signed-off-by: AbdelHedhili <[email protected]>
  • Loading branch information
AbdelHedhili authored and miovd committed Feb 3, 2021
1 parent 994af25 commit 201c749
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.powsybl.dynamicsimulation.groovy;

import java.io.InputStream;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -43,6 +44,11 @@ public GroovyDynamicModelsSupplier(Path path, List<DynamicModelGroovyExtension>
this.extensions = Objects.requireNonNull(extensions);
}

public GroovyDynamicModelsSupplier(InputStream is, List<DynamicModelGroovyExtension> extensions) {
this.codeSource = GroovyScripts.load(is);
this.extensions = Objects.requireNonNull(extensions);
}

@Override
public String getName() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,22 @@ public void test() {
assertTrue(extensions.get(0) instanceof DynamicModelGroovyExtension);

DynamicModelsSupplier supplier = new GroovyDynamicModelsSupplier(fileSystem.getPath("/dynamicModels.groovy"), extensions);
testDynamicModels(supplier, network);
}

@Test
public void testWithInputStream() {
Network network = EurostagTutorialExample1Factory.create();

List<DynamicModelGroovyExtension> extensions = GroovyExtension.find(DynamicModelGroovyExtension.class, "dummy");
assertEquals(1, extensions.size());
assertTrue(extensions.get(0) instanceof DynamicModelGroovyExtension);

DynamicModelsSupplier supplier = new GroovyDynamicModelsSupplier(getClass().getResourceAsStream("/dynamicModels.groovy"), extensions);
testDynamicModels(supplier, network);
}

public void testDynamicModels(DynamicModelsSupplier supplier, Network network) {
List<DynamicModel> dynamicModels = supplier.get(network);
assertEquals(2, dynamicModels.size());

Expand Down

0 comments on commit 201c749

Please sign in to comment.