use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class BProgramJsProxyTest method randomProxyText.
@Test
public void randomProxyText() throws InterruptedException {
BProgram sut = new SingleResourceBProgram("RandomProxy.js");
new BProgramRunner(sut).run();
Double boolCount = sut.getFromGlobalScope("boolCount", Double.class).get();
assertEquals(500.0, boolCount, 100);
Double intCount = sut.getFromGlobalScope("intCount", Double.class).get();
assertEquals(500.0, intCount, 100);
Double floatCount = sut.getFromGlobalScope("floatCount", Double.class).get();
assertEquals(500.0, floatCount, 100);
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class BProgramJsProxyTest method logLevelProxyText.
@Test
public void logLevelProxyText() throws InterruptedException {
BProgram sut = new SingleResourceBProgram("RandomProxy.js");
new BProgramRunner(sut).run();
String logLevel1 = sut.getFromGlobalScope("logLevel1", String.class).get();
assertEquals(BProgramJsProxy.LogLevel.Off.name(), logLevel1);
String logLevel2 = sut.getFromGlobalScope("logLevel2", String.class).get();
assertEquals(BProgramJsProxy.LogLevel.Warn.name(), logLevel2);
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class JsEventSetTest method testRun.
@Test
public void testRun() throws InterruptedException, URISyntaxException {
BProgramRunner bpr = new BProgramRunner(new SingleResourceBProgram("JsEventSet.js"));
bpr.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = bpr.addListener(new InMemoryEventLoggingListener());
bpr.run();
assertEquals(Arrays.asList(new BEvent("1stEvent"), new BEvent("2ndEvent")), eventLogger.getEvents());
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class JsEventSetTest method testJsSetData.
@Test
public void testJsSetData() throws InterruptedException, URISyntaxException {
try {
Context.enter();
BProgram bpr = new StringBProgram("Eventset", "var es=bp.EventSet('a',function(e){return e.name=='a';});\n");
new BProgramRunner(bpr).run();
NativeJavaObject sut = (NativeJavaObject) bpr.getGlobalScope().get("es", bpr.getGlobalScope());
JsEventSet jsSut = (JsEventSet) Context.jsToJava(sut, JsEventSet.class);
assertEquals("a", jsSut.getName());
assertTrue(jsSut.toString().contains("a"));
assertTrue(jsSut.toString().contains("JsEventSet"));
assertTrue(jsSut.contains(BEvent.named("a")));
assertFalse(jsSut.contains(BEvent.named("b")));
} finally {
Context.exit();
}
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class StatementsWithDataTest method superStepTest.
@Test
public void superStepTest() throws InterruptedException {
SingleResourceBProgram bprog = new SingleResourceBProgram("StatementsWithData.js");
BProgramRunner sut = new BProgramRunner();
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
sut.setBProgram(bprog);
sut.getBProgram().setEventSelectionStrategy(new PrioritizedBSyncEventSelectionStrategy());
sut.addListener(new BProgramRunnerListenerAdapter() {
});
sut.run();
eventLogger.getEvents().forEach(e -> System.out.println(e));
EventPattern expected = new EventPattern().append(new BEvent("1")).append(new BEvent("2")).append(new BEvent("3"));
assertTrue(expected.matches(eventLogger.getEvents()));
}
Aggregations