use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class FailedAssertionTest method testAssertion.
@Test
public void testAssertion() throws InterruptedException {
final SingleResourceBProgram bprog = new SingleResourceBProgram("FailedAssertionTest.js");
BProgramRunner sut = new BProgramRunner(bprog);
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
System.out.println("About to start program");
bprog.putInGlobalScope("shouldFail", true);
sut.run();
assertEquals(Arrays.asList("piff", "puff", "poof!"), eventLogger.eventNames());
assertTrue(sut.hasFailedAssertion());
FailedAssertion fa = sut.getFailedAssertion();
assertEquals("assertor", fa.getBThreadName());
assertEquals("Poof has happened.", fa.getMessage());
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class HotNColdTest method superStepTest.
@Test
public void superStepTest() throws InterruptedException {
BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("HotNCold.js"));
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
sut.run();
eventLogger.getEvents().forEach(e -> System.out.println(e));
EventPattern expected = new EventPattern().append(coldEvent).append(hotEvent).append(coldEvent).append(hotEvent).append(coldEvent).append(hotEvent).append(allDoneEvent);
assertTrue(expected.matches(eventLogger.getEvents()));
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class LoggingTest method testLogLevels.
@Test
public void testLogLevels() throws InterruptedException, UnsupportedEncodingException {
PrintStream originalOut = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream myOut = new PrintStream(baos)) {
System.setOut(myOut);
new BProgramRunner(new SingleResourceBProgram("loggingTest.js")).run();
myOut.flush();
}
String result = baos.toString(StandardCharsets.UTF_8.name());
System.setOut(originalOut);
System.out.println("result:");
System.out.println(result);
org.junit.Assert.assertEquals(6l, (long) result.split("\n").length);
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class PushingExternalEventTest method externalEventsFromABthread.
@Test
public void externalEventsFromABthread() throws InterruptedException {
BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("PushingExternalEvent.js"));
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
sut.run();
eventLogger.getEvents().forEach(e -> System.out.println(e));
EventPattern expected = new EventPattern().append(new BEvent("start")).append(new BEvent("external")).append(new BEvent("done"));
assertTrue(expected.matches(eventLogger.getEvents()));
}
use of il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner in project BPjs by bThink-BGU.
the class PushingExternalEventTest method topLevelExternalEvents.
@Test
public void topLevelExternalEvents() throws InterruptedException {
BProgramRunner sut = new BProgramRunner(new SingleResourceBProgram("TopLevelExternalEvents.js"));
sut.addListener(new PrintBProgramRunnerListener());
InMemoryEventLoggingListener eventLogger = sut.addListener(new InMemoryEventLoggingListener());
sut.run();
eventLogger.getEvents().forEach(e -> System.out.println(e));
EventPattern expected = new EventPattern().append(new BEvent("ext1")).append(new BEvent("ext2")).append(new BEvent("ext3")).append(new BEvent("internal"));
assertTrue(expected.matches(eventLogger.getEvents()));
}
Aggregations