Search in sources :

Example 16 with BProgramRunner

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);
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Test(org.junit.Test)

Example 17 with BProgramRunner

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);
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) Test(org.junit.Test)

Example 18 with BProgramRunner

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());
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Test(org.junit.Test)

Example 19 with BProgramRunner

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();
    }
}
Also used : BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) BProgram(il.ac.bgu.cs.bp.bpjs.model.BProgram) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) JsEventSet(il.ac.bgu.cs.bp.bpjs.model.eventsets.JsEventSet) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) StringBProgram(il.ac.bgu.cs.bp.bpjs.model.StringBProgram) Test(org.junit.Test)

Example 20 with BProgramRunner

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()));
}
Also used : PrintBProgramRunnerListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener) EventPattern(il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern) BProgramRunnerListenerAdapter(il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter) BProgramRunner(il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner) SingleResourceBProgram(il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram) InMemoryEventLoggingListener(il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener) PrioritizedBSyncEventSelectionStrategy(il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) Test(org.junit.Test)

Aggregations

BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)43 Test (org.junit.Test)38 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)30 SingleResourceBProgram (il.ac.bgu.cs.bp.bpjs.model.SingleResourceBProgram)29 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)26 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)13 EventPattern (il.ac.bgu.cs.bp.bpjs.analysis.eventpattern.EventPattern)10 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)10 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)4 PrioritizedBSyncEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.PrioritizedBSyncEventSelectionStrategy)4 Scriptable (org.mozilla.javascript.Scriptable)3 BProgramRunnerListenerAdapter (il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListenerAdapter)2 LoggingEventSelectionStrategyDecorator (il.ac.bgu.cs.bp.bpjs.model.eventselection.LoggingEventSelectionStrategyDecorator)2 SimpleEventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.SimpleEventSelectionStrategy)2 Before (org.junit.Before)2 FailedAssertion (il.ac.bgu.cs.bp.bpjs.model.FailedAssertion)1 EventSelectionStrategy (il.ac.bgu.cs.bp.bpjs.model.eventselection.EventSelectionStrategy)1 EventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSet)1 JsEventSet (il.ac.bgu.cs.bp.bpjs.model.eventsets.JsEventSet)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1